// Copyright 2018 Google LLC // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #ifndef SkUTF_DEFINED #define SkUTF_DEFINED
#include"include/private/base/SkAPI.h"
#include <cstddef> #include <cstdint>
typedef int32_t SkUnichar;
namespace SkUTF {
/** Given a sequence of UTF-8 bytes, return the number of unicode codepoints. IfthesequenceisinvalidUTF-8,return-1.
*/
SK_SPI int CountUTF8(constchar* utf8, size_t byteLength);
/** Given a sequence of aligned UTF-16 characters in machine-endian form, returnthenumberofunicodecodepoints.Ifthesequenceisinvalid UTF-16,return-1.
*/
SK_SPI int CountUTF16(const uint16_t* utf16, size_t byteLength);
/** Given a sequence of aligned UTF-32 characters in machine-endian form, returnthenumberofunicodecodepoints.Ifthesequenceisinvalid UTF-32,return-1.
*/
SK_SPI int CountUTF32(const int32_t* utf32, size_t byteLength);
/** Given a sequence of UTF-8 bytes, return the first unicode codepoint. Thepointerwillbeincrementedtopointatthenextcodepoint'sstart.If invalidUTF-8isencountered,set*ptrtoendandreturn-1.
*/
SK_SPI SkUnichar NextUTF8(constchar** ptr, constchar* end);
/** Given a sequence of UTF-8 bytes, return the first unicode codepoint. Thepointerwillbeincrementedtopointatthenextcodepoint'sstart.If invalidUTF-8isencountered,set*ptrtoendand returnthereplacementcharacter(0xFFFD)
*/
SK_SPI SkUnichar NextUTF8WithReplacement(constchar** ptr, constchar* end);
/** Given a sequence of aligned UTF-16 characters in machine-endian form, returnthefirstunicodecodepoint.Thepointerwillbeincrementedto pointatthenextcodepoint'sstart.IfinvalidUTF-16isencountered, set*ptrtoendandreturn-1.
*/
SK_SPI SkUnichar NextUTF16(const uint16_t** ptr, const uint16_t* end);
/** Given a sequence of aligned UTF-32 characters in machine-endian form, returnthefirstunicodecodepoint.Thepointerwillbeincrementedto pointatthenextcodepoint'sstart.IfinvalidUTF-32isencountered, set*ptrtoendandreturn-1.
*/
SK_SPI SkUnichar NextUTF32(const int32_t** ptr, const int32_t* end);
constexpr unsigned kMaxBytesInUTF8Sequence = 4;
/** Convert the unicode codepoint into UTF-8. If `utf8` is non-null, place the resultinthatarray.Returnthenumberofbytesintheresult.If`utf8` isnull,simplyreturnthenumberofbytesthatwouldbeused.Forinvalid unicodecodepoints,return0.
*/
SK_SPI size_t ToUTF8(SkUnichar uni, char utf8[kMaxBytesInUTF8Sequence] = nullptr);
/** Convert the unicode codepoint into UTF-16. If `utf16` is non-null, place theresultinthatarray.ReturnthenumberofUTF-16codeunitsinthe result(1or2).If`utf16`isnull,simplyreturnthenumberofcode unitsthatwouldbeused.Forinvalidunicodecodepoints,return0.
*/
SK_SPI size_t ToUTF16(SkUnichar uni, uint16_t utf16[2] = nullptr);
/** Returns the number of resulting UTF16 values needed to convert the src utf8 sequence. *Ifdstisnotnull,itisfilledwiththecorrespondingvaluesuptoitscapacity. *Ifthereisanerror,-1isreturnedandthedst[]bufferisundefined.
*/
SK_SPI int UTF8ToUTF16(uint16_t dst[], int dstCapacity, constchar src[], size_t srcByteLength);
/** Returns the number of resulting UTF8 values needed to convert the src utf16 sequence. *Ifdstisnotnull,itisfilledwiththecorrespondingvaluesuptoitscapacity. *Ifthereisanerror,-1isreturnedandthedst[]bufferisundefined.
*/
SK_SPI int UTF16ToUTF8(char dst[], int dstCapacity, const uint16_t src[], size_t srcLength);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.