Chromium Code Reviews| Index: include/core/SkTSearch.h |
| diff --git a/include/core/SkTSearch.h b/include/core/SkTSearch.h |
| index a4e4994ef378b2b14a39c1da2daa601c35677f71..3493996656a0466889c1b2a569034a84970ba830 100644 |
| --- a/include/core/SkTSearch.h |
| +++ b/include/core/SkTSearch.h |
| @@ -11,6 +11,7 @@ |
| #define SkTSearch_DEFINED |
| #include "SkTypes.h" |
| +#include <ctype.h> |
| /** |
| * All of the SkTSearch variants want to return the index (0...N-1) of the |
| @@ -125,8 +126,39 @@ int SkStrLCSearch(const char*const* base, int count, const char target[], |
| */ |
| class SkAutoAsciiToLC { |
| public: |
| - SkAutoAsciiToLC(const char str[], size_t len = (size_t)-1); |
| - ~SkAutoAsciiToLC(); |
| + SkAutoAsciiToLC(const char str[], size_t len = (size_t)-1) { |
|
reed1
2013/11/15 18:20:12
Not sure I agree with this one.
1. This class doe
mtklein
2013/11/15 18:28:14
Reverted.
|
| + // see if we need to compute the length |
| + if ((long)len < 0) { |
| + len = strlen(str); |
| + } |
| + fLength = len; |
| + |
| + // assign lc to our preallocated storage if len is small enough, or allocate |
| + // it on the heap |
| + char* lc; |
| + if (len <= STORAGE) { |
| + lc = fStorage; |
| + } else { |
| + lc = (char*)sk_malloc_throw(len + 1); |
| + } |
| + fLC = lc; |
| + |
| + // convert any asii to lower-case. we let non-ascii (utf8) chars pass |
| + // through unchanged |
| + for (int i = (int)(len - 1); i >= 0; --i) { |
| + int c = str[i]; |
| + if ((c & 0x80) == 0) { // is just ascii |
| + c = tolower(c); |
| + } |
| + lc[i] = c; |
| + } |
| + lc[len] = 0; |
| + } |
| + ~SkAutoAsciiToLC() { |
| + if (fLC != fStorage) { |
| + sk_free(fLC); |
| + } |
| + } |
| const char* lc() const { return fLC; } |
| size_t length() const { return fLength; } |
| @@ -139,6 +171,7 @@ private: |
| }; |
| char fStorage[STORAGE+1]; |
| }; |
| +#define SkAutoAsciiToLC(...) SK_REQUIRE_LOCAL_VAR(SkAutoAsciiToLC) |
| // Helper when calling qsort with a compare proc that has typed its arguments |
| #define SkCastForQSort(compare) reinterpret_cast<int (*)(const void*, const void*)>(compare) |