| 1797 | } |
| 1798 | |
| 1799 | const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end) |
| 1800 | { |
| 1801 | if (!needle_end) |
| 1802 | needle_end = needle + strlen(needle); |
| 1803 | |
| 1804 | const char un0 = (char)ImToUpper(*needle); |
| 1805 | while ((!haystack_end && *haystack) || (haystack_end && haystack < haystack_end)) |
| 1806 | { |
| 1807 | if (ImToUpper(*haystack) == un0) |
| 1808 | { |
| 1809 | const char* b = needle + 1; |
| 1810 | for (const char* a = haystack + 1; b < needle_end; a++, b++) |
| 1811 | if (ImToUpper(*a) != ImToUpper(*b)) |
| 1812 | break; |
| 1813 | if (b == needle_end) |
| 1814 | return haystack; |
| 1815 | } |
| 1816 | haystack++; |
| 1817 | } |
| 1818 | return NULL; |
| 1819 | } |
| 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) |