MCPcopy Create free account
hub / github.com/apache/arrow / locate_utf8_utf8_int32

Function locate_utf8_utf8_int32

cpp/src/gandiva/precompiled/string_ops.cc:1848–1874  ·  view source on GitHub ↗

Search for a string within another string starting at position start-pos (1-indexed)

Source from the content-addressed store, hash-verified

1846
1847// Search for a string within another string starting at position start-pos (1-indexed)
1848FORCE_INLINE
1849gdv_int32 locate_utf8_utf8_int32(gdv_int64 context, const char* sub_str,
1850 gdv_int32 sub_str_len, const char* str,
1851 gdv_int32 str_len, gdv_int32 start_pos) {
1852 if (start_pos < 1) {
1853 char err_msg[96];
1854 snprintf(err_msg, sizeof(err_msg),
1855 "LOCATE: Start position must be greater than 0, got %d", start_pos);
1856 gdv_fn_context_set_error_msg(context, err_msg);
1857 return 0;
1858 }
1859
1860 if (str_len == 0 || sub_str_len == 0) {
1861 return 0;
1862 }
1863
1864 gdv_int32 byte_pos = utf8_byte_pos(context, str, str_len, start_pos - 1);
1865 if (byte_pos < 0 || byte_pos >= str_len) {
1866 return 0;
1867 }
1868 for (gdv_int32 i = byte_pos; i <= str_len - sub_str_len; ++i) {
1869 if (memcmp(str + i, sub_str, sub_str_len) == 0) {
1870 return utf8_length(context, str, i) + 1;
1871 }
1872 }
1873 return 0;
1874}
1875
1876FORCE_INLINE
1877const char* replace_with_max_len_utf8_utf8_utf8(gdv_int64 context, const char* text,

Callers 3

strpos_utf8_utf8Function · 0.85
locate_utf8_utf8Function · 0.85
TESTFunction · 0.85

Calls 3

utf8_byte_posFunction · 0.85
utf8_lengthFunction · 0.85

Tested by 1

TESTFunction · 0.68