diff options
author | vng <viktor.govako@gmail.com> | 2015-07-03 20:23:05 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:54:14 +0300 |
commit | c966bfed30e064149cf8f9c6aa06d9281a5a5c21 (patch) | |
tree | d6b8bfc3fa7b822c16fd140f1c5461a39ea3f6ae /coding | |
parent | 7494c3f57668407158a8ef12282e66328553295f (diff) |
[platform]
Replaced Platform::AddOptionalPath with Platform::SetResourceDir.
Added Platform::TestsDataPathForFile to read test files (usually placed in resource directory) in unit tests.
Diffstat (limited to 'coding')
-rw-r--r-- | coding/coding_tests/file_utils_test.cpp | 15 | ||||
-rw-r--r-- | coding/file_name_utils.cpp | 36 | ||||
-rw-r--r-- | coding/file_name_utils.hpp | 3 |
3 files changed, 41 insertions, 13 deletions
diff --git a/coding/coding_tests/file_utils_test.cpp b/coding/coding_tests/file_utils_test.cpp index bba7856b39..c742fc2284 100644 --- a/coding/coding_tests/file_utils_test.cpp +++ b/coding/coding_tests/file_utils_test.cpp @@ -59,3 +59,18 @@ UNIT_TEST(FileName_GetDirectory) TEST_EQUAL(".", my::GetDirectory("somefile"), ()); #endif // !defined(OMIM_OS_WINDOWS) } + +UNIT_TEST(FilePath_Slash) +{ +#ifndef OMIM_OS_WINDOWS + TEST_EQUAL("/", my::AddSlashIfNeeded(""), ()); + TEST_EQUAL("/", my::AddSlashIfNeeded("/"), ()); + TEST_EQUAL("./", my::AddSlashIfNeeded("."), ()); + TEST_EQUAL("data/", my::AddSlashIfNeeded("data"), ()); + TEST_EQUAL("data/", my::AddSlashIfNeeded("data/"), ()); + TEST_EQUAL("/data/", my::AddSlashIfNeeded("/data"), ()); + TEST_EQUAL("/data/", my::AddSlashIfNeeded("/data/"), ()); + TEST_EQUAL("../../data/", my::AddSlashIfNeeded("../../data"), ()); + TEST_EQUAL("../../data/", my::AddSlashIfNeeded("../../data/"), ()); +#endif +} diff --git a/coding/file_name_utils.cpp b/coding/file_name_utils.cpp index 063e1c67d7..b2e44146f0 100644 --- a/coding/file_name_utils.cpp +++ b/coding/file_name_utils.cpp @@ -49,32 +49,42 @@ string GetNativeSeparator() string JoinFoldersToPath(const string & folder, const string & file) { - return folder + GetNativeSeparator() + file; + return folder + GetNativeSeparator() + file; } string JoinFoldersToPath(const string & folder1, const string & folder2, const string & file) { - string nativeSeparator = GetNativeSeparator(); - return folder1 + nativeSeparator + folder2 + nativeSeparator + file; + string nativeSeparator = GetNativeSeparator(); + return folder1 + nativeSeparator + folder2 + nativeSeparator + file; } string JoinFoldersToPath(const string & folder1, const string & folder2, const string & folder3, const string & file) { - string nativeSeparator = GetNativeSeparator(); - return folder1 + nativeSeparator + folder2 + nativeSeparator + folder3 + nativeSeparator + file; + string nativeSeparator = GetNativeSeparator(); + return folder1 + nativeSeparator + folder2 + nativeSeparator + folder3 + nativeSeparator + file; } string JoinFoldersToPath(const vector<string> & folders, const string & file) { - if (folders.empty()) - return file; + if (folders.empty()) + return file; - string nativeSeparator = GetNativeSeparator(); - string result; - for (size_t i = 0; i < folders.size(); ++i) - result = result + folders[i] + nativeSeparator; + string nativeSeparator = GetNativeSeparator(); + string result; + for (size_t i = 0; i < folders.size(); ++i) + result = result + folders[i] + nativeSeparator; - result += file; - return result; + result += file; + return result; } + +string AddSlashIfNeeded(string const & path) +{ + string const sep = GetNativeSeparator(); + string::size_type const pos = path.rfind(sep); + if ((pos != string::npos) && (pos == path.size() - sep.size())) + return path; + return path + sep; +} + } // namespace my diff --git a/coding/file_name_utils.hpp b/coding/file_name_utils.hpp index ddef2af4a9..f738588acd 100644 --- a/coding/file_name_utils.hpp +++ b/coding/file_name_utils.hpp @@ -26,4 +26,7 @@ namespace my string JoinFoldersToPath(const string & folder1, const string & folder2, const string & file); string JoinFoldersToPath(const string & folder1, const string & folder2, const string & folder3, const string & file); string JoinFoldersToPath(const vector<string> & folders, const string & file); + + /// Add terminating slash, if it's not exist to the folder path string. + string AddSlashIfNeeded(string const & path); } |