Search for a string within another string starting at position start-pos (1-indexed)
| 1880 | |
| 1881 | // Search for a string within another string starting at position start-pos (1-indexed) |
| 1882 | FORCE_INLINE |
| 1883 | gdv_int32 locate_utf8_utf8_int32(gdv_int64 context, const char* sub_str, |
| 1884 | gdv_int32 sub_str_len, const char* str, |
| 1885 | gdv_int32 str_len, gdv_int32 start_pos) { |
| 1886 | if (start_pos < 1) { |
| 1887 | char err_msg[96]; |
| 1888 | snprintf(err_msg, sizeof(err_msg), |
| 1889 | "LOCATE: Start position must be greater than 0, got %d", start_pos); |
| 1890 | gdv_fn_context_set_error_msg(context, err_msg); |
| 1891 | return 0; |
| 1892 | } |
| 1893 | |
| 1894 | if (str_len == 0 || sub_str_len == 0) { |
| 1895 | return 0; |
| 1896 | } |
| 1897 | |
| 1898 | gdv_int32 byte_pos = utf8_byte_pos(context, str, str_len, start_pos - 1); |
| 1899 | if (byte_pos < 0 || byte_pos >= str_len) { |
| 1900 | return 0; |
| 1901 | } |
| 1902 | for (gdv_int32 i = byte_pos; i <= str_len - sub_str_len; ++i) { |
| 1903 | if (memcmp(str + i, sub_str, sub_str_len) == 0) { |
| 1904 | return utf8_length(context, str, i) + 1; |
| 1905 | } |
| 1906 | } |
| 1907 | return 0; |
| 1908 | } |
| 1909 | |
| 1910 | FORCE_INLINE |
| 1911 | const char* replace_with_max_len_utf8_utf8_utf8(gdv_int64 context, const char* text, |