Reland "Removing ICU dependencies from skparagraph BUILD.gn file"
This reverts commit 05ce2817f2a060caf8acd5be25b4f29875d63049.
Reason for revert: Fixing the build
Original change's description:
> Revert "Removing ICU dependencies from skparagraph BUILD.gn file"
>
> This reverts commit f1711adb1a04595eba1e9984976bfb92d41d0035.
>
> Reason for revert: Build break
>
> Original change's description:
> > Removing ICU dependencies from skparagraph BUILD.gn file
> >
> > (and from the sources, too)
> >
> > Change-Id: I9d8ff51c91aad4b770b1f183c04734d31252b851
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313148
> > Commit-Queue: Julia Lavrova <jlavrova@google.com>
> > Reviewed-by: Ben Wagner <bungeman@google.com>
>
> TBR=bungeman@google.com,jlavrova@google.com
>
> Change-Id: I1fce2436855e3e2a4cb7d1d7204b3ae49fd530e8
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314540
> Reviewed-by: Julia Lavrova <jlavrova@google.com>
> Commit-Queue: Julia Lavrova <jlavrova@google.com>
TBR=bungeman@google.com,jlavrova@google.com
Change-Id: I13d78d75698df47930adc2514d1328abc556a209
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/316444
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
diff --git a/src/utils/SkUTF.cpp b/src/utils/SkUTF.cpp
index ff17462..500b1ec 100644
--- a/src/utils/SkUTF.cpp
+++ b/src/utils/SkUTF.cpp
@@ -283,4 +283,28 @@
return dstLength;
}
+int SkUTF::UTF16ToUTF8(char dst[], int dstCapacity, const uint16_t src[], size_t srcLength) {
+ if (!dst) {
+ dstCapacity = 0;
+ }
+
+ int dstLength = 0;
+ const char* endDst = dst + dstCapacity;
+ for (size_t i = 0; i < srcLength; ++i) {
+ char utf8[SkUTF::kMaxBytesInUTF8Sequence];
+ size_t count = ToUTF8(src[i], utf8);
+ if (count == 0) {
+ return -1;
+ }
+ dstLength += count;
+ if (dst) {
+ const char* elems = utf8;
+ while (dst < endDst && count > 0) {
+ *dst++ = *elems++;
+ count -= 1;
+ }
+ }
+ }
+ return dstLength;
+}
diff --git a/src/utils/SkUTF.h b/src/utils/SkUTF.h
index eb1ee91..23344a4 100644
--- a/src/utils/SkUTF.h
+++ b/src/utils/SkUTF.h
@@ -6,6 +6,7 @@
#include "include/core/SkTypes.h"
#include <cstddef>
#include <cstdint>
+#include <memory>
typedef int32_t SkUnichar;
@@ -70,6 +71,12 @@
*/
SK_SPI int UTF8ToUTF16(uint16_t dst[], int dstCapacity, const char src[], size_t srcByteLength);
+/** Returns the number of resulting UTF8 values needed to convert the src utf16 sequence.
+ * If dst is not null, it is filled with the corresponding values up to its capacity.
+ * If there is an error, -1 is returned and the dst[] buffer is undefined.
+ */
+SK_SPI int UTF16ToUTF8(char dst[], int dstCapacity, const uint16_t src[], size_t srcLength);
+
} // namespace SkUTF
#endif // SkUTF_DEFINED