Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
utf16.h
Go to the documentation of this file.
1// Copyright 2023 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CORE_FXCRT_UTF16_H_
6#define CORE_FXCRT_UTF16_H_
7
8#include "third_party/base/check.h"
9
10namespace pdfium {
11
12// The number of suffix bits in a UTF-16 surrogate.
13inline constexpr int kSurrogateBits = 10;
14
15// A bitmask for the suffix of a UTF-16 surrogate.
16inline constexpr char16_t kSurrogateMask = (1 << kSurrogateBits) - 1;
17
18// The first supplementary code point, `U+10000`.
19inline constexpr char32_t kMinimumSupplementaryCodePoint = 0x10000;
20
21// The last supplementary code point, `U+10FFFF`.
22inline constexpr char32_t kMaximumSupplementaryCodePoint =
25
26// The first UTF-16 high surrogate code unit, `U+D800`.
27inline constexpr char16_t kMinimumHighSurrogateCodeUnit = 0xd800;
28
29// The last UTF-16 high surrogate code unit, `U+DBFF`.
30inline constexpr char16_t kMaximumHighSurrogateCodeUnit =
32
33// The first UTF-16 low surrogate code unit, `U+DC00`.
34inline constexpr char16_t kMinimumLowSurrogateCodeUnit =
36
37// The last UTF-16 low surrogate code unit, `U+DFFF`.
38inline constexpr char16_t kMaximumLowSurrogateCodeUnit =
40
41// Returns `true` if `code_point` is in a supplementary plane, and therefore
42// requires encoding as a UTF-16 surrogate pair.
43constexpr bool IsSupplementary(char32_t code_point) {
44 return code_point >= kMinimumSupplementaryCodePoint &&
46}
47
48// Returns `true` if `code_point` is a UTF-16 high surrogate.
49constexpr bool IsHighSurrogate(char32_t code_point) {
50 return code_point >= kMinimumHighSurrogateCodeUnit &&
52}
53
54// Returns `true` if `code_point` is a UTF-16 low surrogate.
55constexpr bool IsLowSurrogate(char32_t code_point) {
56 return code_point >= kMinimumLowSurrogateCodeUnit &&
57 code_point <= kMaximumLowSurrogateCodeUnit;
58}
59
60// A UTF-16 surrogate pair.
61class SurrogatePair final {
62 public:
63 // Constructs a surrogate pair from a high and a low surrogate.
64 constexpr SurrogatePair(char16_t high, char16_t low)
65 : high_(high), low_(low) {
66 DCHECK(IsHighSurrogate(high_));
67 DCHECK(IsLowSurrogate(low_));
68 }
69
70 // Constructs a surrogate pair from a code point.
71 explicit constexpr SurrogatePair(char32_t code_point)
72 : high_(GetHighSurrogate(code_point)), low_(GetLowSurrogate(code_point)) {
73 // This constructor initializes `high_` and `low_` using helper functions
74 // because C++17 requires it for `constexpr` constructors.
75 DCHECK(IsSupplementary(code_point));
76 }
77
78 constexpr char16_t high() const { return high_; }
79 constexpr char16_t low() const { return low_; }
80
81 // Decodes this surrogate pair to a code point.
82 constexpr char32_t ToCodePoint() const {
83 char32_t code_point = low_ & kSurrogateMask;
84 code_point |= (high_ & kSurrogateMask) << kSurrogateBits;
85 return kMinimumSupplementaryCodePoint + code_point;
86 }
87
88 private:
89 static constexpr char16_t GetHighSurrogate(char32_t code_point) {
91 char16_t code_unit = (code_point >> kSurrogateBits) & kSurrogateMask;
92 return kMinimumHighSurrogateCodeUnit | code_unit;
93 }
94
95 static constexpr char16_t GetLowSurrogate(char32_t code_point) {
97 char16_t code_unit = code_point & kSurrogateMask;
98 return kMinimumLowSurrogateCodeUnit | code_unit;
99 }
100
101 char16_t high_;
102 char16_t low_;
103};
104
105} // namespace pdfium
106
107#endif // CORE_FXCRT_UTF16_H_
int GetIntegerFor(const ByteString &key) const
int GetIntegerFor(const ByteString &key, int default_int) const
FaxModule(const FaxModule &)=delete
static int FaxG4Decode(const uint8_t *src_buf, uint32_t src_size, int starting_bitpos, int width, int height, int pitch, uint8_t *dest_buf)
FaxModule & operator=(const FaxModule &)=delete
static std::unique_ptr< ScanlineDecoder > CreateDecoder(pdfium::span< const uint8_t > src_span, int width, int height, int K, bool EndOfLine, bool EncodedByteAlign, bool BlackIs1, int Columns, int Rows)
static uint32_t FlateOrLZWDecode(bool bLZW, pdfium::span< const uint8_t > src_span, bool bEarlyChange, int predictor, int Colors, int BitsPerComponent, int Columns, uint32_t estimated_size, std::unique_ptr< uint8_t, FxFreeDeleter > *dest_buf, uint32_t *dest_size)
ByteString & operator+=(char ch)
bool operator==(const char *ptr) const
ByteString & operator+=(const char *str)
ByteString & operator=(const char *str)
static WideString FromUTF8(ByteStringView str)
static WideString FromUTF16BE(pdfium::span< const uint8_t > data)
static WideString FromUTF16LE(pdfium::span< const uint8_t > data)
constexpr SurrogatePair(char32_t code_point)
Definition utf16.h:71
constexpr char16_t high() const
Definition utf16.h:78
constexpr char32_t ToCodePoint() const
Definition utf16.h:82
constexpr SurrogatePair(char16_t high, char16_t low)
Definition utf16.h:64
constexpr char16_t low() const
Definition utf16.h:79
static size_t StripLanguageCodes(pdfium::span< wchar_t > s, size_t n)
const uint16_t kPDFDocEncoding[256]
ByteString PDF_EncodeString(ByteStringView src)
ByteString PDF_EncodeText(WideStringView str)
bool ValidateDecoderPipeline(const CPDF_Array *pDecoders)
uint32_t HexDecode(pdfium::span< const uint8_t > src_span, std::unique_ptr< uint8_t, FxFreeDeleter > *dest_buf, uint32_t *dest_size)
WideString PDF_DecodeText(pdfium::span< const uint8_t > span)
std::unique_ptr< fxcodec::ScanlineDecoder > CreateFaxDecoder(pdfium::span< const uint8_t > src_span, int width, int height, const CPDF_Dictionary *pParams)
uint32_t RunLengthDecode(pdfium::span< const uint8_t > src_span, std::unique_ptr< uint8_t, FxFreeDeleter > *dest_buf, uint32_t *dest_size)
uint32_t FlateOrLZWDecode(bool bLZW, pdfium::span< const uint8_t > src_span, const CPDF_Dictionary *pParams, uint32_t estimated_size, std::unique_ptr< uint8_t, FxFreeDeleter > *dest_buf, uint32_t *dest_size)
ByteString PDF_HexEncodeString(ByteStringView src)
std::unique_ptr< fxcodec::ScanlineDecoder > CreateFlateDecoder(pdfium::span< const uint8_t > src_span, int width, int height, int nComps, int bpc, const CPDF_Dictionary *pParams)
bool PDF_DataDecode(pdfium::span< const uint8_t > src_span, uint32_t estimated_size, bool bImageAcc, const DecoderArray &decoder_array, std::unique_ptr< uint8_t, FxFreeDeleter > *dest_buf, uint32_t *dest_size, ByteString *ImageEncoding, RetainPtr< const CPDF_Dictionary > *pImageParams)
uint32_t A85Decode(pdfium::span< const uint8_t > src_span, std::unique_ptr< uint8_t, FxFreeDeleter > *dest_buf, uint32_t *dest_size)
absl::optional< DecoderArray > GetDecoderArray(RetainPtr< const CPDF_Dictionary > pDict)
bool PDFCharIsLineEnding(uint8_t c)
int FXSYS_HexCharToInt(char c)
#define FX_INVALID_OFFSET
constexpr bool IsSupplementary(char32_t code_point)
Definition utf16.h:43
constexpr char32_t kMaximumSupplementaryCodePoint
Definition utf16.h:22
constexpr char32_t kMinimumSupplementaryCodePoint
Definition utf16.h:19
constexpr bool IsHighSurrogate(char32_t code_point)
Definition utf16.h:49
constexpr char16_t kMaximumHighSurrogateCodeUnit
Definition utf16.h:30
constexpr char16_t kMaximumLowSurrogateCodeUnit
Definition utf16.h:38
constexpr int kSurrogateBits
Definition utf16.h:13
constexpr char16_t kSurrogateMask
Definition utf16.h:16
constexpr char16_t kMinimumHighSurrogateCodeUnit
Definition utf16.h:27
constexpr bool IsLowSurrogate(char32_t code_point)
Definition utf16.h:55
constexpr char16_t kMinimumLowSurrogateCodeUnit
Definition utf16.h:34