| 728 | } |
| 729 | |
| 730 | String String::_separate_compound_words() const { |
| 731 | if (length() == 0) { |
| 732 | return *this; |
| 733 | } |
| 734 | |
| 735 | const char32_t *cstr = get_data(); |
| 736 | int start_index = 0; |
| 737 | String new_string; |
| 738 | |
| 739 | bool is_prev_upper = is_unicode_upper_case(cstr[0]); |
| 740 | bool is_prev_lower = is_unicode_lower_case(cstr[0]); |
| 741 | bool is_prev_digit = is_digit(cstr[0]); |
| 742 | |
| 743 | for (int i = 1; i < length(); i++) { |
| 744 | const bool is_curr_upper = is_unicode_upper_case(cstr[i]); |
| 745 | const bool is_curr_lower = is_unicode_lower_case(cstr[i]); |
| 746 | const bool is_curr_digit = is_digit(cstr[i]); |
| 747 | |
| 748 | bool is_next_lower = false; |
| 749 | if (i + 1 < length()) { |
| 750 | is_next_lower = is_unicode_lower_case(cstr[i + 1]); |
| 751 | } |
| 752 | |
| 753 | const bool cond_a = is_prev_lower && is_curr_upper; // aA |
| 754 | const bool cond_b = (is_prev_upper || is_prev_digit) && is_curr_upper && is_next_lower; // AAa, 2Aa |
| 755 | const bool cond_c = is_prev_digit && is_curr_lower && is_next_lower; // 2aa |
| 756 | const bool cond_d = (is_prev_upper || is_prev_lower) && is_curr_digit; // A2, a2 |
| 757 | |
| 758 | if (cond_a || cond_b || cond_c || cond_d) { |
| 759 | new_string += substr(start_index, i - start_index) + " "; |
| 760 | start_index = i; |
| 761 | } |
| 762 | |
| 763 | is_prev_upper = is_curr_upper; |
| 764 | is_prev_lower = is_curr_lower; |
| 765 | is_prev_digit = is_curr_digit; |
| 766 | } |
| 767 | |
| 768 | new_string += substr(start_index, size() - start_index); |
| 769 | |
| 770 | for (int i = 0; i < new_string.size(); i++) { |
| 771 | const bool whitespace = is_whitespace(new_string[i]); |
| 772 | const bool underscore = is_underscore(new_string[i]); |
| 773 | const bool hyphen = is_hyphen(new_string[i]); |
| 774 | |
| 775 | if (whitespace || underscore || hyphen) { |
| 776 | new_string[i] = ' '; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | return new_string.to_lower(); |
| 781 | } |
| 782 | |
| 783 | String String::capitalize() const { |
| 784 | String words = _separate_compound_words().strip_edges(); |
nothing calls this directly
no test coverage detected