| 196 | |
| 197 | template <class TStringType, typename F> |
| 198 | static 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 | |
| 219 | bool ToLower(TUtf16String& text, size_t pos, size_t count) { |
| 220 | const auto f = [](const wchar32 s) { return ToLower(s); }; |
no test coverage detected