| 3028 | } |
| 3029 | |
| 3030 | FORCE_INLINE |
| 3031 | const char* from_hex_utf8(int64_t context, const char* text, int32_t text_len, |
| 3032 | bool text_validity, bool* out_valid, int32_t* out_len) { |
| 3033 | if (text_len == 0) { |
| 3034 | *out_valid = true; |
| 3035 | *out_len = 0; |
| 3036 | return ""; |
| 3037 | } |
| 3038 | |
| 3039 | // the input string should have a length multiple of two and a true validity |
| 3040 | if (text_len % 2 != 0 || !text_validity) { |
| 3041 | *out_valid = false; |
| 3042 | *out_len = 0; |
| 3043 | return ""; |
| 3044 | } |
| 3045 | |
| 3046 | char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, text_len / 2)); |
| 3047 | |
| 3048 | if (ret == nullptr) { |
| 3049 | *out_valid = false; |
| 3050 | *out_len = 0; |
| 3051 | return ""; |
| 3052 | } |
| 3053 | |
| 3054 | // converting hex encoded string to normal string |
| 3055 | int32_t j = 0; |
| 3056 | for (int32_t i = 0; i < text_len; i += 2) { |
| 3057 | char b1 = text[i]; |
| 3058 | char b2 = text[i + 1]; |
| 3059 | if (isxdigit(static_cast<unsigned char>(b1)) && |
| 3060 | isxdigit(static_cast<unsigned char>(b2))) { |
| 3061 | // [a-fA-F0-9] |
| 3062 | ret[j++] = to_binary_from_hex(b1) * 16 + to_binary_from_hex(b2); |
| 3063 | } else { |
| 3064 | *out_valid = false; |
| 3065 | *out_len = 0; |
| 3066 | return ""; |
| 3067 | } |
| 3068 | } |
| 3069 | *out_valid = true; |
| 3070 | *out_len = j; |
| 3071 | return ret; |
| 3072 | } |
| 3073 | |
| 3074 | // Array that maps each letter from the alphabet to its corresponding number for the |
| 3075 | // soundex algorithm. ABCDEFGHIJKLMNOPQRSTUVWXYZ -> 01230120022455012623010202 |