| 492 | |
| 493 | template <typename F> |
| 494 | static TUtf16String ToSmthRet(const TWtringBuf text, size_t pos, size_t count, F&& f) { |
| 495 | pos = pos < text.size() ? pos : text.size(); |
| 496 | count = count < text.size() - pos ? count : text.size() - pos; |
| 497 | |
| 498 | auto res = TUtf16String::Uninitialized(text.size()); |
| 499 | auto* const resBegin = res.Detach(); |
| 500 | |
| 501 | if (pos) { |
| 502 | MemCopy(resBegin, text.data(), pos); |
| 503 | } |
| 504 | |
| 505 | f(text.data() + pos, count, resBegin + pos); |
| 506 | |
| 507 | if (count - pos != text.size()) { |
| 508 | MemCopy(resBegin + pos + count, text.data() + pos + count, text.size() - pos - count); |
| 509 | } |
| 510 | |
| 511 | return res; |
| 512 | } |
| 513 | |
| 514 | template <typename F> |
| 515 | static TUtf32String ToSmthRet(const TUtf32StringBuf text, size_t pos, size_t count, F&& f) { |