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.
Files changed (289) hide show
  1. package/DEPLOYMENT.md +22 -15
  2. package/README.md +37 -27
  3. package/binding.gyp +5 -7
  4. package/build_scripts/bootstrap.js +2 -1
  5. package/build_scripts/out/build.js +46 -68
  6. package/build_scripts/out/build_model.js +1 -1
  7. package/build_scripts/out/{build_ya.js → build_native.js} +1 -1
  8. package/build_scripts/out/ci.js +5 -5
  9. package/build_scripts/out/config.js +32 -18
  10. package/build_scripts/out/install.js +5 -3
  11. package/build_scripts/out/package_prepublish.js +1 -1
  12. package/build_scripts/out/packaging.js +1 -19
  13. package/build_scripts/out/run_tests.js +1 -1
  14. package/build_scripts/out/test.js +8 -3
  15. package/config.json +18 -11
  16. package/inc/catboost/libs/model_interface/c_api.h +349 -3
  17. package/lib/catboost.d.ts +65 -21
  18. package/package.json +4 -4
  19. package/src/api_helpers.cpp +100 -24
  20. package/src/api_helpers.h +8 -7
  21. package/src/api_module.cpp +1 -2
  22. package/src/model.cpp +483 -83
  23. package/src/model.h +24 -9
  24. package/inc/contrib/libs/cxxsupp/system_stl/include/stlfwd +0 -14
  25. package/inc/util/charset/recode_result.h +0 -9
  26. package/inc/util/charset/unicode_table.h +0 -123
  27. package/inc/util/charset/unidata.h +0 -421
  28. package/inc/util/charset/utf8.h +0 -384
  29. package/inc/util/charset/wide.h +0 -843
  30. package/inc/util/charset/wide_specific.h +0 -22
  31. package/inc/util/datetime/base.h +0 -669
  32. package/inc/util/datetime/constants.h +0 -7
  33. package/inc/util/datetime/cputimer.h +0 -124
  34. package/inc/util/datetime/parser.h +0 -292
  35. package/inc/util/datetime/systime.h +0 -47
  36. package/inc/util/datetime/uptime.h +0 -8
  37. package/inc/util/digest/city.h +0 -88
  38. package/inc/util/digest/fnv.h +0 -73
  39. package/inc/util/digest/multi.h +0 -14
  40. package/inc/util/digest/murmur.h +0 -57
  41. package/inc/util/digest/numeric.h +0 -86
  42. package/inc/util/digest/sequence.h +0 -48
  43. package/inc/util/draft/date.h +0 -129
  44. package/inc/util/draft/datetime.h +0 -184
  45. package/inc/util/draft/enum.h +0 -136
  46. package/inc/util/draft/holder_vector.h +0 -102
  47. package/inc/util/draft/ip.h +0 -131
  48. package/inc/util/draft/matrix.h +0 -108
  49. package/inc/util/draft/memory.h +0 -40
  50. package/inc/util/folder/dirent_win.h +0 -46
  51. package/inc/util/folder/dirut.h +0 -121
  52. package/inc/util/folder/filelist.h +0 -81
  53. package/inc/util/folder/fts.h +0 -108
  54. package/inc/util/folder/iterator.h +0 -109
  55. package/inc/util/folder/lstat_win.h +0 -20
  56. package/inc/util/folder/path.h +0 -225
  57. package/inc/util/folder/pathsplit.h +0 -113
  58. package/inc/util/folder/tempdir.h +0 -42
  59. package/inc/util/generic/adaptor.h +0 -134
  60. package/inc/util/generic/algorithm.h +0 -765
  61. package/inc/util/generic/array_ref.h +0 -282
  62. package/inc/util/generic/array_size.h +0 -24
  63. package/inc/util/generic/benchmark/vector_count_ctor/f.h +0 -9
  64. package/inc/util/generic/bitmap.h +0 -1115
  65. package/inc/util/generic/bitops.h +0 -459
  66. package/inc/util/generic/bt_exception.h +0 -24
  67. package/inc/util/generic/buffer.h +0 -232
  68. package/inc/util/generic/cast.h +0 -176
  69. package/inc/util/generic/deque.h +0 -24
  70. package/inc/util/generic/explicit_type.h +0 -42
  71. package/inc/util/generic/fastqueue.h +0 -55
  72. package/inc/util/generic/flags.h +0 -244
  73. package/inc/util/generic/function.h +0 -103
  74. package/inc/util/generic/fwd.h +0 -171
  75. package/inc/util/generic/guid.h +0 -61
  76. package/inc/util/generic/hash.h +0 -2032
  77. package/inc/util/generic/hash_primes.h +0 -140
  78. package/inc/util/generic/hash_set.h +0 -490
  79. package/inc/util/generic/hide_ptr.h +0 -3
  80. package/inc/util/generic/intrlist.h +0 -876
  81. package/inc/util/generic/is_in.h +0 -53
  82. package/inc/util/generic/iterator.h +0 -137
  83. package/inc/util/generic/iterator_range.h +0 -105
  84. package/inc/util/generic/lazy_value.h +0 -66
  85. package/inc/util/generic/list.h +0 -22
  86. package/inc/util/generic/map.h +0 -44
  87. package/inc/util/generic/mapfindptr.h +0 -60
  88. package/inc/util/generic/maybe.h +0 -713
  89. package/inc/util/generic/maybe_traits.h +0 -164
  90. package/inc/util/generic/mem_copy.h +0 -55
  91. package/inc/util/generic/noncopyable.h +0 -38
  92. package/inc/util/generic/object_counter.h +0 -53
  93. package/inc/util/generic/ptr.h +0 -1113
  94. package/inc/util/generic/queue.h +0 -57
  95. package/inc/util/generic/refcount.h +0 -162
  96. package/inc/util/generic/reserve.h +0 -11
  97. package/inc/util/generic/scope.h +0 -65
  98. package/inc/util/generic/serialized_enum.h +0 -406
  99. package/inc/util/generic/set.h +0 -42
  100. package/inc/util/generic/singleton.h +0 -136
  101. package/inc/util/generic/size_literals.h +0 -65
  102. package/inc/util/generic/stack.h +0 -18
  103. package/inc/util/generic/store_policy.h +0 -120
  104. package/inc/util/generic/strbase.h +0 -612
  105. package/inc/util/generic/strbuf.h +0 -552
  106. package/inc/util/generic/strfcpy.h +0 -17
  107. package/inc/util/generic/string.h +0 -1572
  108. package/inc/util/generic/string_hash.h +0 -21
  109. package/inc/util/generic/string_ut.h +0 -1175
  110. package/inc/util/generic/type_name.h +0 -34
  111. package/inc/util/generic/typelist.h +0 -114
  112. package/inc/util/generic/typetraits.h +0 -325
  113. package/inc/util/generic/utility.h +0 -132
  114. package/inc/util/generic/va_args.h +0 -400
  115. package/inc/util/generic/variant.h +0 -631
  116. package/inc/util/generic/variant_traits.h +0 -171
  117. package/inc/util/generic/vector.h +0 -119
  118. package/inc/util/generic/xrange.h +0 -258
  119. package/inc/util/generic/yexception.h +0 -212
  120. package/inc/util/generic/yexception_ut.h +0 -14
  121. package/inc/util/generic/ylimits.h +0 -92
  122. package/inc/util/generic/ymath.h +0 -206
  123. package/inc/util/memory/addstorage.h +0 -93
  124. package/inc/util/memory/alloc.h +0 -27
  125. package/inc/util/memory/blob.h +0 -296
  126. package/inc/util/memory/mmapalloc.h +0 -8
  127. package/inc/util/memory/pool.h +0 -432
  128. package/inc/util/memory/segmented_string_pool.h +0 -194
  129. package/inc/util/memory/segpool_alloc.h +0 -118
  130. package/inc/util/memory/smallobj.h +0 -141
  131. package/inc/util/memory/tempbuf.h +0 -111
  132. package/inc/util/network/address.h +0 -136
  133. package/inc/util/network/endpoint.h +0 -61
  134. package/inc/util/network/hostip.h +0 -16
  135. package/inc/util/network/init.h +0 -60
  136. package/inc/util/network/interface.h +0 -17
  137. package/inc/util/network/iovec.h +0 -65
  138. package/inc/util/network/ip.h +0 -116
  139. package/inc/util/network/nonblock.h +0 -8
  140. package/inc/util/network/pair.h +0 -9
  141. package/inc/util/network/poller.h +0 -58
  142. package/inc/util/network/pollerimpl.h +0 -707
  143. package/inc/util/network/sock.h +0 -608
  144. package/inc/util/network/socket.h +0 -421
  145. package/inc/util/random/common_ops.h +0 -130
  146. package/inc/util/random/easy.h +0 -47
  147. package/inc/util/random/entropy.h +0 -21
  148. package/inc/util/random/fast.h +0 -101
  149. package/inc/util/random/init_atfork.h +0 -3
  150. package/inc/util/random/lcg_engine.h +0 -66
  151. package/inc/util/random/mersenne.h +0 -46
  152. package/inc/util/random/mersenne32.h +0 -50
  153. package/inc/util/random/mersenne64.h +0 -50
  154. package/inc/util/random/normal.h +0 -38
  155. package/inc/util/random/random.h +0 -30
  156. package/inc/util/random/shuffle.h +0 -39
  157. package/inc/util/str_stl.h +0 -266
  158. package/inc/util/stream/aligned.h +0 -99
  159. package/inc/util/stream/buffer.h +0 -119
  160. package/inc/util/stream/buffered.h +0 -225
  161. package/inc/util/stream/debug.h +0 -53
  162. package/inc/util/stream/direct_io.h +0 -43
  163. package/inc/util/stream/file.h +0 -108
  164. package/inc/util/stream/format.h +0 -444
  165. package/inc/util/stream/fwd.h +0 -100
  166. package/inc/util/stream/hex.h +0 -8
  167. package/inc/util/stream/holder.h +0 -44
  168. package/inc/util/stream/input.h +0 -273
  169. package/inc/util/stream/labeled.h +0 -19
  170. package/inc/util/stream/length.h +0 -100
  171. package/inc/util/stream/mem.h +0 -255
  172. package/inc/util/stream/multi.h +0 -32
  173. package/inc/util/stream/null.h +0 -61
  174. package/inc/util/stream/output.h +0 -304
  175. package/inc/util/stream/pipe.h +0 -112
  176. package/inc/util/stream/printf.h +0 -25
  177. package/inc/util/stream/str.h +0 -207
  178. package/inc/util/stream/tee.h +0 -28
  179. package/inc/util/stream/tempbuf.h +0 -21
  180. package/inc/util/stream/tokenizer.h +0 -214
  181. package/inc/util/stream/trace.h +0 -60
  182. package/inc/util/stream/walk.h +0 -35
  183. package/inc/util/stream/zerocopy.h +0 -91
  184. package/inc/util/stream/zerocopy_output.h +0 -57
  185. package/inc/util/stream/zlib.h +0 -173
  186. package/inc/util/string/ascii.h +0 -236
  187. package/inc/util/string/builder.h +0 -39
  188. package/inc/util/string/cast.h +0 -347
  189. package/inc/util/string/cstriter.h +0 -14
  190. package/inc/util/string/escape.h +0 -70
  191. package/inc/util/string/hex.h +0 -59
  192. package/inc/util/string/join.h +0 -194
  193. package/inc/util/string/printf.h +0 -13
  194. package/inc/util/string/reverse.h +0 -16
  195. package/inc/util/string/split.h +0 -1080
  196. package/inc/util/string/strip.h +0 -257
  197. package/inc/util/string/strspn.h +0 -65
  198. package/inc/util/string/subst.h +0 -56
  199. package/inc/util/string/type.h +0 -50
  200. package/inc/util/string/util.h +0 -195
  201. package/inc/util/string/vector.h +0 -132
  202. package/inc/util/system/align.h +0 -50
  203. package/inc/util/system/atexit.h +0 -22
  204. package/inc/util/system/atomic.h +0 -51
  205. package/inc/util/system/atomic_gcc.h +0 -90
  206. package/inc/util/system/atomic_ops.h +0 -189
  207. package/inc/util/system/atomic_win.h +0 -114
  208. package/inc/util/system/backtrace.h +0 -39
  209. package/inc/util/system/byteorder.h +0 -186
  210. package/inc/util/system/compat.h +0 -84
  211. package/inc/util/system/compiler.h +0 -620
  212. package/inc/util/system/condvar.h +0 -71
  213. package/inc/util/system/context.h +0 -181
  214. package/inc/util/system/context_aarch64.h +0 -8
  215. package/inc/util/system/context_i686.h +0 -9
  216. package/inc/util/system/context_x86.h +0 -12
  217. package/inc/util/system/context_x86_64.h +0 -7
  218. package/inc/util/system/cpu_id.h +0 -159
  219. package/inc/util/system/daemon.h +0 -28
  220. package/inc/util/system/datetime.h +0 -98
  221. package/inc/util/system/defaults.h +0 -149
  222. package/inc/util/system/demangle.h +0 -5
  223. package/inc/util/system/demangle_impl.h +0 -23
  224. package/inc/util/system/direct_io.h +0 -71
  225. package/inc/util/system/dynlib.h +0 -119
  226. package/inc/util/system/env.h +0 -32
  227. package/inc/util/system/error.h +0 -95
  228. package/inc/util/system/event.h +0 -122
  229. package/inc/util/system/execpath.h +0 -17
  230. package/inc/util/system/fasttime.h +0 -6
  231. package/inc/util/system/fhandle.h +0 -27
  232. package/inc/util/system/file.h +0 -210
  233. package/inc/util/system/file_lock.h +0 -34
  234. package/inc/util/system/filemap.h +0 -383
  235. package/inc/util/system/flock.h +0 -35
  236. package/inc/util/system/fs.h +0 -156
  237. package/inc/util/system/fs_win.h +0 -29
  238. package/inc/util/system/fstat.h +0 -46
  239. package/inc/util/system/getpid.h +0 -12
  240. package/inc/util/system/guard.h +0 -179
  241. package/inc/util/system/hi_lo.h +0 -139
  242. package/inc/util/system/hostname.h +0 -10
  243. package/inc/util/system/hp_timer.h +0 -36
  244. package/inc/util/system/info.h +0 -12
  245. package/inc/util/system/interrupt_signals.h +0 -22
  246. package/inc/util/system/madvise.h +0 -30
  247. package/inc/util/system/maxlen.h +0 -32
  248. package/inc/util/system/mem_info.h +0 -18
  249. package/inc/util/system/mincore.h +0 -38
  250. package/inc/util/system/mktemp.h +0 -11
  251. package/inc/util/system/mlock.h +0 -43
  252. package/inc/util/system/mutex.h +0 -67
  253. package/inc/util/system/nice.h +0 -3
  254. package/inc/util/system/pipe.h +0 -90
  255. package/inc/util/system/platform.h +0 -246
  256. package/inc/util/system/progname.h +0 -13
  257. package/inc/util/system/protect.h +0 -25
  258. package/inc/util/system/rusage.h +0 -26
  259. package/inc/util/system/rwlock.h +0 -78
  260. package/inc/util/system/sanitizers.h +0 -122
  261. package/inc/util/system/sem.h +0 -41
  262. package/inc/util/system/shellcommand.h +0 -472
  263. package/inc/util/system/shmat.h +0 -32
  264. package/inc/util/system/sigset.h +0 -78
  265. package/inc/util/system/spin_wait.h +0 -10
  266. package/inc/util/system/spinlock.h +0 -121
  267. package/inc/util/system/src_location.h +0 -25
  268. package/inc/util/system/src_root.h +0 -68
  269. package/inc/util/system/sys_alloc.h +0 -43
  270. package/inc/util/system/sysstat.h +0 -52
  271. package/inc/util/system/tempfile.h +0 -34
  272. package/inc/util/system/thread.h +0 -167
  273. package/inc/util/system/tls.h +0 -307
  274. package/inc/util/system/types.h +0 -119
  275. package/inc/util/system/unaligned_mem.h +0 -67
  276. package/inc/util/system/user.h +0 -5
  277. package/inc/util/system/utime.h +0 -6
  278. package/inc/util/system/valgrind.h +0 -48
  279. package/inc/util/system/winint.h +0 -43
  280. package/inc/util/system/yassert.h +0 -121
  281. package/inc/util/system/yield.h +0 -4
  282. package/inc/util/thread/factory.h +0 -65
  283. package/inc/util/thread/fwd.h +0 -30
  284. package/inc/util/thread/lfqueue.h +0 -406
  285. package/inc/util/thread/lfstack.h +0 -188
  286. package/inc/util/thread/pool.h +0 -388
  287. package/inc/util/thread/singleton.h +0 -42
  288. package/inc/util/ysafeptr.h +0 -427
  289. package/inc/util/ysaveload.h +0 -700
