diff options
author | Herb Derby <herb@google.com> | 2018-05-14 15:05:58 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-14 20:18:19 +0000 |
commit | 8fb2e5c3993fabfe25ba3f7c5ce2b92786c18c97 (patch) | |
tree | c4feea43c049c15ba78b1ddd2d704beac1484c74 /src | |
parent | 84f7c2b3c1a5a405f579ee0e34ebb82ab02de16e (diff) |
Centralize UTFN code point counting
Change-Id: Ifd6bdcb4ac88452ab01124777168b140cae965a9
Reviewed-on: https://skia-review.googlesource.com/128014
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkUtils.cpp | 28 | ||||
-rw-r--r-- | src/core/SkUtils.h | 2 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/core/SkUtils.cpp b/src/core/SkUtils.cpp index d8ba2b39c1..0b92510bb0 100644 --- a/src/core/SkUtils.cpp +++ b/src/core/SkUtils.cpp @@ -372,12 +372,6 @@ size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues, return size; } -const char SkHexadecimalDigits::gUpper[16] = - { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; -const char SkHexadecimalDigits::gLower[16] = - { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - - // returns -1 on error int SkUTF32_CountUnichars(const void* text, size_t byteLength) { if (byteLength == 0) { @@ -398,3 +392,25 @@ int SkUTF32_CountUnichars(const void* text, size_t byteLength) { return SkToInt(byteLength >> 2); } +// returns -1 on error +int SkUTFN_CountUnichars( + SkTypeface::Encoding encoding, const void* utfN, size_t byteLength) { + SkASSERT(utfN != nullptr); + switch (encoding) { + case SkTypeface::kUTF8_Encoding: + return SkUTF8_CountUnichars(utfN, byteLength); + case SkTypeface::kUTF16_Encoding: + return SkUTF16_CountUnichars(utfN, byteLength); + case SkTypeface::kUTF32_Encoding: + return SkUTF32_CountUnichars(utfN, byteLength); + default: + SkDEBUGFAIL("unknown text encoding"); + } + + return -1; +} + +const char SkHexadecimalDigits::gUpper[16] = + { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; +const char SkHexadecimalDigits::gLower[16] = + { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
\ No newline at end of file diff --git a/src/core/SkUtils.h b/src/core/SkUtils.h index 9d7c64524f..6037b60c3c 100644 --- a/src/core/SkUtils.h +++ b/src/core/SkUtils.h @@ -11,6 +11,7 @@ #include "SkTypes.h" #include "SkMath.h" #include "SkOpts.h" +#include "SkTypeface.h" /** Similar to memset(), but it assigns a 16, 32, or 64-bit value into the buffer. @param buffer The memory to have value copied into it @@ -47,6 +48,7 @@ int SkUTF8_CountUnichars(const char utf8[]); int SkUTF8_CountUnichars(const void* utf8, size_t byteLength); int SkUTF16_CountUnichars(const void* utf16, size_t byteLength); int SkUTF32_CountUnichars(const void* utf32, size_t byteLength); +int SkUTFN_CountUnichars(SkTypeface::Encoding encoding, const void* utfN, size_t byteLength); /** This function is safe: invalid UTF8 sequences will return -1 * When -1 is returned, ptr is unchanged. |