From 6f1dcdd9ede0f0158bc41c964b7bdf5786555700 Mon Sep 17 00:00:00 2001 From: vng Date: Mon, 28 Jan 2013 02:18:48 +0300 Subject: [PATCH] Move file_name_utils into coding. --- coding/coding.pro | 2 ++ coding/coding_tests/coding_tests.pro | 1 + coding/coding_tests/file_utils_test.cpp | 35 ++++++++++++++++++++++++ {platform => coding}/file_name_utils.cpp | 9 ++---- {platform => coding}/file_name_utils.hpp | 7 ++--- indexer/index.cpp | 6 ++-- platform/platform.pro | 2 -- storage/storage.cpp | 1 - 8 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 coding/coding_tests/file_utils_test.cpp rename {platform => coding}/file_name_utils.cpp (69%) rename {platform => coding}/file_name_utils.hpp (54%) diff --git a/coding/coding.pro b/coding/coding.pro index 00533454c1..88bbd56a13 100644 --- a/coding/coding.pro +++ b/coding/coding.pro @@ -32,6 +32,7 @@ SOURCES += \ blob_storage.cpp \ uri.cpp \ zip_creator.cpp \ + file_name_utils.cpp \ HEADERS += \ internal/xmlparser.h \ @@ -91,3 +92,4 @@ HEADERS += \ blob_storage.hpp \ uri.hpp \ zip_creator.hpp \ + file_name_utils.hpp \ diff --git a/coding/coding_tests/coding_tests.pro b/coding/coding_tests/coding_tests.pro index 9a4499e7a6..c15dac9b33 100644 --- a/coding/coding_tests/coding_tests.pro +++ b/coding/coding_tests/coding_tests.pro @@ -44,6 +44,7 @@ SOURCES += ../../testing/testingmain.cpp \ blob_storage_test.cpp \ uri_test.cpp \ zip_creator_test.cpp \ + file_utils_test.cpp \ HEADERS += \ reader_test.hpp \ diff --git a/coding/coding_tests/file_utils_test.cpp b/coding/coding_tests/file_utils_test.cpp new file mode 100644 index 0000000000..73aa71c766 --- /dev/null +++ b/coding/coding_tests/file_utils_test.cpp @@ -0,0 +1,35 @@ +#include "../../testing/testing.hpp" + +#include "../file_name_utils.hpp" + + +UNIT_TEST(FileName_Smoke) +{ + string name = "/Users/xxx/Documents/test.test"; + my::GetNameFromFullPath(name); + TEST_EQUAL(name, "test.test", ()); + my::GetNameFromFullPath(name); + TEST_EQUAL(name, "test.test", ()); + my::GetNameWithoutExt(name); + TEST_EQUAL(name, "test", ()); + + name = "C:\\My Documents\\test.test"; + my::GetNameFromFullPath(name); + TEST_EQUAL(name, "test.test", ()); + my::GetNameWithoutExt(name); + TEST_EQUAL(name, "test", ()); + + name = "/"; + my::GetNameFromFullPath(name); + TEST(name.empty(), ()); + + name = "C:\\"; + my::GetNameFromFullPath(name); + TEST(name.empty(), ()); + + name = "../test"; + my::GetNameFromFullPath(name); + TEST_EQUAL(name, "test", ()); + my::GetNameWithoutExt(name); + TEST_EQUAL(name, "test", ()); +} diff --git a/platform/file_name_utils.cpp b/coding/file_name_utils.cpp similarity index 69% rename from platform/file_name_utils.cpp rename to coding/file_name_utils.cpp index 888c90adc9..0976a1ba93 100644 --- a/platform/file_name_utils.cpp +++ b/coding/file_name_utils.cpp @@ -1,7 +1,7 @@ #include "file_name_utils.hpp" -namespace pl +namespace my { void GetNameWithoutExt(string & name) @@ -11,16 +11,11 @@ void GetNameWithoutExt(string & name) name.erase(i); } -void GetNameFromURLRequest(string & name) +void GetNameFromFullPath(string & name) { string::size_type const i = name.find_last_of("/\\"); if (i != string::npos) name = name.substr(i+1); } -void GetNameFromPath(string & name) -{ - GetNameFromURLRequest(name); -} - } diff --git a/platform/file_name_utils.hpp b/coding/file_name_utils.hpp similarity index 54% rename from platform/file_name_utils.hpp rename to coding/file_name_utils.hpp index 5bbad6b31f..8cc8b1e60c 100644 --- a/platform/file_name_utils.hpp +++ b/coding/file_name_utils.hpp @@ -2,14 +2,11 @@ #include "../std/string.hpp" -namespace pl +namespace my { /// Remove extension from file name. void GetNameWithoutExt(string & name); - /// Get file name from download url. - void GetNameFromURLRequest(string & name); - /// Get file name from full path. - void GetNameFromPath(string & name); + void GetNameFromFullPath(string & name); } diff --git a/indexer/index.cpp b/indexer/index.cpp index 979b07c7bf..788b08b47d 100644 --- a/indexer/index.cpp +++ b/indexer/index.cpp @@ -2,8 +2,8 @@ #include "data_header.hpp" #include "../platform/platform.hpp" -#include "../platform/file_name_utils.hpp" +#include "../coding/file_name_utils.hpp" #include "../coding/internal/file_data.hpp" @@ -20,8 +20,8 @@ MwmValue::MwmValue(string const & name) string MwmValue::GetFileName() const { string s = m_cont.GetFileName(); - pl::GetNameFromPath(s); - pl::GetNameWithoutExt(s); + my::GetNameFromFullPath(s); + my::GetNameWithoutExt(s); return s; } diff --git a/platform/platform.pro b/platform/platform.pro index 4572240ac3..75fe5000a7 100644 --- a/platform/platform.pro +++ b/platform/platform.pro @@ -67,7 +67,6 @@ HEADERS += \ chunks_download_strategy.hpp \ servers_list.hpp \ constants.hpp \ - file_name_utils.hpp \ SOURCES += \ preferred_languages.cpp \ @@ -77,4 +76,3 @@ SOURCES += \ chunks_download_strategy.cpp \ platform.cpp \ servers_list.cpp \ - file_name_utils.cpp \ diff --git a/storage/storage.cpp b/storage/storage.cpp index 4353118421..00201aa16a 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -7,7 +7,6 @@ #include "../platform/platform.hpp" #include "../platform/servers_list.hpp" -#include "../platform/file_name_utils.hpp" #include "../platform/settings.hpp" #include "../coding/file_writer.hpp"