skia2/src/utils/SkUTF.h
Julia Lavrova b6b7fffc35 Reland "Removing ICU dependencies from skparagraph BUILD.gn file"
This reverts commit 05ce2817f2.

Reason for revert: Fixing the build

Original change's description:
> Revert "Removing ICU dependencies from skparagraph BUILD.gn file"
>
> This reverts commit f1711adb1a.
>
> 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>
2020-09-11 18:31:24 +00:00

83 lines
3.4 KiB
C++

// 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/core/SkTypes.h"
#include <cstddef>
#include <cstdint>
#include <memory>
typedef int32_t SkUnichar;
namespace SkUTF {
/** Given a sequence of UTF-8 bytes, return the number of unicode codepoints.
If the sequence is invalid UTF-8, return -1.
*/
SK_SPI int CountUTF8(const char* utf8, size_t byteLength);
/** Given a sequence of aligned UTF-16 characters in machine-endian form,
return the number of unicode codepoints. If the sequence is invalid
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,
return the number of unicode codepoints. If the sequence is invalid
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.
The pointer will be incremented to point at the next codepoint's start. If
invalid UTF-8 is encountered, set *ptr to end and return -1.
*/
SK_SPI SkUnichar NextUTF8(const char** ptr, const char* end);
/** Given a sequence of aligned UTF-16 characters in machine-endian form,
return the first unicode codepoint. The pointer will be incremented to
point at the next codepoint's start. If invalid UTF-16 is encountered,
set *ptr to end and return -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,
return the first unicode codepoint. The pointer will be incremented to
point at the next codepoint's start. If invalid UTF-32 is encountered,
set *ptr to end and return -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
result in that array. Return the number of bytes in the result. If `utf8`
is null, simply return the number of bytes that would be used. For invalid
unicode codepoints, return 0.
*/
SK_SPI size_t ToUTF8(SkUnichar uni, char utf8[kMaxBytesInUTF8Sequence] = nullptr);
/** Convert the unicode codepoint into UTF-16. If `utf16` is non-null, place
the result in that array. Return the number of UTF-16 code units in the
result (1 or 2). If `utf16` is null, simply return the number of code
units that would be used. For invalid unicode codepoints, return 0.
*/
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.
* 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 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