| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1e99643 commit 477e61d
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,7 +69,6 @@ | |||
| 69 | 69 | #if defined(_MSC_VER) | |
| 70 | 70 | #include <direct.h> | |
| 71 | 71 | #include <io.h> | |
| 72 | - #define strcasecmp _stricmp | ||
| 73 | 72 | #define getpid GetCurrentProcessId | |
| 74 | 73 | #define umask _umask | |
| 75 | 74 | typedef int mode_t; | |
@@ -1381,27 +1380,27 @@ enum encoding ParseEncoding(const char* encoding, | |||
| 1381 | 1380 | break; | |
| 1382 | 1381 | } | |
| 1383 | 1382 | ||
| 1384 | - if (strcasecmp(encoding, "utf8") == 0) { | ||
| 1383 | + if (StringEqualNoCase(encoding, "utf8")) { | ||
| 1385 | 1384 | return UTF8; | |
| 1386 | - } else if (strcasecmp(encoding, "utf-8") == 0) { | ||
| 1385 | + } else if (StringEqualNoCase(encoding, "utf-8")) { | ||
| 1387 | 1386 | return UTF8; | |
| 1388 | - } else if (strcasecmp(encoding, "ascii") == 0) { | ||
| 1387 | + } else if (StringEqualNoCase(encoding, "ascii")) { | ||
| 1389 | 1388 | return ASCII; | |
| 1390 | - } else if (strcasecmp(encoding, "base64") == 0) { | ||
| 1389 | + } else if (StringEqualNoCase(encoding, "base64")) { | ||
| 1391 | 1390 | return BASE64; | |
| 1392 | - } else if (strcasecmp(encoding, "ucs2") == 0) { | ||
| 1391 | + } else if (StringEqualNoCase(encoding, "ucs2")) { | ||
| 1393 | 1392 | return UCS2; | |
| 1394 | - } else if (strcasecmp(encoding, "ucs-2") == 0) { | ||
| 1393 | + } else if (StringEqualNoCase(encoding, "ucs-2")) { | ||
| 1395 | 1394 | return UCS2; | |
| 1396 | - } else if (strcasecmp(encoding, "utf16le") == 0) { | ||
| 1395 | + } else if (StringEqualNoCase(encoding, "utf16le")) { | ||
| 1397 | 1396 | return UCS2; | |
| 1398 | - } else if (strcasecmp(encoding, "utf-16le") == 0) { | ||
| 1397 | + } else if (StringEqualNoCase(encoding, "utf-16le")) { | ||
| 1399 | 1398 | return UCS2; | |
| 1400 | - } else if (strcasecmp(encoding, "binary") == 0) { | ||
| 1399 | + } else if (StringEqualNoCase(encoding, "binary")) { | ||
| 1401 | 1400 | return BINARY; | |
| 1402 | - } else if (strcasecmp(encoding, "buffer") == 0) { | ||
| 1401 | + } else if (StringEqualNoCase(encoding, "buffer")) { | ||
| 1403 | 1402 | return BUFFER; | |
| 1404 | - } else if (strcasecmp(encoding, "hex") == 0) { | ||
| 1403 | + } else if (StringEqualNoCase(encoding, "hex")) { | ||
| 1405 | 1404 | return HEX; | |
| 1406 | 1405 | } else { | |
| 1407 | 1406 | return default_encoding; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,10 +24,6 @@ | |||
| 24 | 24 | #include <stdlib.h> | |
| 25 | 25 | #include <string.h> | |
| 26 | 26 | ||
| 27 | - #if defined(_MSC_VER) | ||
| 28 | - #define strcasecmp _stricmp | ||
| 29 | - #endif | ||
| 30 | - | ||
| 31 | 27 | #define THROW_AND_RETURN_IF_NOT_STRING_OR_BUFFER(val, prefix) \ | |
| 32 | 28 | do { \ | |
| 33 | 29 | if (!Buffer::HasInstance(val) && !val->IsString()) { \ | |
@@ -4446,7 +4442,7 @@ void DiffieHellman::DiffieHellmanGroup( | |||
| 4446 | 4442 | for (size_t i = 0; i < arraysize(modp_groups); ++i) { | |
| 4447 | 4443 | const modp_group* it = modp_groups + i; | |
| 4448 | 4444 | ||
| 4449 | - if (strcasecmp(*group_name, it->name) != 0) | ||
| 4445 | + if (!StringEqualNoCase(*group_name, it->name)) | ||
| 4450 | 4446 | continue; | |
| 4451 | 4447 | ||
| 4452 | 4448 | initialized = diffieHellman->Init(it->prime, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -203,7 +203,19 @@ void SwapBytes(uint16_t* dst, const uint16_t* src, size_t buflen) { | |||
| 203 | 203 | dst[i] = (src[i] << 8) | (src[i] >> 8); | |
| 204 | 204 | } | |
| 205 | 205 | ||
| 206 | + char ToLower(char c) { | ||
| 207 | + return c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c; | ||
| 208 | + } | ||
| 206 | 209 | ||
| 210 | + bool StringEqualNoCase(const char* a, const char* b) { | ||
| 211 | + do { | ||
| 212 | + if (*a == '\0') | ||
| 213 | + return *b == '\0'; | ||
| 214 | + if (*b == '\0') | ||
| 215 | + return *a == '\0'; | ||
| 216 | + } while (ToLower(*a++) == ToLower(*b++)); | ||
| 217 | + return false; | ||
| 218 | + } | ||
| 207 | 219 | ||
| 208 | 220 | } // namespace node | |
| 209 | 221 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,6 +178,12 @@ inline TypeName* Unwrap(v8::Local<v8::Object> object); | |||
| 178 | 178 | ||
| 179 | 179 | inline void SwapBytes(uint16_t* dst, const uint16_t* src, size_t buflen); | |
| 180 | 180 | ||
| 181 | + // tolower() is locale-sensitive. Use ToLower() instead. | ||
| 182 | + inline char ToLower(char c); | ||
| 183 | + | ||
| 184 | + // strcasecmp() is locale-sensitive. Use StringEqualNoCase() instead. | ||
| 185 | + inline bool StringEqualNoCase(const char* a, const char* b); | ||
| 186 | + | ||
| 181 | 187 | // Allocates an array of member type T. For up to kStackStorageSize items, | |
| 182 | 188 | // the stack is used, otherwise malloc(). | |
| 183 | 189 | template <typename T, size_t kStackStorageSize = 1024> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,3 +56,21 @@ TEST(UtilTest, ListHead) { | |||
| 56 | 56 | EXPECT_TRUE(list.IsEmpty()); | |
| 57 | 57 | EXPECT_FALSE(list.begin() != list.end()); | |
| 58 | 58 | } | |
| 59 | + | ||
| 60 | + TEST(UtilTest, StringEqualNoCase) { | ||
| 61 | + using node::StringEqualNoCase; | ||
| 62 | + EXPECT_FALSE(StringEqualNoCase("a", "b")); | ||
| 63 | + EXPECT_TRUE(StringEqualNoCase("", "")); | ||
| 64 | + EXPECT_TRUE(StringEqualNoCase("equal", "equal")); | ||
| 65 | + EXPECT_TRUE(StringEqualNoCase("equal", "EQUAL")); | ||
| 66 | + EXPECT_TRUE(StringEqualNoCase("EQUAL", "EQUAL")); | ||
| 67 | + EXPECT_FALSE(StringEqualNoCase("equal", "equals")); | ||
| 68 | + EXPECT_FALSE(StringEqualNoCase("equals", "equal")); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + TEST(UtilTest, ToLower) { | ||
| 72 | + using node::ToLower; | ||
| 73 | + EXPECT_EQ('0', ToLower('0')); | ||
| 74 | + EXPECT_EQ('a', ToLower('a')); | ||
| 75 | + EXPECT_EQ('a', ToLower('A')); | ||
| 76 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments