Skip to content

Commit

Permalink
grep breaking on non-ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
kohnish committed Aug 17, 2023
1 parent 9fa9b42 commit a3cf7a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion native/app/json_msg_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
27 changes: 26 additions & 1 deletion native/app/test-vim9-fuzzy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,30 @@
#include "search_helper.h"
#include "vim9_fuzzy_env.h"
#include <gtest/gtest.h>
#include <string>

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]);
}

0 comments on commit a3cf7a6

Please sign in to comment.