| 3441 | */ |
| 3442 | |
| 3443 | String String::Simplified(UInt32 flags) const |
| 3444 | { |
| 3445 | if (m_sharedString->size == 0) |
| 3446 | return String(); |
| 3447 | |
| 3448 | auto newString = std::make_shared<SharedString>(m_sharedString->size); |
| 3449 | char* str = newString->string.get(); |
| 3450 | char* p = str; |
| 3451 | |
| 3452 | const char* ptr = m_sharedString->string.get(); |
| 3453 | bool inword = false; |
| 3454 | if (flags & HandleUtf8) |
| 3455 | { |
| 3456 | utf8::unchecked::iterator<const char*> it(ptr); |
| 3457 | do |
| 3458 | { |
| 3459 | if (Detail::IsSpace(*it)) |
| 3460 | { |
| 3461 | if (inword) |
| 3462 | { |
| 3463 | *p++ = ' '; |
| 3464 | inword = false; |
| 3465 | } |
| 3466 | } |
| 3467 | else |
| 3468 | { |
| 3469 | p = utf8::append(*it, p); |
| 3470 | inword = true; |
| 3471 | } |
| 3472 | } |
| 3473 | while (*++it); |
| 3474 | } |
| 3475 | else |
| 3476 | { |
| 3477 | const char* limit = &m_sharedString->string[m_sharedString->size]; |
| 3478 | do |
| 3479 | { |
| 3480 | if (Detail::IsSpace(*ptr)) |
| 3481 | { |
| 3482 | if (inword) |
| 3483 | { |
| 3484 | *p++ = ' '; |
| 3485 | inword = false; |
| 3486 | } |
| 3487 | } |
| 3488 | else |
| 3489 | { |
| 3490 | *p++ = *ptr; |
| 3491 | inword = true; |
| 3492 | } |
| 3493 | } |
| 3494 | while (++ptr != limit); |
| 3495 | } |
| 3496 | |
| 3497 | if (!inword && p != str) |
| 3498 | p--; |
| 3499 | |
| 3500 | *p = '\0'; |