aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkUtils.cpp
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-05-14 15:05:58 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-14 20:18:19 +0000
commit8fb2e5c3993fabfe25ba3f7c5ce2b92786c18c97 (patch)
treec4feea43c049c15ba78b1ddd2d704beac1484c74 /src/core/SkUtils.cpp
parent84f7c2b3c1a5a405f579ee0e34ebb82ab02de16e (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/core/SkUtils.cpp')
-rw-r--r--src/core/SkUtils.cpp28
1 files changed, 22 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