| 18 | |
| 19 | template <typename TTokenType> |
| 20 | static void GetLetterIndices(const TTokenType& token, TVector<ui32>* letterStartIndices) { |
| 21 | letterStartIndices->clear(); |
| 22 | const unsigned char* current = reinterpret_cast<const unsigned char*>(token.data()); |
| 23 | const ui32 tokenSize = token.size(); |
| 24 | const unsigned char* last = current + tokenSize; |
| 25 | ui32 i = 0; |
| 26 | while (i < tokenSize) { |
| 27 | letterStartIndices->push_back(i); |
| 28 | size_t length = 0; |
| 29 | auto recodeResult = GetUTF8CharLen(length, current, last); |
| 30 | if (recodeResult != RECODE_OK || length == 0) { |
| 31 | letterStartIndices->clear(); |
| 32 | return; |
| 33 | } |
| 34 | i += length; |
| 35 | current += length; |
| 36 | } |
| 37 | letterStartIndices->push_back(tokenSize); |
| 38 | } |
| 39 | |
| 40 | template <bool needToAddEndOfWordToken, typename TTokenType, typename TVisitor> |
| 41 | static void ApplyFuncToLetterNGramsImpl( |
no test coverage detected