Remove unneccesary dependancy
Signed-off-by: Syed Daanish <me@syedm.dev>
This commit is contained in:
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -2,7 +2,3 @@
|
|||||||
path = libs/libgrapheme
|
path = libs/libgrapheme
|
||||||
url = git://git.suckless.org/libgrapheme
|
url = git://git.suckless.org/libgrapheme
|
||||||
ignore = dirty
|
ignore = dirty
|
||||||
[submodule "libs/utfcpp"]
|
|
||||||
path = libs/utfcpp
|
|
||||||
url = https://github.com/nemtrif/utfcpp.git
|
|
||||||
ignore = dirty
|
|
||||||
|
|||||||
1
libs/utfcpp
vendored
1
libs/utfcpp
vendored
Submodule libs/utfcpp deleted from cfc9112cee
@@ -1,4 +1,3 @@
|
|||||||
#include "utfcpp/source/utf8.h"
|
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
|
|
||||||
int display_width(const char *str, size_t len) {
|
int display_width(const char *str, size_t len) {
|
||||||
@@ -99,42 +98,48 @@ uint32_t count_clusters(const char *line, size_t len, size_t from, size_t to) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t utf8_offset_to_utf16(const char *utf8, size_t utf8_len,
|
size_t utf8_offset_to_utf16(const char *s, size_t utf8_len, size_t byte_pos) {
|
||||||
size_t byte_offset) {
|
if (byte_pos > utf8_len)
|
||||||
if (byte_offset > utf8_len)
|
return 0;
|
||||||
return byte_offset;
|
size_t utf16_units = 0;
|
||||||
const char *start = utf8;
|
size_t i = 0;
|
||||||
const char *mid = utf8 + byte_offset;
|
while (i < byte_pos) {
|
||||||
if (!utf8::is_valid(start, mid))
|
unsigned char c = s[i];
|
||||||
assert(0 && "invalid utf8");
|
if ((c & 0x80) == 0x00) {
|
||||||
size_t utf16_offset = 0;
|
i += 1;
|
||||||
for (auto it = start; it < mid;) {
|
utf16_units += 1;
|
||||||
uint32_t codepoint = utf8::next(it, mid);
|
} else if ((c & 0xE0) == 0xC0) {
|
||||||
if (codepoint <= 0xFFFF)
|
i += 2;
|
||||||
utf16_offset += 1;
|
utf16_units += 1;
|
||||||
else
|
} else if ((c & 0xF0) == 0xE0) {
|
||||||
utf16_offset += 2;
|
i += 3;
|
||||||
|
utf16_units += 1;
|
||||||
|
} else {
|
||||||
|
i += 4;
|
||||||
|
utf16_units += 2;
|
||||||
}
|
}
|
||||||
return utf16_offset;
|
}
|
||||||
|
return utf16_units;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t utf16_offset_to_utf8(const char *utf8, size_t utf8_len,
|
size_t utf16_offset_to_utf8(const char *s, size_t utf8_len, size_t utf16_pos) {
|
||||||
size_t utf16_offset) {
|
size_t utf16_units = 0;
|
||||||
const char *start = utf8;
|
size_t i = 0;
|
||||||
const char *end = utf8 + utf8_len;
|
while (utf16_units < utf16_pos && i < utf8_len) {
|
||||||
const char *it = start;
|
unsigned char c = s[i];
|
||||||
size_t utf16_count = 0;
|
if ((c & 0x80) == 0x00) {
|
||||||
while (it < end) {
|
i += 1;
|
||||||
if (utf16_count >= utf16_offset)
|
utf16_units += 1;
|
||||||
break;
|
} else if ((c & 0xE0) == 0xC0) {
|
||||||
const char *prev = it;
|
i += 2;
|
||||||
uint32_t codepoint = utf8::next(it, end);
|
utf16_units += 1;
|
||||||
if (codepoint <= 0xFFFF)
|
} else if ((c & 0xF0) == 0xE0) {
|
||||||
utf16_count += 1;
|
i += 3;
|
||||||
else
|
utf16_units += 1;
|
||||||
utf16_count += 2;
|
} else {
|
||||||
if (utf16_count > utf16_offset)
|
i += 4;
|
||||||
return prev - start;
|
utf16_units += 2;
|
||||||
}
|
}
|
||||||
return it - start;
|
}
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user