MCPcopy Create free account
hub / github.com/catboost/catboost / ModifyStringSymbolwise

Function ModifyStringSymbolwise

util/charset/wide.cpp:198–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196
197template <class TStringType, typename F>
198static bool ModifyStringSymbolwise(TStringType& text, size_t pos, size_t count, F&& f) {
199 // TODO(yazevnul): this is done for consistency with `TUtf16String::to_lower` and friends
200 // at r2914050, maybe worth replacing them with asserts. Also see the same code in `ToTitle`.
201 pos = pos < text.size() ? pos : text.size();
202 count = count < text.size() - pos ? count : text.size() - pos;
203
204 // TUtf16String is refcounted and it's `data` method return pointer to the constant memory.
205 // To simplify the code we do a `const_cast`, though first write to the memory will be done only
206 // after we call `Detach()` and get pointer to a writable piece of memory.
207 auto* p = const_cast<typename TStringType::value_type*>(text.data() + pos);
208 const auto* pe = text.data() + pos + count;
209
210 if (ModifySequence<true>(p, pe, f)) {
211 DetachAndFixPointers(text, p, pe);
212 ModifySequence<false>(p, pe, f);
213 return true;
214 }
215
216 return false;
217}
218
219bool ToLower(TUtf16String& text, size_t pos, size_t count) {
220 const auto f = [](const wchar32 s) { return ToLower(s); };

Callers 2

ToLowerFunction · 0.70
ToUpperFunction · 0.70

Calls 3

DetachAndFixPointersFunction · 0.70
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected