diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-08-05 15:23:56 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-08-05 15:23:56 -0700 |
commit | 54881d9f90acfb1676b3eebb0feb17811d1cc4bf (patch) | |
tree | 4bbadb21100a85dc7d95e4fd844e3e3839645860 | |
parent | a09abace8d4ec0d2fc9bb65493dfae7b7ce8e0fe (diff) |
Use SystemAbstractions::ToLower instead of doing it ourselves
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/NormalizeCaseInsensitiveString.cpp | 24 | ||||
-rw-r--r-- | src/NormalizeCaseInsensitiveString.hpp | 30 | ||||
-rw-r--r-- | src/Uri.cpp | 8 | ||||
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/src/NormalizeCaseInsensitiveStringTests.cpp | 41 |
6 files changed, 8 insertions, 102 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6168290..d764ffe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,13 +8,11 @@ set(This Uri) set(Headers include/Uri/Uri.hpp src/CharacterSet.hpp - src/NormalizeCaseInsensitiveString.hpp src/PercentEncodedCharacterDecoder.hpp ) set(Sources src/CharacterSet.cpp - src/NormalizeCaseInsensitiveString.cpp src/PercentEncodedCharacterDecoder.cpp src/Uri.cpp ) @@ -26,4 +24,8 @@ set_target_properties(${This} PROPERTIES target_include_directories(${This} PUBLIC include) +target_link_libraries(${This} PUBLIC + SystemAbstractions +) + add_subdirectory(test) diff --git a/src/NormalizeCaseInsensitiveString.cpp b/src/NormalizeCaseInsensitiveString.cpp deleted file mode 100644 index 761c72a..0000000 --- a/src/NormalizeCaseInsensitiveString.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @file NormalizeCaseInsensitiveString.cpp - * - * This module contains the implementation of the - * Uri::NormalizeCaseInsensitiveString function. - * - * © 2018 by Richard Walters - */ - -#include "NormalizeCaseInsensitiveString.hpp" - -#include <ctype.h> - -namespace Uri { - - std::string NormalizeCaseInsensitiveString(const std::string& inString) { - std::string outString; - for (char c: inString) { - outString.push_back(tolower(c)); - } - return outString; - } - -} diff --git a/src/NormalizeCaseInsensitiveString.hpp b/src/NormalizeCaseInsensitiveString.hpp deleted file mode 100644 index 014dd74..0000000 --- a/src/NormalizeCaseInsensitiveString.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef URI_NORMALIZE_CASE_INSENSITIVE_STRING_HPP -#define URI_NORMALIZE_CASE_INSENSITIVE_STRING_HPP - -/** - * @file NormalizeCaseInsensitiveString.hpp - * - * This module declares the Uri::NormalizeCaseInsensitiveString function. - * - * © 2018 by Richard Walters - */ - -#include <string> - -namespace Uri { - - /** - * This function takes a string and swaps all upper-case characters - * with their lower-case equivalents, returning the result. - * - * @param[in] inString - * This is the string to be normalized. - * - * @return - * The normalized string is returned. All upper-case characters - * are replaced with their lower-case equivalents. - */ - std::string NormalizeCaseInsensitiveString(const std::string& inString); -} - -#endif /* URI_NORMALIZE_CASE_INSENSITIVE_STRING_HPP */ diff --git a/src/Uri.cpp b/src/Uri.cpp index cb44c1e..4d08e38 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -7,7 +7,6 @@ */ #include "CharacterSet.hpp" -#include "NormalizeCaseInsensitiveString.hpp" #include "PercentEncodedCharacterDecoder.hpp" #include <algorithm> @@ -16,6 +15,7 @@ #include <memory> #include <sstream> #include <string> +#include <SystemAbstractions/StringExtensions.hpp> #include <Uri/Uri.hpp> #include <vector> @@ -869,7 +869,7 @@ namespace Uri { return false; } if (hostIsRegName) { - host = NormalizeCaseInsensitiveString(host); + host = SystemAbstractions::ToLower(host); } if (portString.empty()) { hasPort = false; @@ -926,7 +926,7 @@ namespace Uri { ) { return false; } - scheme = NormalizeCaseInsensitiveString(scheme); + scheme = SystemAbstractions::ToLower(scheme); rest = uriString.substr(schemeEnd + 1); } return true; @@ -1439,7 +1439,7 @@ namespace Uri { } if (!impl_->host.empty()) { if (ValidateIpv6Address(impl_->host)) { - buffer << '[' << NormalizeCaseInsensitiveString(impl_->host) << ']'; + buffer << '[' << SystemAbstractions::ToLower(impl_->host) << ']'; } else { buffer << EncodeElement(impl_->host, REG_NAME_NOT_PCT_ENCODED); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f2fc59..a7f6320 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,6 @@ set(This UriTests) set(Sources src/UriTests.cpp src/CharacterSetTests.cpp - src/NormalizeCaseInsensitiveStringTests.cpp src/PercentEncodedCharacterDecoderTests.cpp ) diff --git a/test/src/NormalizeCaseInsensitiveStringTests.cpp b/test/src/NormalizeCaseInsensitiveStringTests.cpp deleted file mode 100644 index f68d344..0000000 --- a/test/src/NormalizeCaseInsensitiveStringTests.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @file NormalizeCaseInsensitiveStringTests.cpp - * - * This module contains the unit tests of the Uri::NormalizeCaseInsensitiveString class. - * - * © 2018 by Richard Walters - */ - -#include <gtest/gtest.h> -#include <src/NormalizeCaseInsensitiveString.hpp> - -TEST(NormalizeCaseInsensitiveStringTests, NormalizeCaseInsensitiveString) { - ASSERT_EQ( - "example", - Uri::NormalizeCaseInsensitiveString("eXAmplE") - ); - ASSERT_EQ( - "example", - Uri::NormalizeCaseInsensitiveString("example") - ); - ASSERT_EQ( - "example", - Uri::NormalizeCaseInsensitiveString("EXAMPLE") - ); - ASSERT_EQ( - "foo1bar", - Uri::NormalizeCaseInsensitiveString("foo1BAR") - ); - ASSERT_EQ( - "foo1bar", - Uri::NormalizeCaseInsensitiveString("fOo1bAr") - ); - ASSERT_EQ( - "foo1bar", - Uri::NormalizeCaseInsensitiveString("foo1bar") - ); - ASSERT_EQ( - "foo1bar", - Uri::NormalizeCaseInsensitiveString("FOO1BAR") - ); -} |