catboost 1.25.1 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPLOYMENT.md +22 -15
- package/README.md +37 -27
- package/binding.gyp +5 -7
- package/build_scripts/bootstrap.js +2 -1
- package/build_scripts/out/build.js +46 -68
- package/build_scripts/out/build_model.js +1 -1
- package/build_scripts/out/{build_ya.js → build_native.js} +1 -1
- package/build_scripts/out/ci.js +5 -5
- package/build_scripts/out/config.js +32 -18
- package/build_scripts/out/install.js +5 -3
- package/build_scripts/out/package_prepublish.js +1 -1
- package/build_scripts/out/packaging.js +1 -19
- package/build_scripts/out/run_tests.js +1 -1
- package/build_scripts/out/test.js +8 -3
- package/config.json +18 -11
- package/inc/catboost/libs/model_interface/c_api.h +349 -3
- package/lib/catboost.d.ts +65 -21
- package/package.json +4 -4
- package/src/api_helpers.cpp +100 -24
- package/src/api_helpers.h +8 -7
- package/src/api_module.cpp +1 -2
- package/src/model.cpp +483 -83
- package/src/model.h +24 -9
- package/inc/contrib/libs/cxxsupp/system_stl/include/stlfwd +0 -14
- package/inc/util/charset/recode_result.h +0 -9
- package/inc/util/charset/unicode_table.h +0 -123
- package/inc/util/charset/unidata.h +0 -421
- package/inc/util/charset/utf8.h +0 -384
- package/inc/util/charset/wide.h +0 -843
- package/inc/util/charset/wide_specific.h +0 -22
- package/inc/util/datetime/base.h +0 -669
- package/inc/util/datetime/constants.h +0 -7
- package/inc/util/datetime/cputimer.h +0 -124
- package/inc/util/datetime/parser.h +0 -292
- package/inc/util/datetime/systime.h +0 -47
- package/inc/util/datetime/uptime.h +0 -8
- package/inc/util/digest/city.h +0 -88
- package/inc/util/digest/fnv.h +0 -73
- package/inc/util/digest/multi.h +0 -14
- package/inc/util/digest/murmur.h +0 -57
- package/inc/util/digest/numeric.h +0 -86
- package/inc/util/digest/sequence.h +0 -48
- package/inc/util/draft/date.h +0 -129
- package/inc/util/draft/datetime.h +0 -184
- package/inc/util/draft/enum.h +0 -136
- package/inc/util/draft/holder_vector.h +0 -102
- package/inc/util/draft/ip.h +0 -131
- package/inc/util/draft/matrix.h +0 -108
- package/inc/util/draft/memory.h +0 -40
- package/inc/util/folder/dirent_win.h +0 -46
- package/inc/util/folder/dirut.h +0 -121
- package/inc/util/folder/filelist.h +0 -81
- package/inc/util/folder/fts.h +0 -108
- package/inc/util/folder/iterator.h +0 -109
- package/inc/util/folder/lstat_win.h +0 -20
- package/inc/util/folder/path.h +0 -225
- package/inc/util/folder/pathsplit.h +0 -113
- package/inc/util/folder/tempdir.h +0 -42
- package/inc/util/generic/adaptor.h +0 -134
- package/inc/util/generic/algorithm.h +0 -765
- package/inc/util/generic/array_ref.h +0 -282
- package/inc/util/generic/array_size.h +0 -24
- package/inc/util/generic/benchmark/vector_count_ctor/f.h +0 -9
- package/inc/util/generic/bitmap.h +0 -1115
- package/inc/util/generic/bitops.h +0 -459
- package/inc/util/generic/bt_exception.h +0 -24
- package/inc/util/generic/buffer.h +0 -232
- package/inc/util/generic/cast.h +0 -176
- package/inc/util/generic/deque.h +0 -24
- package/inc/util/generic/explicit_type.h +0 -42
- package/inc/util/generic/fastqueue.h +0 -55
- package/inc/util/generic/flags.h +0 -244
- package/inc/util/generic/function.h +0 -103
- package/inc/util/generic/fwd.h +0 -171
- package/inc/util/generic/guid.h +0 -61
- package/inc/util/generic/hash.h +0 -2032
- package/inc/util/generic/hash_primes.h +0 -140
- package/inc/util/generic/hash_set.h +0 -490
- package/inc/util/generic/hide_ptr.h +0 -3
- package/inc/util/generic/intrlist.h +0 -876
- package/inc/util/generic/is_in.h +0 -53
- package/inc/util/generic/iterator.h +0 -137
- package/inc/util/generic/iterator_range.h +0 -105
- package/inc/util/generic/lazy_value.h +0 -66
- package/inc/util/generic/list.h +0 -22
- package/inc/util/generic/map.h +0 -44
- package/inc/util/generic/mapfindptr.h +0 -60
- package/inc/util/generic/maybe.h +0 -713
- package/inc/util/generic/maybe_traits.h +0 -164
- package/inc/util/generic/mem_copy.h +0 -55
- package/inc/util/generic/noncopyable.h +0 -38
- package/inc/util/generic/object_counter.h +0 -53
- package/inc/util/generic/ptr.h +0 -1113
- package/inc/util/generic/queue.h +0 -57
- package/inc/util/generic/refcount.h +0 -162
- package/inc/util/generic/reserve.h +0 -11
- package/inc/util/generic/scope.h +0 -65
- package/inc/util/generic/serialized_enum.h +0 -406
- package/inc/util/generic/set.h +0 -42
- package/inc/util/generic/singleton.h +0 -136
- package/inc/util/generic/size_literals.h +0 -65
- package/inc/util/generic/stack.h +0 -18
- package/inc/util/generic/store_policy.h +0 -120
- package/inc/util/generic/strbase.h +0 -612
- package/inc/util/generic/strbuf.h +0 -552
- package/inc/util/generic/strfcpy.h +0 -17
- package/inc/util/generic/string.h +0 -1572
- package/inc/util/generic/string_hash.h +0 -21
- package/inc/util/generic/string_ut.h +0 -1175
- package/inc/util/generic/type_name.h +0 -34
- package/inc/util/generic/typelist.h +0 -114
- package/inc/util/generic/typetraits.h +0 -325
- package/inc/util/generic/utility.h +0 -132
- package/inc/util/generic/va_args.h +0 -400
- package/inc/util/generic/variant.h +0 -631
- package/inc/util/generic/variant_traits.h +0 -171
- package/inc/util/generic/vector.h +0 -119
- package/inc/util/generic/xrange.h +0 -258
- package/inc/util/generic/yexception.h +0 -212
- package/inc/util/generic/yexception_ut.h +0 -14
- package/inc/util/generic/ylimits.h +0 -92
- package/inc/util/generic/ymath.h +0 -206
- package/inc/util/memory/addstorage.h +0 -93
- package/inc/util/memory/alloc.h +0 -27
- package/inc/util/memory/blob.h +0 -296
- package/inc/util/memory/mmapalloc.h +0 -8
- package/inc/util/memory/pool.h +0 -432
- package/inc/util/memory/segmented_string_pool.h +0 -194
- package/inc/util/memory/segpool_alloc.h +0 -118
- package/inc/util/memory/smallobj.h +0 -141
- package/inc/util/memory/tempbuf.h +0 -111
- package/inc/util/network/address.h +0 -136
- package/inc/util/network/endpoint.h +0 -61
- package/inc/util/network/hostip.h +0 -16
- package/inc/util/network/init.h +0 -60
- package/inc/util/network/interface.h +0 -17
- package/inc/util/network/iovec.h +0 -65
- package/inc/util/network/ip.h +0 -116
- package/inc/util/network/nonblock.h +0 -8
- package/inc/util/network/pair.h +0 -9
- package/inc/util/network/poller.h +0 -58
- package/inc/util/network/pollerimpl.h +0 -707
- package/inc/util/network/sock.h +0 -608
- package/inc/util/network/socket.h +0 -421
- package/inc/util/random/common_ops.h +0 -130
- package/inc/util/random/easy.h +0 -47
- package/inc/util/random/entropy.h +0 -21
- package/inc/util/random/fast.h +0 -101
- package/inc/util/random/init_atfork.h +0 -3
- package/inc/util/random/lcg_engine.h +0 -66
- package/inc/util/random/mersenne.h +0 -46
- package/inc/util/random/mersenne32.h +0 -50
- package/inc/util/random/mersenne64.h +0 -50
- package/inc/util/random/normal.h +0 -38
- package/inc/util/random/random.h +0 -30
- package/inc/util/random/shuffle.h +0 -39
- package/inc/util/str_stl.h +0 -266
- package/inc/util/stream/aligned.h +0 -99
- package/inc/util/stream/buffer.h +0 -119
- package/inc/util/stream/buffered.h +0 -225
- package/inc/util/stream/debug.h +0 -53
- package/inc/util/stream/direct_io.h +0 -43
- package/inc/util/stream/file.h +0 -108
- package/inc/util/stream/format.h +0 -444
- package/inc/util/stream/fwd.h +0 -100
- package/inc/util/stream/hex.h +0 -8
- package/inc/util/stream/holder.h +0 -44
- package/inc/util/stream/input.h +0 -273
- package/inc/util/stream/labeled.h +0 -19
- package/inc/util/stream/length.h +0 -100
- package/inc/util/stream/mem.h +0 -255
- package/inc/util/stream/multi.h +0 -32
- package/inc/util/stream/null.h +0 -61
- package/inc/util/stream/output.h +0 -304
- package/inc/util/stream/pipe.h +0 -112
- package/inc/util/stream/printf.h +0 -25
- package/inc/util/stream/str.h +0 -207
- package/inc/util/stream/tee.h +0 -28
- package/inc/util/stream/tempbuf.h +0 -21
- package/inc/util/stream/tokenizer.h +0 -214
- package/inc/util/stream/trace.h +0 -60
- package/inc/util/stream/walk.h +0 -35
- package/inc/util/stream/zerocopy.h +0 -91
- package/inc/util/stream/zerocopy_output.h +0 -57
- package/inc/util/stream/zlib.h +0 -173
- package/inc/util/string/ascii.h +0 -236
- package/inc/util/string/builder.h +0 -39
- package/inc/util/string/cast.h +0 -347
- package/inc/util/string/cstriter.h +0 -14
- package/inc/util/string/escape.h +0 -70
- package/inc/util/string/hex.h +0 -59
- package/inc/util/string/join.h +0 -194
- package/inc/util/string/printf.h +0 -13
- package/inc/util/string/reverse.h +0 -16
- package/inc/util/string/split.h +0 -1080
- package/inc/util/string/strip.h +0 -257
- package/inc/util/string/strspn.h +0 -65
- package/inc/util/string/subst.h +0 -56
- package/inc/util/string/type.h +0 -50
- package/inc/util/string/util.h +0 -195
- package/inc/util/string/vector.h +0 -132
- package/inc/util/system/align.h +0 -50
- package/inc/util/system/atexit.h +0 -22
- package/inc/util/system/atomic.h +0 -51
- package/inc/util/system/atomic_gcc.h +0 -90
- package/inc/util/system/atomic_ops.h +0 -189
- package/inc/util/system/atomic_win.h +0 -114
- package/inc/util/system/backtrace.h +0 -39
- package/inc/util/system/byteorder.h +0 -186
- package/inc/util/system/compat.h +0 -84
- package/inc/util/system/compiler.h +0 -620
- package/inc/util/system/condvar.h +0 -71
- package/inc/util/system/context.h +0 -181
- package/inc/util/system/context_aarch64.h +0 -8
- package/inc/util/system/context_i686.h +0 -9
- package/inc/util/system/context_x86.h +0 -12
- package/inc/util/system/context_x86_64.h +0 -7
- package/inc/util/system/cpu_id.h +0 -159
- package/inc/util/system/daemon.h +0 -28
- package/inc/util/system/datetime.h +0 -98
- package/inc/util/system/defaults.h +0 -149
- package/inc/util/system/demangle.h +0 -5
- package/inc/util/system/demangle_impl.h +0 -23
- package/inc/util/system/direct_io.h +0 -71
- package/inc/util/system/dynlib.h +0 -119
- package/inc/util/system/env.h +0 -32
- package/inc/util/system/error.h +0 -95
- package/inc/util/system/event.h +0 -122
- package/inc/util/system/execpath.h +0 -17
- package/inc/util/system/fasttime.h +0 -6
- package/inc/util/system/fhandle.h +0 -27
- package/inc/util/system/file.h +0 -210
- package/inc/util/system/file_lock.h +0 -34
- package/inc/util/system/filemap.h +0 -383
- package/inc/util/system/flock.h +0 -35
- package/inc/util/system/fs.h +0 -156
- package/inc/util/system/fs_win.h +0 -29
- package/inc/util/system/fstat.h +0 -46
- package/inc/util/system/getpid.h +0 -12
- package/inc/util/system/guard.h +0 -179
- package/inc/util/system/hi_lo.h +0 -139
- package/inc/util/system/hostname.h +0 -10
- package/inc/util/system/hp_timer.h +0 -36
- package/inc/util/system/info.h +0 -12
- package/inc/util/system/interrupt_signals.h +0 -22
- package/inc/util/system/madvise.h +0 -30
- package/inc/util/system/maxlen.h +0 -32
- package/inc/util/system/mem_info.h +0 -18
- package/inc/util/system/mincore.h +0 -38
- package/inc/util/system/mktemp.h +0 -11
- package/inc/util/system/mlock.h +0 -43
- package/inc/util/system/mutex.h +0 -67
- package/inc/util/system/nice.h +0 -3
- package/inc/util/system/pipe.h +0 -90
- package/inc/util/system/platform.h +0 -246
- package/inc/util/system/progname.h +0 -13
- package/inc/util/system/protect.h +0 -25
- package/inc/util/system/rusage.h +0 -26
- package/inc/util/system/rwlock.h +0 -78
- package/inc/util/system/sanitizers.h +0 -122
- package/inc/util/system/sem.h +0 -41
- package/inc/util/system/shellcommand.h +0 -472
- package/inc/util/system/shmat.h +0 -32
- package/inc/util/system/sigset.h +0 -78
- package/inc/util/system/spin_wait.h +0 -10
- package/inc/util/system/spinlock.h +0 -121
- package/inc/util/system/src_location.h +0 -25
- package/inc/util/system/src_root.h +0 -68
- package/inc/util/system/sys_alloc.h +0 -43
- package/inc/util/system/sysstat.h +0 -52
- package/inc/util/system/tempfile.h +0 -34
- package/inc/util/system/thread.h +0 -167
- package/inc/util/system/tls.h +0 -307
- package/inc/util/system/types.h +0 -119
- package/inc/util/system/unaligned_mem.h +0 -67
- package/inc/util/system/user.h +0 -5
- package/inc/util/system/utime.h +0 -6
- package/inc/util/system/valgrind.h +0 -48
- package/inc/util/system/winint.h +0 -43
- package/inc/util/system/yassert.h +0 -121
- package/inc/util/system/yield.h +0 -4
- package/inc/util/thread/factory.h +0 -65
- package/inc/util/thread/fwd.h +0 -30
- package/inc/util/thread/lfqueue.h +0 -406
- package/inc/util/thread/lfstack.h +0 -188
- package/inc/util/thread/pool.h +0 -388
- package/inc/util/thread/singleton.h +0 -42
- package/inc/util/ysafeptr.h +0 -427
- package/inc/util/ysaveload.h +0 -700
package/inc/util/charset/wide.h
DELETED
|
@@ -1,843 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "recode_result.h"
|
|
4
|
-
#include "unidata.h"
|
|
5
|
-
#include "utf8.h"
|
|
6
|
-
#include "wide_specific.h"
|
|
7
|
-
|
|
8
|
-
#include <util/generic/algorithm.h>
|
|
9
|
-
#include <util/generic/string.h>
|
|
10
|
-
#include <util/generic/yexception.h>
|
|
11
|
-
#include <util/memory/tempbuf.h>
|
|
12
|
-
#include <util/system/compiler.h>
|
|
13
|
-
#include <util/system/cpu_id.h>
|
|
14
|
-
#include <util/system/yassert.h>
|
|
15
|
-
|
|
16
|
-
#include <cstring>
|
|
17
|
-
|
|
18
|
-
#ifdef _sse2_
|
|
19
|
-
#include <emmintrin.h>
|
|
20
|
-
#endif
|
|
21
|
-
|
|
22
|
-
template <class T>
|
|
23
|
-
class TTempArray;
|
|
24
|
-
using TCharTemp = TTempArray<wchar16>;
|
|
25
|
-
|
|
26
|
-
namespace NDetail {
|
|
27
|
-
inline TString InStringMsg(const char* s, size_t len) {
|
|
28
|
-
return (len <= 50) ? " in string " + TString(s, len).Quote() : TString();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
template <bool isPointer>
|
|
32
|
-
struct TSelector;
|
|
33
|
-
|
|
34
|
-
template <>
|
|
35
|
-
struct TSelector<false> {
|
|
36
|
-
template <class T>
|
|
37
|
-
static inline void WriteSymbol(wchar16 s, T& dest) noexcept {
|
|
38
|
-
dest.push_back(s);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
template <>
|
|
43
|
-
struct TSelector<true> {
|
|
44
|
-
template <class T>
|
|
45
|
-
static inline void WriteSymbol(wchar16 s, T& dest) noexcept {
|
|
46
|
-
*(dest++) = s;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
inline wchar32 ReadSurrogatePair(const wchar16* chars) noexcept {
|
|
51
|
-
const wchar32 SURROGATE_OFFSET = static_cast<wchar32>(0x10000 - (0xD800 << 10) - 0xDC00);
|
|
52
|
-
wchar16 lead = chars[0];
|
|
53
|
-
wchar16 tail = chars[1];
|
|
54
|
-
|
|
55
|
-
Y_ASSERT(IsW16SurrogateLead(lead));
|
|
56
|
-
Y_ASSERT(IsW16SurrogateTail(tail));
|
|
57
|
-
|
|
58
|
-
return (static_cast<wchar32>(lead) << 10) + tail + SURROGATE_OFFSET;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
template <class T>
|
|
62
|
-
inline void WriteSurrogatePair(wchar32 s, T& dest) noexcept;
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
inline wchar16* SkipSymbol(wchar16* begin, const wchar16* end) noexcept {
|
|
67
|
-
return begin + W16SymbolSize(begin, end);
|
|
68
|
-
}
|
|
69
|
-
inline const wchar16* SkipSymbol(const wchar16* begin, const wchar16* end) noexcept {
|
|
70
|
-
return begin + W16SymbolSize(begin, end);
|
|
71
|
-
}
|
|
72
|
-
inline wchar32* SkipSymbol(wchar32* begin, const wchar32* end) noexcept {
|
|
73
|
-
Y_ASSERT(begin < end);
|
|
74
|
-
return begin + 1;
|
|
75
|
-
}
|
|
76
|
-
inline const wchar32* SkipSymbol(const wchar32* begin, const wchar32* end) noexcept {
|
|
77
|
-
Y_ASSERT(begin < end);
|
|
78
|
-
return begin + 1;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
inline wchar32 ReadSymbol(const wchar16* begin, const wchar16* end) noexcept {
|
|
82
|
-
Y_ASSERT(begin < end);
|
|
83
|
-
if (IsW16SurrogateLead(*begin)) {
|
|
84
|
-
if (begin + 1 != end && IsW16SurrogateTail(*(begin + 1)))
|
|
85
|
-
return ::NDetail::ReadSurrogatePair(begin);
|
|
86
|
-
|
|
87
|
-
return BROKEN_RUNE;
|
|
88
|
-
} else if (IsW16SurrogateTail(*begin)) {
|
|
89
|
-
return BROKEN_RUNE;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return *begin;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
inline wchar32 ReadSymbol(const wchar32* begin, const wchar32* end) noexcept {
|
|
96
|
-
Y_ASSERT(begin < end);
|
|
97
|
-
return *begin;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
//! presuming input data is either big enought of null terminated
|
|
101
|
-
inline wchar32 ReadSymbolAndAdvance(const wchar16*& begin) noexcept {
|
|
102
|
-
Y_ASSERT(*begin);
|
|
103
|
-
if (IsW16SurrogateLead(begin[0])) {
|
|
104
|
-
if (IsW16SurrogateTail(begin[1])) {
|
|
105
|
-
Y_ASSERT(begin[1] != 0);
|
|
106
|
-
const wchar32 c = ::NDetail::ReadSurrogatePair(begin);
|
|
107
|
-
begin += 2;
|
|
108
|
-
return c;
|
|
109
|
-
}
|
|
110
|
-
++begin;
|
|
111
|
-
return BROKEN_RUNE;
|
|
112
|
-
} else if (IsW16SurrogateTail(begin[0])) {
|
|
113
|
-
++begin;
|
|
114
|
-
return BROKEN_RUNE;
|
|
115
|
-
}
|
|
116
|
-
return *(begin++);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
//! presuming input data is either big enought of null terminated
|
|
120
|
-
inline wchar32 ReadSymbolAndAdvance(const wchar32*& begin) noexcept {
|
|
121
|
-
Y_ASSERT(*begin);
|
|
122
|
-
return *(begin++);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
inline wchar32 ReadSymbolAndAdvance(const wchar16*& begin, const wchar16* end) noexcept {
|
|
126
|
-
Y_ASSERT(begin < end);
|
|
127
|
-
if (IsW16SurrogateLead(begin[0])) {
|
|
128
|
-
if (begin + 1 != end && IsW16SurrogateTail(begin[1])) {
|
|
129
|
-
const wchar32 c = ::NDetail::ReadSurrogatePair(begin);
|
|
130
|
-
begin += 2;
|
|
131
|
-
return c;
|
|
132
|
-
}
|
|
133
|
-
++begin;
|
|
134
|
-
return BROKEN_RUNE;
|
|
135
|
-
} else if (IsW16SurrogateTail(begin[0])) {
|
|
136
|
-
++begin;
|
|
137
|
-
return BROKEN_RUNE;
|
|
138
|
-
}
|
|
139
|
-
return *(begin++);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
inline wchar32 ReadSymbolAndAdvance(const wchar32*& begin, const wchar32* end) noexcept {
|
|
143
|
-
Y_ASSERT(begin < end);
|
|
144
|
-
return *(begin++);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
template <class T>
|
|
148
|
-
inline size_t WriteSymbol(wchar16 s, T& dest) noexcept {
|
|
149
|
-
::NDetail::TSelector<std::is_pointer<T>::value>::WriteSymbol(s, dest);
|
|
150
|
-
return 1;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
template <class T>
|
|
154
|
-
inline size_t WriteSymbol(wchar32 s, T& dest) noexcept {
|
|
155
|
-
if (s > 0xFFFF) {
|
|
156
|
-
if (s >= ::NUnicode::UnicodeInstancesLimit()) {
|
|
157
|
-
return WriteSymbol(static_cast<wchar16>(BROKEN_RUNE), dest);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
::NDetail::WriteSurrogatePair(s, dest);
|
|
161
|
-
return 2;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return WriteSymbol(static_cast<wchar16>(s), dest);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
inline bool WriteSymbol(wchar32 s, wchar16*& dest, const wchar16* destEnd) noexcept {
|
|
168
|
-
Y_ASSERT(dest < destEnd);
|
|
169
|
-
|
|
170
|
-
if (s > 0xFFFF) {
|
|
171
|
-
if (s >= NUnicode::UnicodeInstancesLimit()) {
|
|
172
|
-
*(dest++) = static_cast<wchar16>(BROKEN_RUNE);
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (dest + 2 > destEnd)
|
|
177
|
-
return false;
|
|
178
|
-
|
|
179
|
-
::NDetail::WriteSurrogatePair(s, dest);
|
|
180
|
-
} else {
|
|
181
|
-
*(dest++) = static_cast<wchar16>(s);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
inline size_t WriteSymbol(wchar32 s, wchar32*& dest) noexcept {
|
|
188
|
-
*(dest++) = s;
|
|
189
|
-
return 1;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
inline bool WriteSymbol(wchar32 s, wchar32*& dest, const wchar32* destEnd) noexcept {
|
|
193
|
-
Y_ASSERT(dest < destEnd);
|
|
194
|
-
|
|
195
|
-
*(dest++) = s;
|
|
196
|
-
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
template <class T>
|
|
201
|
-
inline void ::NDetail::WriteSurrogatePair(wchar32 s, T& dest) noexcept {
|
|
202
|
-
const wchar32 LEAD_OFFSET = 0xD800 - (0x10000 >> 10);
|
|
203
|
-
Y_ASSERT(s > 0xFFFF && s < ::NUnicode::UnicodeInstancesLimit());
|
|
204
|
-
|
|
205
|
-
wchar16 lead = LEAD_OFFSET + (static_cast<wchar16>(s >> 10));
|
|
206
|
-
wchar16 tail = 0xDC00 + static_cast<wchar16>(s & 0x3FF);
|
|
207
|
-
Y_ASSERT(IsW16SurrogateLead(lead));
|
|
208
|
-
Y_ASSERT(IsW16SurrogateTail(tail));
|
|
209
|
-
|
|
210
|
-
WriteSymbol(lead, dest);
|
|
211
|
-
WriteSymbol(tail, dest);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
class TCharIterator {
|
|
215
|
-
private:
|
|
216
|
-
const wchar16* Begin;
|
|
217
|
-
const wchar16* End;
|
|
218
|
-
|
|
219
|
-
public:
|
|
220
|
-
inline explicit TCharIterator(const wchar16* end)
|
|
221
|
-
: Begin(end)
|
|
222
|
-
, End(end)
|
|
223
|
-
{
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
inline TCharIterator(const wchar16* begin, const wchar16* end)
|
|
227
|
-
: Begin(begin)
|
|
228
|
-
, End(end)
|
|
229
|
-
{
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
inline TCharIterator& operator++() {
|
|
233
|
-
Begin = SkipSymbol(Begin, End);
|
|
234
|
-
|
|
235
|
-
return *this;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
inline bool operator==(const wchar16* other) const {
|
|
239
|
-
return Begin == other;
|
|
240
|
-
}
|
|
241
|
-
inline bool operator!=(const wchar16* other) const {
|
|
242
|
-
return !(*this == other);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
inline bool operator==(const TCharIterator& other) const {
|
|
246
|
-
return *this == other.Begin;
|
|
247
|
-
}
|
|
248
|
-
inline bool operator!=(const TCharIterator& other) const {
|
|
249
|
-
return *this != other.Begin;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
inline wchar32 operator*() const {
|
|
253
|
-
return ReadSymbol(Begin, End);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
inline const wchar16* Get() const {
|
|
257
|
-
return Begin;
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
namespace NDetail {
|
|
262
|
-
template <bool robust, typename TCharType>
|
|
263
|
-
inline void UTF8ToWideImplScalar(const unsigned char*& cur, const unsigned char* last, TCharType*& dest) noexcept {
|
|
264
|
-
wchar32 rune = BROKEN_RUNE;
|
|
265
|
-
|
|
266
|
-
while (cur != last) {
|
|
267
|
-
if (ReadUTF8CharAndAdvance(rune, cur, last) != RECODE_OK) {
|
|
268
|
-
if (robust) {
|
|
269
|
-
rune = BROKEN_RUNE;
|
|
270
|
-
++cur;
|
|
271
|
-
} else {
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
Y_ASSERT(cur <= last);
|
|
277
|
-
WriteSymbol(rune, dest);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
template <typename TCharType>
|
|
282
|
-
inline void UTF16ToUTF32ImplScalar(const wchar16* cur, const wchar16* last, TCharType*& dest) noexcept {
|
|
283
|
-
wchar32 rune = BROKEN_RUNE;
|
|
284
|
-
|
|
285
|
-
while (cur != last) {
|
|
286
|
-
rune = ReadSymbolAndAdvance(cur, last);
|
|
287
|
-
Y_ASSERT(cur <= last);
|
|
288
|
-
WriteSymbol(rune, dest);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
template <class TCharType>
|
|
293
|
-
inline void UTF8ToWideImplSSE41(const unsigned char*& /*cur*/, const unsigned char* /*last*/, TCharType*& /*dest*/) noexcept {
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
void UTF8ToWideImplSSE41(const unsigned char*& cur, const unsigned char* last, wchar16*& dest) noexcept;
|
|
297
|
-
|
|
298
|
-
void UTF8ToWideImplSSE41(const unsigned char*& cur, const unsigned char* last, wchar32*& dest) noexcept;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
//! @return len if robust and position where encoding stopped if not
|
|
302
|
-
template <bool robust, typename TCharType>
|
|
303
|
-
inline size_t UTF8ToWideImpl(const char* text, size_t len, TCharType* dest, size_t& written) noexcept {
|
|
304
|
-
const unsigned char* cur = reinterpret_cast<const unsigned char*>(text);
|
|
305
|
-
const unsigned char* last = cur + len;
|
|
306
|
-
TCharType* p = dest;
|
|
307
|
-
#ifdef _sse_ //can't check for sse4, as we build most of arcadia without sse4 support even on platforms that support it
|
|
308
|
-
if (cur + 16 <= last && NX86::CachedHaveSSE41()) {
|
|
309
|
-
::NDetail::UTF8ToWideImplSSE41(cur, last, p);
|
|
310
|
-
}
|
|
311
|
-
#endif
|
|
312
|
-
|
|
313
|
-
::NDetail::UTF8ToWideImplScalar<robust>(cur, last, p);
|
|
314
|
-
written = p - dest;
|
|
315
|
-
return cur - reinterpret_cast<const unsigned char*>(text);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
template <typename TCharType>
|
|
319
|
-
inline size_t UTF8ToWideImpl(const char* text, size_t len, TCharType* dest, size_t& written) {
|
|
320
|
-
return UTF8ToWideImpl<false>(text, len, dest, written);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
template <bool robust>
|
|
324
|
-
inline TUtf16String UTF8ToWide(const char* text, size_t len) {
|
|
325
|
-
TUtf16String w = TUtf16String::Uninitialized(len);
|
|
326
|
-
size_t written;
|
|
327
|
-
size_t pos = UTF8ToWideImpl<robust>(text, len, w.begin(), written);
|
|
328
|
-
if (pos != len)
|
|
329
|
-
ythrow yexception() << "failed to decode UTF-8 string at pos " << pos << ::NDetail::InStringMsg(text, len);
|
|
330
|
-
Y_ASSERT(w.size() >= written);
|
|
331
|
-
w.remove(written);
|
|
332
|
-
return w;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
template <bool robust, typename TCharType>
|
|
336
|
-
inline bool UTF8ToWide(const char* text, size_t len, TCharType* dest, size_t& written) noexcept {
|
|
337
|
-
return UTF8ToWideImpl<robust>(text, len, dest, written) == len;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
//! converts text from UTF8 to unicode, stops immediately it UTF8 byte sequence is wrong
|
|
341
|
-
//! @attention destination buffer must be long enough to fit all characters of the text,
|
|
342
|
-
//! conversion stops if a broken symbol is met
|
|
343
|
-
//! @return @c true if all the text converted successfully, @c false - a broken symbol was found
|
|
344
|
-
template <typename TCharType>
|
|
345
|
-
inline bool UTF8ToWide(const char* text, size_t len, TCharType* dest, size_t& written) noexcept {
|
|
346
|
-
return UTF8ToWide<false>(text, len, dest, written);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
template <bool robust>
|
|
350
|
-
inline TWtringBuf UTF8ToWide(const TStringBuf src, TUtf16String& dst) {
|
|
351
|
-
dst.ReserveAndResize(src.size());
|
|
352
|
-
size_t written = 0;
|
|
353
|
-
UTF8ToWideImpl<robust>(src.data(), src.size(), dst.begin(), written);
|
|
354
|
-
dst.resize(written);
|
|
355
|
-
return dst;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
//! if not robust will stop at first error position
|
|
359
|
-
template <bool robust>
|
|
360
|
-
inline TUtf32StringBuf UTF8ToUTF32(const TStringBuf src, TUtf32String& dst) {
|
|
361
|
-
dst.ReserveAndResize(src.size());
|
|
362
|
-
size_t written = 0;
|
|
363
|
-
UTF8ToWideImpl<robust>(src.data(), src.size(), dst.begin(), written);
|
|
364
|
-
dst.resize(written);
|
|
365
|
-
return dst;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
inline TWtringBuf UTF8ToWide(const TStringBuf src, TUtf16String& dst) {
|
|
369
|
-
return UTF8ToWide<false>(src, dst);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
inline TUtf16String UTF8ToWide(const char* text, size_t len) {
|
|
373
|
-
return UTF8ToWide<false>(text, len);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
template <bool robust>
|
|
377
|
-
inline TUtf16String UTF8ToWide(const TStringBuf s) {
|
|
378
|
-
return UTF8ToWide<robust>(s.data(), s.size());
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
template <bool robust>
|
|
382
|
-
inline TUtf32String UTF8ToUTF32(const TStringBuf s) {
|
|
383
|
-
TUtf32String r;
|
|
384
|
-
UTF8ToUTF32<robust>(s, r);
|
|
385
|
-
return r;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
inline TUtf16String UTF8ToWide(const TStringBuf s) {
|
|
389
|
-
return UTF8ToWide<false>(s.data(), s.size());
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
//! converts text from unicode to UTF8
|
|
393
|
-
//! @attention destination buffer must be long enough to fit all characters of the text,
|
|
394
|
-
//! @c WriteUTF8Char converts @c wchar32 into maximum 4 bytes of UTF8 so
|
|
395
|
-
//! destination buffer must have length equal to <tt> len * 4 </tt>
|
|
396
|
-
template <typename TCharType>
|
|
397
|
-
inline void WideToUTF8(const TCharType* text, size_t len, char* dest, size_t& written) {
|
|
398
|
-
const TCharType* const last = text + len;
|
|
399
|
-
unsigned char* p = reinterpret_cast<unsigned char*>(dest);
|
|
400
|
-
size_t runeLen;
|
|
401
|
-
for (const TCharType* cur = text; cur != last;) {
|
|
402
|
-
WriteUTF8Char(ReadSymbolAndAdvance(cur, last), runeLen, p);
|
|
403
|
-
Y_ASSERT(runeLen <= 4);
|
|
404
|
-
p += runeLen;
|
|
405
|
-
}
|
|
406
|
-
written = p - reinterpret_cast<unsigned char*>(dest);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
constexpr size_t WideToUTF8BufferSize(const size_t inputStringSize) noexcept {
|
|
410
|
-
return inputStringSize * 4; // * 4 because the conversion functions can convert unicode character into maximum 4 bytes of UTF8
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
inline TStringBuf WideToUTF8(const TWtringBuf src, TString& dst) {
|
|
414
|
-
dst.ReserveAndResize(WideToUTF8BufferSize(src.size()));
|
|
415
|
-
size_t written = 0;
|
|
416
|
-
WideToUTF8(src.data(), src.size(), dst.begin(), written);
|
|
417
|
-
Y_ASSERT(dst.size() >= written);
|
|
418
|
-
dst.remove(written);
|
|
419
|
-
return dst;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
inline TString WideToUTF8(const wchar16* text, size_t len) {
|
|
423
|
-
TString s = TString::Uninitialized(WideToUTF8BufferSize(len));
|
|
424
|
-
size_t written = 0;
|
|
425
|
-
WideToUTF8(text, len, s.begin(), written);
|
|
426
|
-
Y_ASSERT(s.size() >= written);
|
|
427
|
-
s.remove(written);
|
|
428
|
-
return s;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
inline TString WideToUTF8(const wchar32* text, size_t len) {
|
|
432
|
-
TString s = TString::Uninitialized(WideToUTF8BufferSize(len));
|
|
433
|
-
size_t written = 0;
|
|
434
|
-
WideToUTF8(text, len, s.begin(), written);
|
|
435
|
-
Y_ASSERT(s.size() >= written);
|
|
436
|
-
s.remove(written);
|
|
437
|
-
return s;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
inline TString WideToUTF8(const TWtringBuf w) {
|
|
441
|
-
return WideToUTF8(w.data(), w.size());
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
inline TString WideToUTF8(const TUtf32StringBuf w) {
|
|
445
|
-
return WideToUTF8(w.data(), w.size());
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
inline TUtf16String UTF32ToWide(const wchar32* begin, size_t len) {
|
|
449
|
-
TUtf16String res;
|
|
450
|
-
res.reserve(len);
|
|
451
|
-
|
|
452
|
-
const wchar32* end = begin + len;
|
|
453
|
-
for (const wchar32* i = begin; i != end; ++i) {
|
|
454
|
-
WriteSymbol(*i, res);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return res;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// adopted from https://chromium.googlesource.com/chromium/src/+/master/base/strings/string_util.cc
|
|
461
|
-
// Assuming that a pointer is the size of a "machine word", then
|
|
462
|
-
// uintptr_t is an integer type that is also a machine word.
|
|
463
|
-
|
|
464
|
-
namespace NDetail {
|
|
465
|
-
using TMachineWord = uintptr_t;
|
|
466
|
-
const uintptr_t kMachineWordAlignmentMask = sizeof(TMachineWord) - 1;
|
|
467
|
-
|
|
468
|
-
inline bool IsAlignedToMachineWord(const void* pointer) {
|
|
469
|
-
return !(reinterpret_cast<TMachineWord>(pointer) & kMachineWordAlignmentMask);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
template <typename T>
|
|
473
|
-
inline T* AlignToMachineWord(T* pointer) {
|
|
474
|
-
return reinterpret_cast<T*>(reinterpret_cast<TMachineWord>(pointer) & ~kMachineWordAlignmentMask);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
template <size_t size, typename CharacterType>
|
|
478
|
-
struct NonASCIIMask;
|
|
479
|
-
|
|
480
|
-
template <>
|
|
481
|
-
struct
|
|
482
|
-
NonASCIIMask<4, wchar16> {
|
|
483
|
-
static constexpr ui32 Value() {
|
|
484
|
-
return 0xFF80FF80U;
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
template <>
|
|
489
|
-
struct
|
|
490
|
-
NonASCIIMask<4, char> {
|
|
491
|
-
static constexpr ui32 Value() {
|
|
492
|
-
return 0x80808080U;
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
template <>
|
|
497
|
-
struct
|
|
498
|
-
NonASCIIMask<8, wchar16> {
|
|
499
|
-
static constexpr ui64 Value() {
|
|
500
|
-
return 0xFF80FF80FF80FF80ULL;
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
template <>
|
|
505
|
-
struct
|
|
506
|
-
NonASCIIMask<8, char> {
|
|
507
|
-
static constexpr ui64 Value() {
|
|
508
|
-
return 0x8080808080808080ULL;
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
template <typename TChar>
|
|
513
|
-
inline bool DoIsStringASCIISlow(const TChar* first, const TChar* last) {
|
|
514
|
-
using TUnsignedChar = std::make_unsigned_t<TChar>;
|
|
515
|
-
Y_ASSERT(first <= last);
|
|
516
|
-
for (; first != last; ++first) {
|
|
517
|
-
if (static_cast<TUnsignedChar>(*first) > 0x7F) {
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
return true;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
template <typename TChar>
|
|
525
|
-
inline bool DoIsStringASCII(const TChar* first, const TChar* last) {
|
|
526
|
-
if (last - first < 10) {
|
|
527
|
-
return DoIsStringASCIISlow(first, last);
|
|
528
|
-
}
|
|
529
|
-
TMachineWord allCharBits = 0;
|
|
530
|
-
TMachineWord nonAsciiBitMask = NonASCIIMask<sizeof(TMachineWord), TChar>::Value();
|
|
531
|
-
|
|
532
|
-
// Prologue: align the input.
|
|
533
|
-
while (!IsAlignedToMachineWord(first) && first != last) {
|
|
534
|
-
allCharBits |= *first;
|
|
535
|
-
++first;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// Compare the values of CPU word size.
|
|
539
|
-
const TChar* word_end = AlignToMachineWord(last);
|
|
540
|
-
const size_t loopIncrement = sizeof(TMachineWord) / sizeof(TChar);
|
|
541
|
-
while (first < word_end) {
|
|
542
|
-
allCharBits |= *(reinterpret_cast<const TMachineWord*>(first));
|
|
543
|
-
first += loopIncrement;
|
|
544
|
-
|
|
545
|
-
// fast exit
|
|
546
|
-
if (allCharBits & nonAsciiBitMask) {
|
|
547
|
-
return false;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// Process the remaining bytes.
|
|
552
|
-
while (first != last) {
|
|
553
|
-
allCharBits |= *first;
|
|
554
|
-
++first;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
return !(allCharBits & nonAsciiBitMask);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
#ifdef _sse2_
|
|
561
|
-
inline bool DoIsStringASCIISSE(const unsigned char* first, const unsigned char* last) {
|
|
562
|
-
//scalar version for short strings
|
|
563
|
-
if (first + 8 > last) {
|
|
564
|
-
return ::NDetail::DoIsStringASCIISlow(first, last);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
alignas(16) unsigned char buf[16];
|
|
568
|
-
|
|
569
|
-
while (first + 16 <= last) {
|
|
570
|
-
memcpy(buf, first, 16);
|
|
571
|
-
__m128i chunk = _mm_load_si128(reinterpret_cast<__m128i*>(buf));
|
|
572
|
-
|
|
573
|
-
int asciiMask = _mm_movemask_epi8(chunk);
|
|
574
|
-
if (asciiMask) {
|
|
575
|
-
return false;
|
|
576
|
-
}
|
|
577
|
-
first += 16;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
if (first + 8 <= last) {
|
|
581
|
-
memcpy(buf, first, 8);
|
|
582
|
-
__m128i chunk = _mm_loadl_epi64(reinterpret_cast<__m128i*>(buf));
|
|
583
|
-
|
|
584
|
-
int asciiMask = _mm_movemask_epi8(chunk);
|
|
585
|
-
if (asciiMask) {
|
|
586
|
-
return false;
|
|
587
|
-
}
|
|
588
|
-
first += 8;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
return ::NDetail::DoIsStringASCIISlow(first, last);
|
|
592
|
-
}
|
|
593
|
-
#endif //_sse2_
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
//! returns @c true if character sequence has no symbols with value greater than 0x7F
|
|
598
|
-
template <typename TChar>
|
|
599
|
-
inline bool IsStringASCII(const TChar* first, const TChar* last) {
|
|
600
|
-
return ::NDetail::DoIsStringASCII(first, last);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
#ifdef _sse2_
|
|
604
|
-
template <>
|
|
605
|
-
inline bool IsStringASCII<unsigned char>(const unsigned char* first, const unsigned char* last) {
|
|
606
|
-
return ::NDetail::DoIsStringASCIISSE(first, last);
|
|
607
|
-
}
|
|
608
|
-
template <>
|
|
609
|
-
inline bool IsStringASCII<char>(const char* first, const char* last) {
|
|
610
|
-
return ::NDetail::DoIsStringASCIISSE(reinterpret_cast<const unsigned char*>(first), reinterpret_cast<const unsigned char*>(last));
|
|
611
|
-
}
|
|
612
|
-
#endif
|
|
613
|
-
|
|
614
|
-
//! copies elements from one character sequence to another using memcpy
|
|
615
|
-
//! for compatibility only
|
|
616
|
-
template <typename TChar>
|
|
617
|
-
inline void Copy(const TChar* first, size_t len, TChar* result) {
|
|
618
|
-
memcpy(result, first, len * sizeof(TChar));
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
template <typename TChar1, typename TChar2>
|
|
622
|
-
inline void Copy(const TChar1* first, size_t len, TChar2* result) {
|
|
623
|
-
Copy(first, first + len, result);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
//! copies symbols from one character sequence to another without any conversion
|
|
627
|
-
//! @note this function can be used instead of the template constructor of @c std::basic_string:
|
|
628
|
-
//! template <typename InputIterator>
|
|
629
|
-
//! basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator());
|
|
630
|
-
//! and the family of template member functions: append, assign, insert, replace.
|
|
631
|
-
template <typename TStringType, typename TChar>
|
|
632
|
-
inline TStringType CopyTo(const TChar* first, const TChar* last) {
|
|
633
|
-
Y_ASSERT(first <= last);
|
|
634
|
-
TStringType str = TStringType::Uninitialized(last - first);
|
|
635
|
-
Copy(first, last, str.begin());
|
|
636
|
-
return str;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
template <typename TStringType, typename TChar>
|
|
640
|
-
inline TStringType CopyTo(const TChar* s, size_t n) {
|
|
641
|
-
TStringType str = TStringType::Uninitialized(n);
|
|
642
|
-
Copy(s, n, str.begin());
|
|
643
|
-
return str;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
inline TString WideToASCII(const TWtringBuf w) {
|
|
647
|
-
Y_ASSERT(IsStringASCII(w.begin(), w.end()));
|
|
648
|
-
return CopyTo<TString>(w.begin(), w.end());
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
inline TUtf16String ASCIIToWide(const TStringBuf s) {
|
|
652
|
-
Y_ASSERT(IsStringASCII(s.begin(), s.end()));
|
|
653
|
-
return CopyTo<TUtf16String>(s.begin(), s.end());
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
inline TUtf32String ASCIIToUTF32(const TStringBuf s) {
|
|
657
|
-
Y_ASSERT(IsStringASCII(s.begin(), s.end()));
|
|
658
|
-
return CopyTo<TUtf32String>(s.begin(), s.end());
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
//! returns @c true if string contains whitespace characters only
|
|
662
|
-
inline bool IsSpace(const wchar16* s, size_t n) {
|
|
663
|
-
if (n == 0)
|
|
664
|
-
return false;
|
|
665
|
-
|
|
666
|
-
Y_ASSERT(s);
|
|
667
|
-
|
|
668
|
-
const wchar16* const e = s + n;
|
|
669
|
-
for (const wchar16* p = s; p != e; ++p) {
|
|
670
|
-
if (!IsWhitespace(*p))
|
|
671
|
-
return false;
|
|
672
|
-
}
|
|
673
|
-
return true;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
//! returns @c true if string contains whitespace characters only
|
|
677
|
-
inline bool IsSpace(const TWtringBuf s) {
|
|
678
|
-
return IsSpace(s.data(), s.length());
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
//! replaces multiple sequential whitespace characters with a single space character
|
|
682
|
-
void Collapse(TUtf16String& w);
|
|
683
|
-
|
|
684
|
-
//! @return new length
|
|
685
|
-
size_t Collapse(wchar16* s, size_t n);
|
|
686
|
-
|
|
687
|
-
//! Removes leading whitespace characters
|
|
688
|
-
TWtringBuf StripLeft(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
|
|
689
|
-
void StripLeft(TUtf16String& text);
|
|
690
|
-
|
|
691
|
-
//! Removes trailing whitespace characters
|
|
692
|
-
TWtringBuf StripRight(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
|
|
693
|
-
void StripRight(TUtf16String& text);
|
|
694
|
-
|
|
695
|
-
//! Removes leading and trailing whitespace characters
|
|
696
|
-
TWtringBuf Strip(const TWtringBuf text) noexcept Y_WARN_UNUSED_RESULT;
|
|
697
|
-
void Strip(TUtf16String& text);
|
|
698
|
-
|
|
699
|
-
/* Check if given word is lowercase/uppercase. Will return false if string contains any
|
|
700
|
-
* non-alphabetical symbols. It is expected that `text` is a correct UTF-16 string.
|
|
701
|
-
*
|
|
702
|
-
* For example `IsLowerWord("hello")` will return `true`, when `IsLowerWord("hello there")` will
|
|
703
|
-
* return false because of the space in the middle of the string. Empty string is also considered
|
|
704
|
-
* lowercase.
|
|
705
|
-
*/
|
|
706
|
-
bool IsLowerWord(const TWtringBuf text) noexcept;
|
|
707
|
-
bool IsUpperWord(const TWtringBuf text) noexcept;
|
|
708
|
-
|
|
709
|
-
/* Will check if given word starts with capital letter and the rest of the word is lowercase. Will
|
|
710
|
-
* return `false` for empty string. See also `IsLowerWord`.
|
|
711
|
-
*/
|
|
712
|
-
bool IsTitleWord(const TWtringBuf text) noexcept;
|
|
713
|
-
|
|
714
|
-
/* Check if given string is lowercase/uppercase. Will return `true` if all alphabetic symbols are
|
|
715
|
-
* in proper case, all other symbols are ignored. It is expected that `text` is a correct UTF-16
|
|
716
|
-
* string.
|
|
717
|
-
*
|
|
718
|
-
* For example `IsLowerWord("hello")` will return `true` and `IsLowerWord("hello there")` will
|
|
719
|
-
* also return true because. Empty string is also considered lowercase.
|
|
720
|
-
*
|
|
721
|
-
* NOTE: for any case where `IsLowerWord` returns `true` `IsLower` will also return `true`.
|
|
722
|
-
*/
|
|
723
|
-
bool IsLower(const TWtringBuf text) noexcept;
|
|
724
|
-
bool IsUpper(const TWtringBuf text) noexcept;
|
|
725
|
-
|
|
726
|
-
/* Lowercase/uppercase given string inplace. Any alphabetic symbol will be converted to a proper
|
|
727
|
-
* case, the rest of the symbols will be kept the same. It is expected that `text` is a correct
|
|
728
|
-
* UTF-16 string.
|
|
729
|
-
*
|
|
730
|
-
* For example `ToLower("heLLo")` will return `"hello"`.
|
|
731
|
-
*
|
|
732
|
-
* @param text String to modify
|
|
733
|
-
* @param pos Position of the first character to modify
|
|
734
|
-
* @param count Length of the substring
|
|
735
|
-
* @returns `true` if `text` was changed
|
|
736
|
-
*
|
|
737
|
-
* NOTE: `pos` and `count` are measured in `wchar16`, not in codepoints.
|
|
738
|
-
*/
|
|
739
|
-
bool ToLower(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
|
|
740
|
-
bool ToUpper(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
|
|
741
|
-
|
|
742
|
-
/* Lowercase/uppercase given string inplace. Any alphabetic symbol will be converted to a proper
|
|
743
|
-
* case, the rest of the symbols will be kept the same. It is expected that `text` is a correct
|
|
744
|
-
* UTF-32 string.
|
|
745
|
-
*
|
|
746
|
-
* For example `ToLower("heLLo")` will return `"hello"`.
|
|
747
|
-
*
|
|
748
|
-
* @param text String to modify
|
|
749
|
-
* @param pos Position of the first character to modify
|
|
750
|
-
* @param count Length of the substring
|
|
751
|
-
* @returns `true` if `text` was changed
|
|
752
|
-
*
|
|
753
|
-
* NOTE: `pos` and `count` are measured in `wchar16`, not in codepoints.
|
|
754
|
-
*/
|
|
755
|
-
bool ToLower(TUtf32String& /*text*/, size_t /*pos*/ = 0, size_t /*count*/ = TUtf16String::npos);
|
|
756
|
-
bool ToUpper(TUtf32String& /*text*/, size_t /*pos*/ = 0, size_t /*count*/ = TUtf16String::npos);
|
|
757
|
-
|
|
758
|
-
/* Titlecase first symbol and lowercase the rest, see `ToLower` for more details.
|
|
759
|
-
*/
|
|
760
|
-
bool ToTitle(TUtf16String& text, size_t pos = 0, size_t count = TUtf16String::npos);
|
|
761
|
-
|
|
762
|
-
/* Titlecase first symbol and lowercase the rest, see `ToLower` for more details.
|
|
763
|
-
*/
|
|
764
|
-
bool ToTitle(TUtf32String& /*text*/, size_t /*pos*/ = 0, size_t /*count*/ = TUtf16String::npos);
|
|
765
|
-
|
|
766
|
-
/* @param text Pointer to the string to modify
|
|
767
|
-
* @param length Length of the string to modify
|
|
768
|
-
* @param out Pointer to the character array to write to
|
|
769
|
-
*
|
|
770
|
-
* NOTE: [text, text+length) and [out, out+length) should not interleave.
|
|
771
|
-
*
|
|
772
|
-
* TODO(yazevnul): replace these functions with `bool(const TWtringBuf, const TArrayRef<wchar16>)`
|
|
773
|
-
* overload.
|
|
774
|
-
*/
|
|
775
|
-
bool ToLower(const wchar16* text, size_t length, wchar16* out) noexcept;
|
|
776
|
-
bool ToUpper(const wchar16* text, size_t length, wchar16* out) noexcept;
|
|
777
|
-
bool ToTitle(const wchar16* text, size_t length, wchar16* out) noexcept;
|
|
778
|
-
|
|
779
|
-
bool ToLower(const wchar32* text, size_t length, wchar32* out) noexcept;
|
|
780
|
-
bool ToUpper(const wchar32* text, size_t length, wchar32* out) noexcept;
|
|
781
|
-
bool ToTitle(const wchar32* text, size_t length, wchar32* out) noexcept;
|
|
782
|
-
|
|
783
|
-
/* @param text Pointer to the string to modify
|
|
784
|
-
* @param length Length of the string to modify
|
|
785
|
-
*
|
|
786
|
-
* TODO(yazevnul): replace these functions with `bool(const TArrayRef<wchar16>)` overload.
|
|
787
|
-
*/
|
|
788
|
-
bool ToLower(wchar16* text, size_t length) noexcept;
|
|
789
|
-
bool ToUpper(wchar16* text, size_t length) noexcept;
|
|
790
|
-
bool ToTitle(wchar16* text, size_t length) noexcept;
|
|
791
|
-
|
|
792
|
-
bool ToLower(wchar32* text, size_t length) noexcept;
|
|
793
|
-
bool ToUpper(wchar32* text, size_t length) noexcept;
|
|
794
|
-
bool ToTitle(wchar32* text, size_t length) noexcept;
|
|
795
|
-
|
|
796
|
-
/* Convenience wrappers for `ToLower`, `ToUpper` and `ToTitle`.
|
|
797
|
-
*/
|
|
798
|
-
TUtf16String ToLowerRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
|
|
799
|
-
TUtf16String ToUpperRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
|
|
800
|
-
TUtf16String ToTitleRet(TUtf16String text, size_t pos = 0, size_t count = TUtf16String::npos) Y_WARN_UNUSED_RESULT;
|
|
801
|
-
|
|
802
|
-
TUtf16String ToLowerRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
|
|
803
|
-
TUtf16String ToUpperRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
|
|
804
|
-
TUtf16String ToTitleRet(const TWtringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
|
|
805
|
-
|
|
806
|
-
TUtf32String ToLowerRet(const TUtf32StringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
|
|
807
|
-
TUtf32String ToUpperRet(const TUtf32StringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
|
|
808
|
-
TUtf32String ToTitleRet(const TUtf32StringBuf text, size_t pos = 0, size_t count = TWtringBuf::npos) Y_WARN_UNUSED_RESULT;
|
|
809
|
-
|
|
810
|
-
//! replaces the '<', '>' and '&' characters in string with '<', '>' and '&' respectively
|
|
811
|
-
// insertBr=true - replace '\r' and '\n' with "<BR>"
|
|
812
|
-
template <bool insertBr>
|
|
813
|
-
void EscapeHtmlChars(TUtf16String& str);
|
|
814
|
-
|
|
815
|
-
//! returns number of characters in range. Handle surrogate pairs as one character.
|
|
816
|
-
inline size_t CountWideChars(const wchar16* b, const wchar16* e) {
|
|
817
|
-
size_t count = 0;
|
|
818
|
-
Y_ENSURE(b <= e, TStringBuf("invalid iterators"));
|
|
819
|
-
while (b < e) {
|
|
820
|
-
b = SkipSymbol(b, e);
|
|
821
|
-
++count;
|
|
822
|
-
}
|
|
823
|
-
return count;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
inline size_t CountWideChars(const TWtringBuf str) {
|
|
827
|
-
return CountWideChars(str.begin(), str.end());
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
//! checks whether the range is valid UTF-16 sequence
|
|
831
|
-
inline bool IsValidUTF16(const wchar16* b, const wchar16* e) {
|
|
832
|
-
Y_ENSURE(b <= e, TStringBuf("invalid iterators"));
|
|
833
|
-
while (b < e) {
|
|
834
|
-
wchar32 symbol = ReadSymbolAndAdvance(b, e);
|
|
835
|
-
if (symbol == BROKEN_RUNE)
|
|
836
|
-
return false;
|
|
837
|
-
}
|
|
838
|
-
return true;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
inline bool IsValidUTF16(const TWtringBuf str) {
|
|
842
|
-
return IsValidUTF16(str.begin(), str.end());
|
|
843
|
-
}
|