* @brief Break line into constituent words */
| 418 | * @brief Break line into constituent words |
| 419 | */ |
| 420 | std::vector<stringdiffs::word> |
| 421 | stringdiffs::BuildWordsArray(const String & str) const |
| 422 | { |
| 423 | std::vector<word> words = { word(0, -1, 0, 0) }; // dummy; |
| 424 | int i = 0, begin = 0; |
| 425 | ICUBreakIterator *pIterChar = ICUBreakIterator::getCharacterBreakIterator(reinterpret_cast<const UChar *>(str.c_str()), static_cast<int32_t>(str.length())); |
| 426 | |
| 427 | size_t sLen = str.length(); |
| 428 | assert(sLen < INT_MAX); |
| 429 | |
| 430 | if (str.empty()) |
| 431 | return words; |
| 432 | |
| 433 | int break_type = 0; |
| 434 | int prev_break_type = 0; |
| 435 | int iLen = static_cast<int>(sLen); |
| 436 | for (; i < iLen;) |
| 437 | { |
| 438 | break_type = dlword; |
| 439 | tchar_t ch = str[i]; |
| 440 | if (ch == '\r' || ch == '\n') |
| 441 | { |
| 442 | if (m_eol_mode == EOL_AS_SPACE) |
| 443 | break_type = dlspace; |
| 444 | else |
| 445 | break_type = dleol; |
| 446 | } |
| 447 | else if (isSafeWhitespace(ch)) |
| 448 | { |
| 449 | break_type = dlspace; |
| 450 | } |
| 451 | else if (isWordBreak(m_breakType, str.c_str(), i)) |
| 452 | { |
| 453 | break_type = dlbreak; |
| 454 | } |
| 455 | else if (m_ignore_numbers && tc::istdigit(ch)) |
| 456 | { |
| 457 | break_type = dlnumber; |
| 458 | } |
| 459 | if (i > 0 && (break_type != prev_break_type || break_type == dlbreak || (prev_break_type == dleol && !(str[i - 1] == '\r' && ch == '\n')))) |
| 460 | { |
| 461 | words.push_back(word(begin, i - 1, prev_break_type, Hash(str, begin, i - 1, 0))); |
| 462 | begin = i; |
| 463 | } |
| 464 | if (m_eol_mode == EOL_AS_SPACE && break_type == dlspace) |
| 465 | { |
| 466 | for (; i < iLen; i++) |
| 467 | { |
| 468 | tchar_t ch2 = str[i]; |
| 469 | if (ch2 != '\r' && ch2 != '\n' && !isSafeWhitespace(ch2)) |
| 470 | break; |
| 471 | } |
| 472 | pIterChar->preceding(i); |
| 473 | } |
| 474 | else |
| 475 | { |
| 476 | i = pIterChar->next(); |
| 477 | } |
nothing calls this directly
no test coverage detected