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.
| 1820 | |
| 1821 | // 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. |
| 1822 | void ImStrTrimBlanks(char* buf) |
| 1823 | { |
| 1824 | char* p = buf; |
| 1825 | while (p[0] == ' ' || p[0] == '\t') // Leading blanks |
| 1826 | p++; |
| 1827 | char* p_start = p; |
| 1828 | while (*p != 0) // Find end of string |
| 1829 | p++; |
| 1830 | while (p > p_start && (p[-1] == ' ' || p[-1] == '\t')) // Trailing blanks |
| 1831 | p--; |
| 1832 | if (p_start != buf) // Copy memory if we had leading blanks |
| 1833 | memmove(buf, p_start, p - p_start); |
| 1834 | buf[p - p_start] = 0; // Zero terminate |
| 1835 | } |
| 1836 | |
| 1837 | const char* ImStrSkipBlank(const char* str) |
| 1838 | { |