Delete unused code in rtc_base/stringutils.*
Delete functions: string_match, tolowercase, asccmp, ascicmp, ascncmp,
ascnicmp, asccpyn, ascii_string_compare.
Bug: webrtc:6424
Change-Id: I2dbbfae216c86b315654f22da27e04e9b3bad5a0
Reviewed-on: https://webrtc-review.googlesource.com/c/105980
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25203}
diff --git a/rtc_base/stringutils.cc b/rtc_base/stringutils.cc
index 35153ab..db48ec7 100644
--- a/rtc_base/stringutils.cc
+++ b/rtc_base/stringutils.cc
@@ -14,89 +14,6 @@
namespace rtc {
-bool memory_check(const void* memory, int c, size_t count) {
- const char* char_memory = static_cast<const char*>(memory);
- char char_c = static_cast<char>(c);
- for (size_t i = 0; i < count; ++i) {
- if (char_memory[i] != char_c) {
- return false;
- }
- }
- return true;
-}
-
-bool string_match(const char* target, const char* pattern) {
- while (*pattern) {
- if (*pattern == '*') {
- if (!*++pattern) {
- return true;
- }
- while (*target) {
- if ((toupper(*pattern) == toupper(*target)) &&
- string_match(target + 1, pattern + 1)) {
- return true;
- }
- ++target;
- }
- return false;
- } else {
- if (toupper(*pattern) != toupper(*target)) {
- return false;
- }
- ++target;
- ++pattern;
- }
- }
- return !*target;
-}
-
-#if defined(WEBRTC_WIN)
-int ascii_string_compare(const wchar_t* s1,
- const char* s2,
- size_t n,
- CharacterTransformation transformation) {
- wchar_t c1, c2;
- while (true) {
- if (n-- == 0)
- return 0;
- c1 = transformation(*s1);
- // Double check that characters are not UTF-8
- RTC_DCHECK_LT(*s2, 128);
- // Note: *s2 gets implicitly promoted to wchar_t
- c2 = transformation(*s2);
- if (c1 != c2)
- return (c1 < c2) ? -1 : 1;
- if (!c1)
- return 0;
- ++s1;
- ++s2;
- }
-}
-
-size_t asccpyn(wchar_t* buffer,
- size_t buflen,
- const char* source,
- size_t srclen) {
- if (buflen <= 0)
- return 0;
-
- if (srclen == SIZE_UNKNOWN) {
- srclen = strlenn(source, buflen - 1);
- } else if (srclen >= buflen) {
- srclen = buflen - 1;
- }
-#if RTC_DCHECK_IS_ON
- // Double check that characters are not UTF-8
- for (size_t pos = 0; pos < srclen; ++pos)
- RTC_DCHECK_LT(source[pos], 128);
-#endif
- std::copy(source, source + srclen, buffer);
- buffer[srclen] = 0;
- return srclen;
-}
-
-#endif // WEBRTC_WIN
-
void replace_substrs(const char* search,
size_t search_len,
const char* replace,
diff --git a/rtc_base/stringutils.h b/rtc_base/stringutils.h
index 367a673..2d9228b 100644
--- a/rtc_base/stringutils.h
+++ b/rtc_base/stringutils.h
@@ -40,35 +40,6 @@
#define STACK_ARRAY(TYPE, LEN) \
static_cast<TYPE*>(::alloca((LEN) * sizeof(TYPE)))
-namespace rtc {
-
-// Determines whether the simple wildcard pattern matches target.
-// Alpha characters in pattern match case-insensitively.
-// Asterisks in pattern match 0 or more characters.
-// Ex: string_match("www.TEST.GOOGLE.COM", "www.*.com") -> true
-bool string_match(const char* target, const char* pattern);
-
-} // namespace rtc
-
-///////////////////////////////////////////////////////////////////////////////
-// Rename a few common string functions so they are consistent across platforms.
-// tolowercase is like tolower, but not compatible with end-of-file value
-//
-// It's not clear if we will ever use wchar_t strings on unix. In theory,
-// all strings should be Utf8 all the time, except when interfacing with Win32
-// APIs that require Utf16.
-///////////////////////////////////////////////////////////////////////////////
-inline char tolowercase(char c) {
- return static_cast<char>(tolower(c));
-}
-
-#if defined(WEBRTC_WIN)
-
-inline wchar_t tolowercase(wchar_t c) {
- return static_cast<wchar_t>(towlower(c));
-}
-
-#endif // WEBRTC_WIN
#if defined(WEBRTC_POSIX)
@@ -197,60 +168,6 @@
}
///////////////////////////////////////////////////////////////////////////////
-// Allow safe comparing and copying ascii (not UTF-8) with both wide and
-// non-wide character strings.
-///////////////////////////////////////////////////////////////////////////////
-
-inline int asccmp(const char* s1, const char* s2) {
- return strcmp(s1, s2);
-}
-inline int ascicmp(const char* s1, const char* s2) {
- return _stricmp(s1, s2);
-}
-inline int ascncmp(const char* s1, const char* s2, size_t n) {
- return strncmp(s1, s2, n);
-}
-inline int ascnicmp(const char* s1, const char* s2, size_t n) {
- return _strnicmp(s1, s2, n);
-}
-inline size_t asccpyn(char* buffer,
- size_t buflen,
- const char* source,
- size_t srclen = SIZE_UNKNOWN) {
- return strcpyn(buffer, buflen, source, srclen);
-}
-
-#if defined(WEBRTC_WIN)
-
-typedef wchar_t (*CharacterTransformation)(wchar_t);
-inline wchar_t identity(wchar_t c) {
- return c;
-}
-int ascii_string_compare(const wchar_t* s1,
- const char* s2,
- size_t n,
- CharacterTransformation transformation);
-
-inline int asccmp(const wchar_t* s1, const char* s2) {
- return ascii_string_compare(s1, s2, static_cast<size_t>(-1), identity);
-}
-inline int ascicmp(const wchar_t* s1, const char* s2) {
- return ascii_string_compare(s1, s2, static_cast<size_t>(-1), tolowercase);
-}
-inline int ascncmp(const wchar_t* s1, const char* s2, size_t n) {
- return ascii_string_compare(s1, s2, n, identity);
-}
-inline int ascnicmp(const wchar_t* s1, const char* s2, size_t n) {
- return ascii_string_compare(s1, s2, n, tolowercase);
-}
-size_t asccpyn(wchar_t* buffer,
- size_t buflen,
- const char* source,
- size_t srclen = SIZE_UNKNOWN);
-
-#endif // WEBRTC_WIN
-
-///////////////////////////////////////////////////////////////////////////////
// Traits<char> specializations
///////////////////////////////////////////////////////////////////////////////
diff --git a/rtc_base/stringutils_unittest.cc b/rtc_base/stringutils_unittest.cc
index a6e6468..663e976 100644
--- a/rtc_base/stringutils_unittest.cc
+++ b/rtc_base/stringutils_unittest.cc
@@ -13,70 +13,6 @@
namespace rtc {
-// Tests for string_match().
-
-TEST(string_matchTest, Matches) {
- EXPECT_TRUE(string_match("A.B.C.D", "a.b.c.d"));
- EXPECT_TRUE(string_match("www.TEST.GOOGLE.COM", "www.*.com"));
- EXPECT_TRUE(string_match("127.0.0.1", "12*.0.*1"));
- EXPECT_TRUE(string_match("127.1.0.21", "12*.0.*1"));
- EXPECT_FALSE(string_match("127.0.0.0", "12*.0.*1"));
- EXPECT_FALSE(string_match("127.0.0.0", "12*.0.*1"));
- EXPECT_FALSE(string_match("127.1.1.21", "12*.0.*1"));
-}
-
-// It's not clear if we will ever use wchar_t strings on unix. In theory,
-// all strings should be Utf8 all the time, except when interfacing with Win32
-// APIs that require Utf16.
-
-#if defined(WEBRTC_WIN)
-
-// Tests for ascii_string_compare().
-
-// Tests null input.
-TEST(ascii_string_compareTest, NullInput) {
- // The following results in an access violation in
- // ascii_string_compare. Is this a bug or by design? stringutils.h
- // should document the expected behavior in this case.
-
- // EXPECT_EQ(0, ascii_string_compare(nullptr, nullptr, 1, identity));
-}
-
-// Tests comparing two strings of different lengths.
-TEST(ascii_string_compareTest, DifferentLengths) {
- EXPECT_EQ(-1, ascii_string_compare(L"Test", "Test1", 5, identity));
-}
-
-// Tests the case where the buffer size is smaller than the string
-// lengths.
-TEST(ascii_string_compareTest, SmallBuffer) {
- EXPECT_EQ(0, ascii_string_compare(L"Test", "Test1", 3, identity));
-}
-
-// Tests the case where the buffer is not full.
-TEST(ascii_string_compareTest, LargeBuffer) {
- EXPECT_EQ(0, ascii_string_compare(L"Test", "Test", 10, identity));
-}
-
-// Tests comparing two eqaul strings.
-TEST(ascii_string_compareTest, Equal) {
- EXPECT_EQ(0, ascii_string_compare(L"Test", "Test", 5, identity));
- EXPECT_EQ(0, ascii_string_compare(L"TeSt", "tEsT", 5, tolowercase));
-}
-
-// Tests comparing a smller string to a larger one.
-TEST(ascii_string_compareTest, LessThan) {
- EXPECT_EQ(-1, ascii_string_compare(L"abc", "abd", 4, identity));
- EXPECT_EQ(-1, ascii_string_compare(L"ABC", "abD", 5, tolowercase));
-}
-
-// Tests comparing a larger string to a smaller one.
-TEST(ascii_string_compareTest, GreaterThan) {
- EXPECT_EQ(1, ascii_string_compare(L"xyz", "xy", 5, identity));
- EXPECT_EQ(1, ascii_string_compare(L"abc", "ABB", 5, tolowercase));
-}
-#endif // WEBRTC_WIN
-
TEST(string_trim_Test, Trimming) {
EXPECT_EQ("temp", string_trim("\n\r\t temp \n\r\t"));
EXPECT_EQ("temp\n\r\t temp", string_trim(" temp\n\r\t temp "));