7#include "core/fxcrt/fx_string.h"
15#include "build/build_config.h"
16#include "core/fxcrt/bytestring.h"
17#include "core/fxcrt/code_point_view.h"
18#include "core/fxcrt/fx_extension.h"
19#include "core/fxcrt/span.h"
20#include "core/fxcrt/utf16.h"
21#include "core/fxcrt/widestring.h"
23#if !defined(WCHAR_T_IS_16_BIT) && !defined(WCHAR_T_IS_32_BIT)
24#error "Unknown wchar_t size"
26#if defined(WCHAR_T_IS_16_BIT) && defined(WCHAR_T_IS_32_BIT)
27#error "Conflicting wchar_t sizes"
35void AppendCodePointToByteString(
char32_t code_point,
ByteString& buffer) {
41 if (code_point < 0x80) {
48 if (code_point < 0x800) {
50 }
else if (code_point < 0x10000) {
56 static constexpr std::array<uint8_t, 3> kPrefix = {{0xc0, 0xe0, 0xf0}};
57 int order = 1 << ((byte_size - 1) * 6);
58 buffer += kPrefix[byte_size - 2] | (code_point / order);
59 for (
int i = 0; i < byte_size - 1; i++) {
60 code_point = code_point % order;
62 buffer
+= 0x80 | (code_point / order);
70 for (
char32_t code_point : pdfium::CodePointView(wsStr)) {
71 AppendCodePointToByteString(code_point, buffer);
77 if (wsStr.IsEmpty()) {
81 std::u16string result;
82 result.reserve(wsStr.GetLength());
84 for (
wchar_t c : wsStr) {
85#if defined(WCHAR_T_IS_32_BIT)
86 if (pdfium::IsSupplementary(c)) {
87 pdfium::SurrogatePair pair(c);
88 result.push_back(pair.high());
89 result.push_back(pair.low());
101constexpr float kFractionScalesFloat[] = {
102 0.1f, 0.01f, 0.001f, 0.0001f,
103 0.00001f, 0.000001f, 0.0000001f, 0.00000001f,
104 0.000000001f, 0.0000000001f, 0.00000000001f};
106const double kFractionScalesDouble[] = {
107 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001,
108 0.0000001, 0.00000001, 0.000000001, 0.0000000001, 0.00000000001};
111T StringTo(
ByteStringView strc, pdfium::span<
const T> fractional_scales) {
115 bool bNegative =
false;
117 size_t len = strc.GetLength();
118 if (strc[0] ==
'+') {
120 }
else if (strc[0] ==
'-') {
125 if (strc[cc] !=
'+' && strc[cc] !=
'-')
133 value = value * 10 + FXSYS_DecimalCharToInt(strc.CharAt(cc));
137 if (cc < len && strc[cc] ==
'.') {
141 fractional_scales[scale] * FXSYS_DecimalCharToInt(strc.CharAt(cc));
143 if (scale == fractional_scales.size())
148 return bNegative ? -value : value;
154 return StringTo<
float>(strc, kFractionScalesFloat);
158 return StringToFloat(FX_UTF8Encode(wsStr).AsStringView());
162 return StringTo<
double>(strc, kFractionScalesDouble);
166 return StringToDouble(FX_UTF8Encode(wsStr).AsStringView());
fxcrt::ByteString ByteString
ByteString & operator+=(char ch)
double StringToDouble(WideStringView wsStr)
float StringToFloat(ByteStringView str)
ByteString FX_UTF8Encode(WideStringView wsStr)
std::u16string FX_UTF16Encode(WideStringView wsStr)
float StringToFloat(WideStringView wsStr)
double StringToDouble(ByteStringView str)
constexpr char32_t kMaximumSupplementaryCodePoint
fxcrt::ByteStringView ByteStringView
fxcrt::WideStringView WideStringView