| 2422 | } |
| 2423 | |
| 2424 | FORCE_INLINE |
| 2425 | const char* binary_string(gdv_int64 context, const char* text, gdv_int32 text_len, |
| 2426 | gdv_int32* out_len) { |
| 2427 | if (text_len == 0) { |
| 2428 | *out_len = 0; |
| 2429 | return ""; |
| 2430 | } |
| 2431 | |
| 2432 | gdv_binary ret = |
| 2433 | reinterpret_cast<gdv_binary>(gdv_fn_context_arena_malloc(context, text_len)); |
| 2434 | |
| 2435 | if (ret == nullptr) { |
| 2436 | gdv_fn_context_set_error_msg(context, "Could not allocate memory for output string"); |
| 2437 | *out_len = 0; |
| 2438 | return ""; |
| 2439 | } |
| 2440 | |
| 2441 | // converting hex encoded string to normal string |
| 2442 | int j = 0; |
| 2443 | for (int i = 0; i < text_len; i++, j++) { |
| 2444 | if (text[i] == '\\' && i + 3 < text_len && |
| 2445 | (text[i + 1] == 'x' || text[i + 1] == 'X')) { |
| 2446 | char hd1 = text[i + 2]; |
| 2447 | char hd2 = text[i + 3]; |
| 2448 | if (isxdigit(static_cast<unsigned char>(hd1)) && |
| 2449 | isxdigit(static_cast<unsigned char>(hd2))) { |
| 2450 | // [a-fA-F0-9] |
| 2451 | ret[j] = to_binary_from_hex(hd1) * 16 + to_binary_from_hex(hd2); |
| 2452 | i += 3; |
| 2453 | } else { |
| 2454 | ret[j] = text[i]; |
| 2455 | } |
| 2456 | } else { |
| 2457 | ret[j] = text[i]; |
| 2458 | } |
| 2459 | } |
| 2460 | *out_len = j; |
| 2461 | return ret; |
| 2462 | } |
| 2463 | |
| 2464 | #define CAST_INT_BIGINT_VARBINARY(OUT_TYPE, TYPE_NAME) \ |
| 2465 | FORCE_INLINE \ |