| 641 | } |
| 642 | |
| 643 | BString BString::trim() { |
| 644 | if (isEmpty()) { |
| 645 | return *this; |
| 646 | } |
| 647 | int startIndex = 0; |
| 648 | int len = length(); |
| 649 | int endIndex = len; |
| 650 | for (int i = 0; i < len; i++) { |
| 651 | if (std::isspace(data->str[i])) { |
| 652 | startIndex++; |
| 653 | } else { |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | for (int i = len - 1; i > startIndex; i--) { |
| 658 | if (std::isspace(data->str[i])) { |
| 659 | endIndex--; |
| 660 | } else { |
| 661 | break; |
| 662 | } |
| 663 | } |
| 664 | if (startIndex == 0 && endIndex == len) { |
| 665 | return *this; |
| 666 | } |
| 667 | makeWritable(0); |
| 668 | data->len = endIndex - startIndex; |
| 669 | if (startIndex) { |
| 670 | memmove(data->str, data->str + startIndex, data->len); |
| 671 | } |
| 672 | data->str[data->len] = 0; |
| 673 | return *this; |
| 674 | } |
| 675 | |
| 676 | BString BString::operator+(const BString& s) const { |
| 677 | if (isEmpty()) { |
no test coverage detected