Revert "Small changes for SkText that are not in experimental directory"

This reverts commit 92f1bc0083bf2fa1d7eca2857c0d837a8dcf1f17.

Reason for revert: Blocking Android roll.

Original change's description:
> Small changes for SkText that are not in experimental directory
>
> (also made utf 8<->16 conversion static on SkUnicode)
>
> Change-Id: Ie64d18ad21a35ec10bd0b350fb7887fb78a419d8
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/448140
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Julia Lavrova <jlavrova@google.com>

Change-Id: Ieb9eb0495dddfc0f9e9e74861b24efc0201fd520
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/448656
Auto-Submit: Brian Osman <brianosman@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
diff --git a/BUILD.gn b/BUILD.gn
index 54dc80f..f69f621 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1981,7 +1981,6 @@
       ":test",
       ":tool_utils",
       "experimental/skrive:tests",
-      "experimental/sktext:tests",
       "modules/skottie:tests",
       "modules/skparagraph:tests",
       "modules/sksg:tests",
diff --git a/experimental/sktext/src/Text.cpp b/experimental/sktext/src/Text.cpp
index b82f2d8..023b6d2 100644
--- a/experimental/sktext/src/Text.cpp
+++ b/experimental/sktext/src/Text.cpp
@@ -24,7 +24,7 @@
     // Fill out all code unit properties
     unicodeText->fCodeUnitProperties.push_back_n(utf16.size() + 1, CodeUnitFlags::kNoCodeUnitFlag);
     unicodeText->fUnicode->forEachCodepoint(unicodeText->fText8.c_str(), unicodeText->fText8.size(),
-    [&unicodeText, &utf16Index](SkUnichar unichar, int32_t start, int32_t end, size_t count) {
+    [&unicodeText, &utf16Index](SkUnichar unichar, int32_t start, int32_t end) {
         for (auto i = start; i < end; ++i) {
             unicodeText->fUTF16FromUTF8[i] = utf16Index;
         }
@@ -37,7 +37,7 @@
         // Get white spaces
     // TODO: It's a bug. We need to operate on utf16 indexes everywhere
     unicodeText->fUnicode->forEachCodepoint(unicodeText->fText8.c_str(), unicodeText->fText8.size(),
-       [&unicodeText](SkUnichar unichar, int32_t start, int32_t end, size_t count) {
+       [&unicodeText](SkUnichar unichar, int32_t start, int32_t end) {
             if (unicodeText->fUnicode->isWhitespace(unichar)) {
                 for (auto i = start; i < end; ++i) {
                     unicodeText->fCodeUnitProperties[i] |=  CodeUnitFlags::kPartOfWhiteSpace;
diff --git a/modules/skparagraph/src/ParagraphImpl.cpp b/modules/skparagraph/src/ParagraphImpl.cpp
index 8873bc4..44ef329 100644
--- a/modules/skparagraph/src/ParagraphImpl.cpp
+++ b/modules/skparagraph/src/ParagraphImpl.cpp
@@ -267,7 +267,7 @@
 
     // Get all spaces
     fUnicode->forEachCodepoint(fText.c_str(), fText.size(),
-       [this](SkUnichar unichar, int32_t start, int32_t end, int32_t count) {
+       [this](SkUnichar unichar, int32_t start, int32_t end) {
             if (fUnicode->isWhitespace(unichar)) {
                 for (auto i = start; i < end; ++i) {
                     fCodeUnitProperties[i] |=  CodeUnitFlags::kPartOfWhiteSpaceBreak;
diff --git a/modules/skunicode/include/SkUnicode.h b/modules/skunicode/include/SkUnicode.h
index 7978922..280bb91 100644
--- a/modules/skunicode/include/SkUnicode.h
+++ b/modules/skunicode/include/SkUnicode.h
@@ -115,6 +115,7 @@
         virtual bool isControl(SkUnichar utf8) = 0;
         virtual bool isWhitespace(SkUnichar utf8) = 0;
         virtual bool isSpace(SkUnichar utf8) = 0;
+        virtual SkString convertUtf16ToUtf8(const std::u16string& utf16) = 0;
         virtual SkString toUpper(const SkString&) = 0;
 
         // Methods used in SkShaper and SkText
@@ -137,43 +138,6 @@
         virtual bool getGraphemes
                (const char utf8[], int utf8Units, std::vector<Position>* results) = 0;
 
-        static SkString convertUtf16ToUtf8(const char16_t * utf16, int utf16Units) {
-
-            int utf8Units = SkUTF::UTF16ToUTF8(nullptr, 0, (uint16_t*)utf16, utf16Units);
-            if (utf8Units < 0) {
-                SkDEBUGF("Convert error: Invalid utf16 input");
-                return SkString();
-            }
-            SkAutoTArray<char> utf8(utf8Units);
-            SkDEBUGCODE(int dstLen =) SkUTF::UTF16ToUTF8(utf8.data(), utf8Units, (uint16_t*)utf16, utf16Units);
-            SkASSERT(dstLen == utf8Units);
-
-            return SkString(utf8.data(), utf8Units);
-        }
-
-        static SkString convertUtf16ToUtf8(const std::u16string& utf16) {
-            return convertUtf16ToUtf8(utf16.c_str(), utf16.size());
-        }
-
-        static std::u16string convertUtf8ToUtf16(const char* utf8, int utf8Units) {
-
-            int utf16Units = SkUTF::UTF8ToUTF16(nullptr, 0, utf8, utf8Units);
-            if (utf16Units < 0) {
-                SkDEBUGF("Convert error: Invalid utf8 input");
-                return std::u16string();
-            }
-
-            SkAutoTArray<uint16_t> utf16(utf16Units);
-            SkDEBUGCODE(int dstLen =) SkUTF::UTF8ToUTF16(utf16.data(), utf16Units, utf8, utf8Units);
-            SkASSERT(dstLen == utf16Units);
-
-            return std::u16string((char16_t *)utf16.data(), utf16Units);
-        }
-
-        static std::u16string convertUtf8ToUtf16(const SkString& utf8) {
-            return convertUtf8ToUtf16(utf8.c_str(), utf8.size());
-        }
-
         template <typename Callback>
         void forEachCodepoint(const char* utf8, int32_t utf8Units, Callback&& callback) {
             const char* current = utf8;
@@ -183,9 +147,7 @@
                 SkUnichar unichar = SkUTF::NextUTF8(&current, end);
                 if (unichar < 0) unichar = 0xFFFD;
                 auto after = current - utf8;
-                uint16_t buffer[2];
-                size_t count = SkUTF::ToUTF16(unichar, buffer);
-                callback(unichar, before, after, count);
+                callback(unichar, before, after);
             }
         }
 
diff --git a/modules/skunicode/src/SkUnicode_icu.cpp b/modules/skunicode/src/SkUnicode_icu.cpp
index e714fb8..7b33f2a 100644
--- a/modules/skunicode/src/SkUnicode_icu.cpp
+++ b/modules/skunicode/src/SkUnicode_icu.cpp
@@ -282,11 +282,15 @@
                             std::vector<BidiRegion>* bidiRegions) {
 
         // Convert to UTF16 since for now bidi iterator only operates on utf16
-        auto utf16 = convertUtf8ToUtf16(utf8, utf8Units);
+        std::unique_ptr<uint16_t[]> utf16;
+        auto utf16Units = utf8ToUtf16(utf8, utf8Units, &utf16);
+        if (utf16Units < 0) {
+            return false;
+        }
 
         // Create bidi iterator
         UErrorCode status = U_ZERO_ERROR;
-        SkUnicodeBidi bidi(sk_ubidi_openSized(utf16.size(), 0, &status));
+        SkUnicodeBidi bidi(sk_ubidi_openSized(utf16Units, 0, &status));
         if (U_FAILURE(status)) {
             SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
             return false;
@@ -295,7 +299,7 @@
         uint8_t bidiLevel = (dir == TextDirection::kLTR) ? UBIDI_LTR : UBIDI_RTL;
         // The required lifetime of utf16 isn't well documented.
         // It appears it isn't used after ubidi_setPara except through ubidi_getText.
-        sk_ubidi_setPara(bidi.get(), (const UChar*)utf16.c_str(), utf16.size(), bidiLevel, nullptr,
+        sk_ubidi_setPara(bidi.get(), (const UChar*)utf16.get(), utf16Units, bidiLevel, nullptr,
                          &status);
         if (U_FAILURE(status)) {
             SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
@@ -413,6 +417,30 @@
         return true;
     }
 
+    static int utf8ToUtf16(const char* utf8, size_t utf8Units, std::unique_ptr<uint16_t[]>* utf16) {
+        int utf16Units = SkUTF::UTF8ToUTF16(nullptr, 0, utf8, utf8Units);
+        if (utf16Units < 0) {
+            SkDEBUGF("Convert error: Invalid utf8 input");
+            return utf16Units;
+        }
+        *utf16 = std::unique_ptr<uint16_t[]>(new uint16_t[utf16Units]);
+        SkDEBUGCODE(int dstLen =) SkUTF::UTF8ToUTF16(utf16->get(), utf16Units, utf8, utf8Units);
+        SkASSERT(dstLen == utf16Units);
+        return utf16Units;
+   }
+
+    static int utf16ToUtf8(const uint16_t* utf16, size_t utf16Units, std::unique_ptr<char[]>* utf8) {
+        int utf8Units = SkUTF::UTF16ToUTF8(nullptr, 0, utf16, utf16Units);
+        if (utf8Units < 0) {
+            SkDEBUGF("Convert error: Invalid utf16 input");
+            return utf8Units;
+        }
+        *utf8 = std::unique_ptr<char[]>(new char[utf8Units]);
+        SkDEBUGCODE(int dstLen =) SkUTF::UTF16ToUTF8(utf8->get(), utf8Units, utf16, utf16Units);
+        SkASSERT(dstLen == utf8Units);
+        return utf8Units;
+   }
+
 public:
     ~SkUnicode_icu() override { }
     std::unique_ptr<SkBidiIterator> makeBidiIterator(const uint16_t text[], int count,
@@ -460,12 +488,26 @@
         return property == U_LB_LINE_FEED || property == U_LB_MANDATORY_BREAK;
     }
 
+    SkString convertUtf16ToUtf8(const std::u16string& utf16) override {
+        std::unique_ptr<char[]> utf8;
+        auto utf8Units = SkUnicode_icu::utf16ToUtf8((uint16_t*)utf16.data(), utf16.size(), &utf8);
+        if (utf8Units >= 0) {
+            return SkString(utf8.get(), utf8Units);
+        } else {
+            return SkString();
+        }
+    }
+
     SkString toUpper(const SkString& str) override {
         // Convert to UTF16 since that's what ICU wants.
-        auto str16 = convertUtf8ToUtf16(str.c_str(), str.size());
+        std::unique_ptr<uint16_t[]> str16;
+        const auto str16len = utf8ToUtf16(str.c_str(), str.size(), &str16);
+        if (str16len <= 0) {
+            return SkString();
+        }
 
         UErrorCode icu_err = U_ZERO_ERROR;
-        const auto upper16len = sk_u_strToUpper(nullptr, 0, (UChar*)(str16.c_str()), str16.size(),
+        const auto upper16len = sk_u_strToUpper(nullptr, 0, (UChar*)(str16.get()), str16len,
                                                 nullptr, &icu_err);
         if (icu_err != U_BUFFER_OVERFLOW_ERROR || upper16len <= 0) {
             return SkString();
@@ -474,13 +516,17 @@
         SkAutoSTArray<128, uint16_t> upper16(upper16len);
         icu_err = U_ZERO_ERROR;
         sk_u_strToUpper((UChar*)(upper16.get()), SkToS32(upper16.size()),
-                        (UChar*)(str16.c_str()), str16.size(),
+                        (UChar*)(str16.get()), str16len,
                         nullptr, &icu_err);
         SkASSERT(!U_FAILURE(icu_err));
 
         // ... and back to utf8 'cause that's what we want.
-        auto upper8 = convertUtf16ToUtf8(str16);
-        return upper8;
+        std::unique_ptr<char[]> upper8;
+        auto upper8len = utf16ToUtf8(upper16.data(), upper16.size(), &upper8);
+
+        return upper8len >= 0
+                ? SkString(upper8.get(), upper8len)
+                : SkString();
     }
 
     bool getBidiRegions(const char utf8[],
@@ -505,8 +551,13 @@
     bool getWords(const char utf8[], int utf8Units, std::vector<Position>* results) override {
 
         // Convert to UTF16 since we want the results in utf16
-        auto utf16 = convertUtf8ToUtf16(utf8, utf8Units);
-        return extractWords((uint16_t*)utf16.c_str(), utf16.size(), results);
+        std::unique_ptr<uint16_t[]> utf16;
+        auto utf16Units = utf8ToUtf16(utf8, utf8Units, &utf16);
+        if (utf16Units < 0) {
+            return false;
+        }
+
+        return extractWords(utf16.get(), utf16Units, results);
     }
 
     bool getGraphemes(const char utf8[], int utf8Units, std::vector<Position>* results) override {