SkString: remove externally unused ::setUTF16() from API
Moved to SkStringUtils in src/ Change-Id: I026e3a325570bbf34e90797d921cb2f05b9a29f6 Reviewed-on: https://skia-review.googlesource.com/111602 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
9b1a886061
commit
ee08b4a2e9
@ -186,8 +186,6 @@ public:
|
||||
void set(const SkString& src) { *this = src; }
|
||||
void set(const char text[]);
|
||||
void set(const char text[], size_t len);
|
||||
void setUTF16(const uint16_t[]);
|
||||
void setUTF16(const uint16_t[], size_t len);
|
||||
|
||||
void insert(size_t offset, const SkString& src) { this->insert(offset, src.c_str(), src.size()); }
|
||||
void insert(size_t offset, const char text[]);
|
||||
|
@ -369,45 +369,6 @@ void SkString::set(const char text[], size_t len) {
|
||||
}
|
||||
}
|
||||
|
||||
void SkString::setUTF16(const uint16_t src[]) {
|
||||
int count = 0;
|
||||
|
||||
while (src[count]) {
|
||||
count += 1;
|
||||
}
|
||||
this->setUTF16(src, count);
|
||||
}
|
||||
|
||||
static SkString utf8_from_utf16(const uint16_t src[], size_t count) {
|
||||
SkString ret;
|
||||
if (count > 0) {
|
||||
SkASSERT(src);
|
||||
size_t n = 0;
|
||||
const uint16_t* end = src + count;
|
||||
for (const uint16_t* ptr = src; ptr < end;) {
|
||||
const uint16_t* last = ptr;
|
||||
SkUnichar u = SkUTF16_NextUnichar(&ptr);
|
||||
size_t s = SkUTF8_FromUnichar(u);
|
||||
if (n > SK_MaxU32 - s) {
|
||||
end = last; // truncate input string
|
||||
break;
|
||||
}
|
||||
n += s;
|
||||
}
|
||||
ret = SkString(n);
|
||||
char* out = ret.writable_str();
|
||||
for (const uint16_t* ptr = src; ptr < end;) {
|
||||
out += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&ptr), out);
|
||||
}
|
||||
SkASSERT(out == ret.writable_str() + n);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SkString::setUTF16(const uint16_t src[], size_t count) {
|
||||
*this = utf8_from_utf16(src, count);
|
||||
}
|
||||
|
||||
void SkString::insert(size_t offset, const char text[]) {
|
||||
this->insert(offset, text, text ? strlen(text) : 0);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "SkString.h"
|
||||
#include "SkStringUtils.h"
|
||||
#include "SkUtils.h"
|
||||
|
||||
void SkAddFlagToString(SkString* string, bool flag, const char* flagStr, bool* needSeparator) {
|
||||
if (flag) {
|
||||
@ -61,3 +62,29 @@ SkString SkTabString(const SkString& string, int tabCnt) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SkString SkStringFromUTF16(const uint16_t* src, size_t count) {
|
||||
SkString ret;
|
||||
if (count > 0) {
|
||||
SkASSERT(src);
|
||||
size_t n = 0;
|
||||
const uint16_t* end = src + count;
|
||||
for (const uint16_t* ptr = src; ptr < end;) {
|
||||
const uint16_t* last = ptr;
|
||||
SkUnichar u = SkUTF16_NextUnichar(&ptr);
|
||||
size_t s = SkUTF8_FromUnichar(u);
|
||||
if (n > SK_MaxU32 - s) {
|
||||
end = last; // truncate input string
|
||||
break;
|
||||
}
|
||||
n += s;
|
||||
}
|
||||
ret = SkString(n);
|
||||
char* out = ret.writable_str();
|
||||
for (const uint16_t* ptr = src; ptr < end;) {
|
||||
out += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&ptr), out);
|
||||
}
|
||||
SkASSERT(out == ret.writable_str() + n);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -40,4 +40,6 @@ static inline void SkAppendScalarHex(SkString* str, SkScalar value) {
|
||||
/** Indents every non-empty line of the string by tabCnt tabs */
|
||||
SkString SkTabString(const SkString& string, int tabCnt);
|
||||
|
||||
SkString SkStringFromUTF16(const uint16_t* src, size_t count);
|
||||
|
||||
#endif
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "SkLeanWindows.h"
|
||||
#include "SkMalloc.h"
|
||||
#include "SkOSFile.h"
|
||||
#include "SkStringUtils.h"
|
||||
#include "SkTFitsIn.h"
|
||||
|
||||
#include <io.h>
|
||||
@ -250,7 +251,10 @@ static bool get_the_file(HANDLE handle, SkString* name, WIN32_FIND_DATAW* dataPt
|
||||
}
|
||||
// if we get here, we've found a file/dir
|
||||
if (name) {
|
||||
name->setUTF16((uint16_t*)dataPtr->cFileName);
|
||||
const uint16_t* utf16name = (const uint16_t*)dataPtr->cFileName;
|
||||
const uint16_t* ptr = utf16name;
|
||||
while (*ptr != 0) { ++ptr; }
|
||||
*name = SkStringFromUTF16(utf16name, ptr - utf16name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "SkOTTable_name.h"
|
||||
|
||||
#include "SkEndian.h"
|
||||
#include "SkString.h"
|
||||
#include "SkStringUtils.h"
|
||||
#include "SkTSearch.h"
|
||||
#include "SkTemplates.h"
|
||||
#include "SkUtils.h"
|
||||
|
@ -6,7 +6,9 @@
|
||||
*/
|
||||
|
||||
#include "SkLuaCanvas.h"
|
||||
|
||||
#include "SkLua.h"
|
||||
#include "SkStringUtils.h"
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
@ -51,11 +53,9 @@ void AutoCallLua::pushEncodedText(SkPaint::TextEncoding enc, const void* text,
|
||||
case SkPaint::kUTF8_TextEncoding:
|
||||
this->pushString((const char*)text, length, "text");
|
||||
break;
|
||||
case SkPaint::kUTF16_TextEncoding: {
|
||||
SkString str;
|
||||
str.setUTF16((const uint16_t*)text, length);
|
||||
this->pushString(str, "text");
|
||||
} break;
|
||||
case SkPaint::kUTF16_TextEncoding:
|
||||
this->pushString(SkStringFromUTF16((const uint16_t*)text, length), "text");
|
||||
break;
|
||||
case SkPaint::kGlyphID_TextEncoding:
|
||||
this->pushArrayU16((const uint16_t*)text, SkToInt(length >> 1),
|
||||
"glyphs");
|
||||
|
@ -5,12 +5,14 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "SkString.h"
|
||||
#include "Test.h"
|
||||
#include <thread>
|
||||
|
||||
#include "SkString.h"
|
||||
#include "SkStringUtils.h"
|
||||
|
||||
DEF_TEST(String, reporter) {
|
||||
SkString a;
|
||||
@ -304,28 +306,22 @@ DEF_TEST(String_huge, r) {
|
||||
}
|
||||
}
|
||||
|
||||
static SkString utf16_to_utf8(const uint16_t* utf16, size_t len) {
|
||||
SkString s;
|
||||
s.setUTF16(utf16, len);
|
||||
return s;
|
||||
}
|
||||
|
||||
DEF_TEST(String_fromUTF16, r) {
|
||||
// test data produced with `iconv`.
|
||||
const uint16_t test1[] = {
|
||||
0xD835, 0xDCD0, 0xD835, 0xDCD1, 0xD835, 0xDCD2, 0xD835, 0xDCD3, 0xD835, 0xDCD4, 0x0020,
|
||||
0xD835, 0xDCD5, 0xD835, 0xDCD6, 0xD835, 0xDCD7, 0xD835, 0xDCD8, 0xD835, 0xDCD9
|
||||
};
|
||||
REPORTER_ASSERT(r, utf16_to_utf8(test1, SK_ARRAY_COUNT(test1)).equals("𝓐𝓑𝓒𝓓𝓔 𝓕𝓖𝓗𝓘𝓙"));
|
||||
REPORTER_ASSERT(r, SkStringFromUTF16(test1, SK_ARRAY_COUNT(test1)).equals("𝓐𝓑𝓒𝓓𝓔 𝓕𝓖𝓗𝓘𝓙"));
|
||||
|
||||
const uint16_t test2[] = {
|
||||
0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0020, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A,
|
||||
};
|
||||
REPORTER_ASSERT(r, utf16_to_utf8(test2, SK_ARRAY_COUNT(test2)).equals("ABCDE FGHIJ"));
|
||||
REPORTER_ASSERT(r, SkStringFromUTF16(test2, SK_ARRAY_COUNT(test2)).equals("ABCDE FGHIJ"));
|
||||
|
||||
const uint16_t test3[] = {
|
||||
0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x0020, 0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA,
|
||||
};
|
||||
REPORTER_ASSERT(r, utf16_to_utf8(test3, SK_ARRAY_COUNT(test3)).equals("αβγδε ζηθικ"));
|
||||
REPORTER_ASSERT(r, SkStringFromUTF16(test3, SK_ARRAY_COUNT(test3)).equals("αβγδε ζηθικ"));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user