@@ -1,612 +0,0 @@
1
- #pragma once
2
-
3
- // Some of these includes are just a legacy from previous implementation.
4
- // We don't need them here, but removing them is tricky because it breaks all
5
- // kinds of builds downstream
6
- #include "mem_copy.h"
7
- #include "ptr.h"
8
- #include "utility.h"
9
-
10
- #include <util/charset/unidata.h>
11
- #include <util/system/platform.h>
12
- #include <util/system/yassert.h>
13
-
14
- #include <contrib/libs/libc_compat/string.h>
15
-
16
- #include <cctype>
17
- #include <cstring>
18
- #include <string>
19
- #include <string_view>
20
-
21
-
22
- namespace NStringPrivate {
23
- template <class TCharType>
24
- size_t GetStringLengthWithLimit(const TCharType* s, size_t maxlen) {
25
- Y_ASSERT(s);
26
- size_t i = 0;
27
- for (; i != maxlen && s[i]; ++i)
28
- ;
29
- return i;
30
- }
31
-
32
- inline size_t GetStringLengthWithLimit(const char* s, size_t maxlen) {
33
- Y_ASSERT(s);
34
- return strnlen(s, maxlen);
35
- }
36
- }
37
-
38
- template <typename TDerived, typename TCharType, typename TTraitsType = std::char_traits<TCharType>>
39
- class TStringBase {
40
- using TStringView = std::basic_string_view<TCharType>;
41
- using TStringViewWithTraits = std::basic_string_view<TCharType, TTraitsType>;
42
-
43
- public:
44
- using TChar = TCharType;
45
- using TTraits = TTraitsType;
46
- using TSelf = TStringBase<TDerived, TChar, TTraits>;
47
-
48
- using size_type = size_t;
49
- using difference_type = ptrdiff_t;
50
- static constexpr size_t npos = size_t(-1);
51
-
52
- using const_iterator = const TCharType*;
53
- using const_reference = const TCharType&;
54
-
55
- template <typename TBase>
56
- struct TReverseIteratorBase {
57
- constexpr TReverseIteratorBase() noexcept = default;
58
- explicit constexpr TReverseIteratorBase(TBase p)
59
- : P_(p)
60
- {
61
- }
62
-
63
- TReverseIteratorBase operator++() noexcept {
64
- --P_;
65
- return *this;
66
- }
67
-
68
- TReverseIteratorBase operator++(int) noexcept {
69
- TReverseIteratorBase old(*this);
70
- --P_;
71
- return old;
72
- }
73
-
74
- TReverseIteratorBase& operator--() noexcept {
75
- ++P_;
76
- return *this;
77
- }
78
-
79
- TReverseIteratorBase operator--(int) noexcept {
80
- TReverseIteratorBase old(*this);
81
- ++P_;
82
- return old;
83
- }
84
-
85
- constexpr auto operator*() const noexcept -> std::remove_pointer_t<TBase>& {
86
- return *TBase(*this);
87
- }
88
-
89
- explicit constexpr operator TBase() const noexcept {
90
- return TBase(P_ - 1);
91
- }
92
-
93
- constexpr auto operator-(const TReverseIteratorBase o) const noexcept {
94
- return o.P_ - P_;
95
- }
96
-
97
- constexpr bool operator==(const TReverseIteratorBase o) const noexcept {
98
- return P_ == o.P_;
99
- }
100
-
101
- constexpr bool operator!=(const TReverseIteratorBase o) const noexcept {
102
- return !(*this == o);
103
- }
104
-
105
- private:
106
- TBase P_ = nullptr;
107
- };
108
- using const_reverse_iterator = TReverseIteratorBase<const_iterator>;
109
-
110
- _LIBCPP_CONSTEXPR_AFTER_CXX14
111
- static inline size_t StrLen(const TCharType* s) noexcept {
112
- if (Y_LIKELY(s)) {
113
- return TTraits::length(s);
114
- }
115
- return 0;
116
- }
117
-
118
- template <class TCharTraits>
119
- inline constexpr operator std::basic_string_view<TCharType, TCharTraits>() const {
120
- return std::basic_string_view<TCharType, TCharTraits>(data(), size());
121
- }
122
-
123
- template <class TCharTraits, class Allocator>
124
- inline explicit operator std::basic_string<TCharType, TCharTraits, Allocator>() const {
125
- return std::basic_string<TCharType, TCharTraits, Allocator>(Ptr(), Len());
126
- }
127
-
128
- /**
129
- * @param Pointer to character inside the string, or nullptr.
130
- * @return Offset from string beginning (in chars), or npos on nullptr.
131
- */
132
- inline size_t off(const TCharType* ret) const noexcept {
133
- return ret ? (size_t)(ret - Ptr()) : npos;
134
- }
135
-
136
- inline size_t IterOff(const_iterator it) const noexcept {
137
- return begin() <= it && end() > it ? size_t(it - begin()) : npos;
138
- }
139
-
140
- inline const_iterator begin() const noexcept {
141
- return Ptr();
142
- }
143
-
144
- inline const_iterator end() const noexcept {
145
- return Ptr() + size();
146
- }
147
-
148
- inline const_iterator cbegin() const noexcept {
149
- return begin();
150
- }
151
-
152
- inline const_iterator cend() const noexcept {
153
- return end();
154
- }
155
-
156
- inline const_reverse_iterator rbegin() const noexcept {
157
- return const_reverse_iterator(Ptr() + size());
158
- }
159
-
160
- inline const_reverse_iterator rend() const noexcept {
161
- return const_reverse_iterator(Ptr());
162
- }
163
-
164
- inline const_reverse_iterator crbegin() const noexcept {
165
- return rbegin();
166
- }
167
-
168
- inline const_reverse_iterator crend() const noexcept {
169
- return rend();
170
- }
171
-
172
- inline TCharType back() const noexcept {
173
- Y_ASSERT(!this->empty());
174
- return Ptr()[Len() - 1];
175
- }
176
-
177
- inline TCharType front() const noexcept {
178
- Y_ASSERT(!empty());
179
- return Ptr()[0];
180
- }
181
-
182
- constexpr const TCharType* data() const noexcept {
183
- return Ptr();
184
- }
185
-
186
- constexpr inline size_t size() const noexcept {
187
- return Len();
188
- }
189
-
190
- constexpr inline bool is_null() const noexcept {
191
- return *Ptr() == 0;
192
- }
193
-
194
- Y_PURE_FUNCTION
195
- constexpr inline bool empty() const noexcept {
196
- return Len() == 0;
197
- }
198
-
199
- constexpr inline explicit operator bool() const noexcept {
200
- return !empty();
201
- }
202
-
203
- public: // style-guide compliant methods
204
- constexpr const TCharType* Data() const noexcept {
205
- return Ptr();
206
- }
207
-
208
- constexpr size_t Size() const noexcept {
209
- return Len();
210
- }
211
-
212
- Y_PURE_FUNCTION
213
- constexpr bool Empty() const noexcept {
214
- return 0 == Len();
215
- }
216
-
217
- private:
218
- static inline TStringView LegacySubString(const TStringView view, size_t p, size_t n) noexcept {
219
- p = Min(p, view.length());
220
- return view.substr(p, n);
221
- }
222
-
223
- public:
224
- // ~~~ Comparison ~~~ : FAMILY0(int, compare)
225
- static int compare(const TSelf& s1, const TSelf& s2) noexcept {
226
- return s1.AsStringView().compare(s2.AsStringView());
227
- }
228
-
229
- static int compare(const TCharType* p, const TSelf& s2) noexcept {
230
- TCharType null{0};
231
- return TStringViewWithTraits(p ? p : &null).compare(s2.AsStringView());
232
- }
233
-
234
- static int compare(const TSelf& s1, const TCharType* p) noexcept {
235
- TCharType null{0};
236
- return s1.AsStringView().compare(p ? p : &null);
237
- }
238
-
239
- static int compare(const TStringView s1, const TStringView s2) noexcept {
240
- return TStringViewWithTraits(s1.data(), s1.size()).compare(
241
- TStringViewWithTraits(s2.data(), s2.size()));
242
- }
243
-
244
- template <class T>
245
- inline int compare(const T& t) const noexcept {
246
- return compare(*this, t);
247
- }
248
-
249
- inline int compare(size_t p, size_t n, const TStringView t) const noexcept {
250
- return compare(LegacySubString(*this, p, n), t);
251
- }
252
-
253
- inline int compare(size_t p, size_t n, const TStringView t, size_t p1, size_t n1) const noexcept {
254
- return compare(LegacySubString(*this, p, n), LegacySubString(t, p1, n1));
255
- }
256
-
257
- inline int compare(size_t p, size_t n, const TStringView t, size_t n1) const noexcept {
258
- return compare(LegacySubString(*this, p, n), LegacySubString(t, 0, n1));
259
- }
260
-
261
- inline int compare(const TCharType* p, size_t len) const noexcept {
262
- return compare(*this, TStringView(p, len));
263
- }
264
-
265
- static bool equal(const TSelf& s1, const TSelf& s2) noexcept {
266
- return s1.AsStringView() == s2.AsStringView();
267
- }
268
-
269
- static bool equal(const TSelf& s1, const TCharType* p) noexcept {
270
- if (p == nullptr) {
271
- return s1.Len() == 0;
272
- }
273
-
274
- return s1.AsStringView() == p;
275
- }
276
-
277
- static bool equal(const TCharType* p, const TSelf& s2) noexcept {
278
- return equal(s2, p);
279
- }
280
-
281
- static bool equal(const TStringView s1, const TStringView s2) noexcept {
282
- return TStringViewWithTraits{s1.data(), s1.size()} == TStringViewWithTraits{s2.data(), s2.size()};
283
- }
284
-
285
- template <class T>
286
- inline bool equal(const T& t) const noexcept {
287
- return equal(*this, t);
288
- }
289
-
290
- inline bool equal(size_t p, size_t n, const TStringView t) const noexcept {
291
- return equal(LegacySubString(*this, p, n), t);
292
- }
293
-
294
- inline bool equal(size_t p, size_t n, const TStringView t, size_t p1, size_t n1) const noexcept {
295
- return equal(LegacySubString(*this, p, n), LegacySubString(t, p1, n1));
296
- }
297
-
298
- inline bool equal(size_t p, size_t n, const TStringView t, size_t n1) const noexcept {
299
- return equal(LegacySubString(*this, p, n), LegacySubString(t, 0, n1));
300
- }
301
-
302
- static inline bool StartsWith(const TCharType* what, size_t whatLen, const TCharType* with, size_t withLen) noexcept {
303
- return withLen <= whatLen && TStringViewWithTraits(what, withLen) == TStringViewWithTraits(with, withLen);
304
- }
305
-
306
- static inline bool EndsWith(const TCharType* what, size_t whatLen, const TCharType* with, size_t withLen) noexcept {
307
- return withLen <= whatLen && TStringViewWithTraits(what + whatLen - withLen, withLen) == TStringViewWithTraits(with, withLen);
308
- }
309
-
310
- inline bool StartsWith(const TCharType* s, size_t n) const noexcept {
311
- return StartsWith(Ptr(), Len(), s, n);
312
- }
313
-
314
- inline bool StartsWith(const TStringView s) const noexcept {
315
- return StartsWith(s.data(), s.length());
316
- }
317
-
318
- inline bool StartsWith(TCharType ch) const noexcept {
319
- return !empty() && TTraits::eq(*Ptr(), ch);
320
- }
321
-
322
- inline bool EndsWith(const TCharType* s, size_t n) const noexcept {
323
- return EndsWith(Ptr(), Len(), s, n);
324
- }
325
-
326
- inline bool EndsWith(const TStringView s) const noexcept {
327
- return EndsWith(s.data(), s.length());
328
- }
329
-
330
- inline bool EndsWith(TCharType ch) const noexcept {
331
- return !empty() && TTraits::eq(Ptr()[Len() - 1], ch);
332
- }
333
-
334
- template <typename TDerived2, typename TTraits2>
335
- bool operator==(const TStringBase<TDerived2, TChar, TTraits2>& s2) const noexcept {
336
- return equal(*this, s2);
337
- }
338
-
339
- bool operator==(TStringView s2) const noexcept {
340
- return equal(*this, s2);
341
- }
342
-
343
- bool operator==(const TCharType* pc) const noexcept {
344
- return equal(*this, pc);
345
- }
346
-
347
- #ifndef __cpp_impl_three_way_comparison
348
- friend bool operator==(const TCharType* pc, const TSelf& s) noexcept {
349
- return equal(pc, s);
350
- }
351
-
352
- template <typename TDerived2, typename TTraits2>
353
- friend bool operator!=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept {
354
- return !(s1 == s2);
355
- }
356
-
357
- friend bool operator!=(const TSelf& s1, TStringView s2) noexcept {
358
- return !(s1 == s2);
359
- }
360
-
361
- friend bool operator!=(const TSelf& s, const TCharType* pc) noexcept {
362
- return !(s == pc);
363
- }
364
-
365
- friend bool operator!=(const TCharType* pc, const TSelf& s) noexcept {
366
- return !(pc == s);
367
- }
368
- #endif
369
-
370
- template <typename TDerived2, typename TTraits2>
371
- friend bool operator<(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept {
372
- return compare(s1, s2) < 0;
373
- }
374
-
375
- friend bool operator<(const TSelf& s1, TStringView s2) noexcept {
376
- return compare(s1, s2) < 0;
377
- }
378
-
379
- friend bool operator<(const TSelf& s, const TCharType* pc) noexcept {
380
- return compare(s, pc) < 0;
381
- }
382
-
383
- friend bool operator<(const TCharType* pc, const TSelf& s) noexcept {
384
- return compare(pc, s) < 0;
385
- }
386
-
387
- template <typename TDerived2, typename TTraits2>
388
- friend bool operator<=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept {
389
- return compare(s1, s2) <= 0;
390
- }
391
-
392
- friend bool operator<=(const TSelf& s1, TStringView s2) noexcept {
393
- return compare(s1, s2) <= 0;
394
- }
395
-
396
- friend bool operator<=(const TSelf& s, const TCharType* pc) noexcept {
397
- return compare(s, pc) <= 0;
398
- }
399
-
400
- friend bool operator<=(const TCharType* pc, const TSelf& s) noexcept {
401
- return compare(pc, s) <= 0;
402
- }
403
-
404
- template <typename TDerived2, typename TTraits2>
405
- friend bool operator>(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept {
406
- return compare(s1, s2) > 0;
407
- }
408
-
409
- friend bool operator>(const TSelf& s1, TStringView s2) noexcept {
410
- return compare(s1, s2) > 0;
411
- }
412
-
413
- friend bool operator>(const TSelf& s, const TCharType* pc) noexcept {
414
- return compare(s, pc) > 0;
415
- }
416
-
417
- friend bool operator>(const TCharType* pc, const TSelf& s) noexcept {
418
- return compare(pc, s) > 0;
419
- }
420
-
421
- template <typename TDerived2, typename TTraits2>
422
- friend bool operator>=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept {
423
- return compare(s1, s2) >= 0;
424
- }
425
-
426
- friend bool operator>=(const TSelf& s1, TStringView s2) noexcept {
427
- return compare(s1, s2) >= 0;
428
- }
429
-
430
- friend bool operator>=(const TSelf& s, const TCharType* pc) noexcept {
431
- return compare(s, pc) >= 0;
432
- }
433
-
434
- friend bool operator>=(const TCharType* pc, const TSelf& s) noexcept {
435
- return compare(pc, s) >= 0;
436
- }
437
-
438
- // ~~ Read access ~~
439
- inline TCharType at(size_t pos) const noexcept {
440
- if (Y_LIKELY(pos < Len())) {
441
- return (Ptr())[pos];
442
- }
443
- return 0;
444
- }
445
-
446
- inline TCharType operator[](size_t pos) const noexcept {
447
- Y_ASSERT(pos < this->size());
448
-
449
- return Ptr()[pos];
450
- }
451
-
452
- //~~~~Search~~~~
453
- /**
454
- * @return Position of the substring inside this string, or `npos` if not found.
455
- */
456
- inline size_t find(const TStringView s, size_t pos = 0) const noexcept {
457
- return find(s.data(), pos, s.size());
458
- }
459
-
460
- inline size_t find(const TCharType* s, size_t pos, size_t count) const noexcept {
461
- return AsStringView().find(s, pos, count);
462
- }
463
-
464
- inline size_t find(TCharType c, size_t pos = 0) const noexcept {
465
- return AsStringView().find(c, pos);
466
- }
467
-
468
- inline size_t rfind(TCharType c) const noexcept {
469
- return AsStringView().rfind(c);
470
- }
471
-
472
- inline size_t rfind(TCharType c, size_t pos) const noexcept {
473
- if (pos == 0) {
474
- return npos;
475
- }
476
- return AsStringView().rfind(c, pos - 1);
477
- }
478
-
479
- inline size_t rfind(const TStringView str, size_t pos = npos) const {
480
- return AsStringView().rfind(str.data(), pos, str.size());
481
- }
482
-
483
- //~~~~Contains~~~~
484
- /**
485
- * @returns Whether this string contains the provided substring.
486
- */
487
- inline bool Contains(const TStringView s, size_t pos = 0) const noexcept {
488
- return !s.length() || find(s, pos) != npos;
489
- }
490
-
491
- inline bool Contains(TChar c, size_t pos = 0) const noexcept {
492
- return find(c, pos) != npos;
493
- }
494
-
495
- inline void Contains(std::enable_if<std::is_unsigned<TCharType>::value, char> c, size_t pos = 0) const noexcept {
496
- return find(ui8(c), pos) != npos;
497
- }
498
-
499
- //~~~~Character Set Search~~~
500
- inline size_t find_first_of(TCharType c) const noexcept {
501
- return find_first_of(c, 0);
502
- }
503
-
504
- inline size_t find_first_of(TCharType c, size_t pos) const noexcept {
505
- return find(c, pos);
506
- }
507
-
508
- inline size_t find_first_of(const TStringView set) const noexcept {
509
- return find_first_of(set, 0);
510
- }
511
-
512
- inline size_t find_first_of(const TStringView set, size_t pos) const noexcept {
513
- return AsStringView().find_first_of(set.data(), pos, set.size());
514
- }
515
-
516
- inline size_t find_first_not_of(TCharType c) const noexcept {
517
- return find_first_not_of(c, 0);
518
- }
519
-
520
- inline size_t find_first_not_of(TCharType c, size_t pos) const noexcept {
521
- return find_first_not_of(TStringView(&c, 1), pos);
522
- }
523
-
524
- inline size_t find_first_not_of(const TStringView set) const noexcept {
525
- return find_first_not_of(set, 0);
526
- }
527
-
528
- inline size_t find_first_not_of(const TStringView set, size_t pos) const noexcept {
529
- return AsStringView().find_first_not_of(set.data(), pos, set.size());
530
- }
531
-
532
- inline size_t find_last_of(TCharType c, size_t pos = npos) const noexcept {
533
- return find_last_of(&c, pos, 1);
534
- }
535
-
536
- inline size_t find_last_of(const TStringView set, size_t pos = npos) const noexcept {
537
- return find_last_of(set.data(), pos, set.length());
538
- }
539
-
540
- inline size_t find_last_of(const TCharType* set, size_t pos, size_t n) const noexcept {
541
- return AsStringView().find_last_of(set, pos, n);
542
- }
543
-
544
- inline size_t find_last_not_of(TCharType c, size_t pos = npos) const noexcept {
545
- return AsStringView().find_last_not_of(c, pos);
546
- }
547
-
548
- inline size_t find_last_not_of(const TStringView set, size_t pos = npos) const noexcept {
549
- return find_last_not_of(set.data(), pos, set.length());
550
- }
551
-
552
- inline size_t find_last_not_of(const TCharType* set, size_t pos, size_t n) const noexcept {
553
- return AsStringView().find_last_not_of(set, pos, n);
554
- }
555
-
556
- inline size_t copy(TCharType* pc, size_t n, size_t pos) const {
557
- if (pos > Len()) {
558
- throw std::out_of_range("TStringBase::copy");
559
- }
560
-
561
- return CopyImpl(pc, n, pos);
562
- }
563
-
564
- inline size_t copy(TCharType* pc, size_t n) const noexcept {
565
- return CopyImpl(pc, n, 0);
566
- }
567
-
568
- inline size_t strcpy(TCharType* pc, size_t n) const noexcept {
569
- if (n) {
570
- n = copy(pc, n - 1);
571
- pc[n] = 0;
572
- }
573
-
574
- return n;
575
- }
576
-
577
- inline TDerived copy() const Y_WARN_UNUSED_RESULT {
578
- return TDerived(Ptr(), Len());
579
- }
580
-
581
- // ~~~ Partial copy ~~~~
582
- TDerived substr(size_t pos, size_t n = npos) const Y_WARN_UNUSED_RESULT {
583
- return TDerived(*This(), pos, n);
584
- }
585
-
586
- private:
587
- using GenericFinder = const TCharType* (*)(const TCharType*, size_t, const TCharType*, size_t);
588
-
589
- TStringViewWithTraits AsStringView() const {
590
- return static_cast<TStringViewWithTraits>(*this);
591
- }
592
-
593
- constexpr inline const TCharType* Ptr() const noexcept {
594
- return This()->data();
595
- }
596
-
597
- constexpr inline size_t Len() const noexcept {
598
- return This()->length();
599
- }
600
-
601
- constexpr inline const TDerived* This() const noexcept {
602
- return static_cast<const TDerived*>(this);
603
- }
604
-
605
- inline size_t CopyImpl(TCharType* pc, size_t n, size_t pos) const noexcept {
606
- const size_t toCopy = Min(Len() - pos, n);
607
-
608
- TTraits::copy(pc, Ptr() + pos, toCopy);
609
-
610
- return toCopy;
611
- }
612
- };