From a3cf7a6dfb57925c7d16901a45f3e037c17ba9b2 Mon Sep 17 00:00:00 2001 From: kohnish Date: Thu, 17 Aug 2023 21:10:51 +0200 Subject: [PATCH] grep breaking on non-ascii --- native/app/json_msg_handler.c | 5 ++++- native/app/test-vim9-fuzzy.cxx | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/native/app/json_msg_handler.c b/native/app/json_msg_handler.c index 819d847..aa8a672 100644 --- a/native/app/json_msg_handler.c +++ b/native/app/json_msg_handler.c @@ -23,7 +23,10 @@ char *json_escape(const char *json, size_t len, size_t *result_len) { char *buf = malloc(len * 2); size_t counter = 0; for (size_t i = 0; i < len; i++) { - if (json[i] == '\n') { + // only ascii is supported + if ((json[i] & 192) >= 192) { + continue; + } else if (json[i] == '\n') { buf[counter] = '\\'; buf[++counter] = 'n'; } else if (json[i] == '\r') { diff --git a/native/app/test-vim9-fuzzy.cxx b/native/app/test-vim9-fuzzy.cxx index f4545a2..c47026d 100644 --- a/native/app/test-vim9-fuzzy.cxx +++ b/native/app/test-vim9-fuzzy.cxx @@ -3,5 +3,30 @@ #include "search_helper.h" #include "vim9_fuzzy_env.h" #include +#include -TEST(fuzzy, start_fuzzy_response) {} + +// const std::string g_test_str = std::string("aあiい"); +const char *s = "aあiい"; +// 2 bytes: 110xxxxx 10xxxxxx +// 192 +// 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx +// 4 bytes: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + +TEST(fuzzy, start_fuzzy_response) { + if ((s[1] & 192) >= 192) { + printf("two bytes\n"); + } + if ((s[1] & 224) >= 224) { + printf("three bytes\n"); + } + if ((s[1] & 240) >= 240) { + printf("four bytes \n"); + } + // printf("%02X\n", g_test_str.c_str()[0]); + // printf("%02X\n", g_test_str.c_str()[1]); + // printf("%02X\n", g_test_str.c_str()[2]); + // printf("%02X\n", g_test_str.c_str()[3]); + // printf("%02X\n", g_test_str.c_str()[4]); + // printf("%02X\n", g_test_str.c_str()[5]); +}