Trim str by offsetting contents when there's leading data + writing a \0 at the trailing position. We use this in situation where the cost is negligible.
| 1715 | |
| 1716 | // Trim str by offsetting contents when there's leading data + writing a \0 at the trailing position. We use this in situation where the cost is negligible. |
| 1717 | void ImStrTrimBlanks(char* buf) |
| 1718 | { |
| 1719 | char* p = buf; |
| 1720 | while (p[0] == ' ' || p[0] == '\t') // Leading blanks |
| 1721 | p++; |
| 1722 | char* p_start = p; |
| 1723 | while (*p != 0) // Find end of string |
| 1724 | p++; |
| 1725 | while (p > p_start && (p[-1] == ' ' || p[-1] == '\t')) // Trailing blanks |
| 1726 | p--; |
| 1727 | if (p_start != buf) // Copy memory if we had leading blanks |
| 1728 | memmove(buf, p_start, p - p_start); |
| 1729 | buf[p - p_start] = 0; // Zero terminate |
| 1730 | } |
| 1731 | |
| 1732 | const char* ImStrSkipBlank(const char* str) |
| 1733 | { |