<commit_before>#include "platform/platform.hpp"
#include "platform/platform_unix_impl.hpp"
#include "platform/constants.hpp"
#include "platform/settings.hpp"

#include "coding/zip_reader.hpp"
#include "coding/file_name_utils.hpp"

#include "base/logging.hpp"
#include "base/thread.hpp"
#include "base/regexp.hpp"
#include "base/string_utils.hpp"

#include <unistd.h>     // for sysconf
#include <sys/stat.h>

Platform::Platform()
{
  /// @see initialization routine in android/jni/com/.../Platform.hpp
}

namespace
{
enum SourceT
{
  EXTERNAL_RESOURCE,
  RESOURCE,
  WRITABLE_PATH,
  SETTINGS_PATH,
  FULL_PATH,
  SOURCE_COUNT
};

bool IsResource(string const & file, string const & ext)
{
  if (ext == DATA_FILE_EXTENSION)
  {
    return (strings::StartsWith(file, WORLD_COASTS_FILE_NAME) ||
            strings::StartsWith(file, WORLD_FILE_NAME));
  }
  else if (ext == BOOKMARKS_FILE_EXTENSION ||
           ext == ROUTING_FILE_EXTENSION ||
           file == SETTINGS_FILE_NAME)
  {
    return false;
  }

  return true;
}

size_t GetSearchSources(string const & file, string const & searchScope,
                        SourceT (&arr)[SOURCE_COUNT])
{
  size_t ret = 0;

  for (size_t i = 0; i < searchScope.size(); ++i)
  {
    switch (searchScope[i])
    {
    case 'w': arr[ret++] = WRITABLE_PATH; break;
    case 'r': arr[ret++] = RESOURCE; break;
    case 'e': arr[ret++] = EXTERNAL_RESOURCE; break;
    case 's': arr[ret++] = SETTINGS_PATH; break;
    case 'f':
      if (strings::StartsWith(file, "/"))
        arr[ret++] = FULL_PATH;
      break;
    default : CHECK(false, ("Unsupported searchScope:", searchScope)); break;
    }
  }

  return ret;
}

#ifdef DEBUG
class DbgLogger
{
  string const & m_file;
  SourceT m_src;
public:
  DbgLogger(string const & file) : m_file(file) {}
  void SetSource(SourceT src) { m_src = src; }
  ~DbgLogger()
  {
    LOG(LDEBUG, ("Source for file", m_file, "is", m_src));
  }
};
#endif

}

ModelReader * Platform::GetReader(string const & file, string const & searchScope) const
{
  string const ext = my::GetFileExtension(file);
  ASSERT(!ext.empty(), ());

  uint32_t const logPageSize = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_SIZE : 10;
  uint32_t const logPageCount = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_COUNT : 4;

  SourceT sources[SOURCE_COUNT];
  size_t n = 0;

  if (searchScope.empty())
  {
    // Default behaviour - use predefined scope for resource files and writable path for all others.

    if (IsResource(file, ext))
      n = GetSearchSources(file, m_androidDefResScope, sources);
    else
    {
      // Add source for map files and other dynamic stored data.
      sources[n++] = WRITABLE_PATH;
    }
  }
  else
  {
    // Use passed scope as client wishes.
    n = GetSearchSources(file, searchScope, sources);
  }

#ifdef DEBUG
  DbgLogger logger(file);
#endif<commit_msg>Bugfix. Car routing on android platform.<commit_after>#include "platform/platform.hpp"
#include "platform/platform_unix_impl.hpp"
#include "platform/constants.hpp"
#include "platform/settings.hpp"

#include "coding/zip_reader.hpp"
#include "coding/file_name_utils.hpp"

#include "base/logging.hpp"
#include "base/thread.hpp"
#include "base/regexp.hpp"
#include "base/string_utils.hpp"

#include <unistd.h>     // for sysconf
#include <sys/stat.h>

Platform::Platform()
{
  /// @see initialization routine in android/jni/com/.../Platform.hpp
}

namespace
{
enum SourceT
{
  EXTERNAL_RESOURCE,
  RESOURCE,
  WRITABLE_PATH,
  SETTINGS_PATH,
  FULL_PATH,
  SOURCE_COUNT
};

bool IsResource(string const & file, string const & ext)
{
  if (ext == DATA_FILE_EXTENSION)
  {
    return (strings::StartsWith(file, WORLD_COASTS_FILE_NAME) ||
            strings::StartsWith(file, WORLD_FILE_NAME));
  }
  else if (ext == BOOKMARKS_FILE_EXTENSION ||
           ext == ROUTING_FILE_EXTENSION ||
           file == SETTINGS_FILE_NAME)
  {
    return false;
  }

  return true;
}

size_t GetSearchSources(string const & file, string const & searchScope,
                        SourceT (&arr)[SOURCE_COUNT])
{
  size_t ret = 0;

  for (size_t i = 0; i < searchScope.size(); ++i)
  {
    switch (searchScope[i])
    {
    case 'w': arr[ret++] = WRITABLE_PATH; break;
    case 'r': arr[ret++] = RESOURCE; break;
    case 'e': arr[ret++] = EXTERNAL_RESOURCE; break;
    case 's': arr[ret++] = SETTINGS_PATH; break;
    case 'f':
      if (strings::StartsWith(file, "/"))
        arr[ret++] = FULL_PATH;
      break;
    default : CHECK(false, ("Unsupported searchScope:", searchScope)); break;
    }
  }

  return ret;
}

#ifdef DEBUG
class DbgLogger
{
  string const & m_file;
  SourceT m_src;
public:
  DbgLogger(string const & file) : m_file(file) {}
  void SetSource(SourceT src) { m_src = src; }
  ~DbgLogger()
  {
    LOG(LDEBUG, ("Source for file", m_file, "is", m_src));
  }
};
#endif

}

ModelReader * Platform::GetReader(string const & file, string const & searchScope) const
{
  string const ext = my::GetFileExtension(file);
  ASSERT(!ext.empty(), ());

  uint32_t const logPageSize = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_SIZE : 10;
  uint32_t const logPageCount = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_COUNT : 4;

  SourceT sources[SOURCE_COUNT];
  size_t n = 0;

  if (searchScope.empty())
  {
    // Default behaviour - use predefined scope for resource files and writable path for all others.

    if (IsResource(file, ext))
      n = GetSearchSources(file, m_androidDefResScope, sources);
    else
    {
      // Add source for map files and other dynamic stored data.
      sources[n++] = WRITABLE_PATH;
      sources[n++] = FULL_PATH;
    }
  }
  else
  {
    // Use passed scope as client wishes.
    n = GetSearchSources(file, searchScope, sources);
  }

#ifdef DEBUG
  DbgLogger logger(file);
#endif
{'fraction_non_alphanumeric': 0.1322742186150924, 'fraction_numerical': 0.003453634950785702, 'mean_word_length': 3.4864446165762972, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6117831', 'n_tokens_mistral': 2058, 'n_tokens_neox': 2019, 'n_words': 478}