Skip to content

Commit 6a33027

Browse files
committed
Fastfetch: use the official function instead of our local copy
1 parent 5e9c0d0 commit 6a33027

File tree

1 file changed

+1
-39
lines changed

1 file changed

+1
-39
lines changed

src/fastfetch.c

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -319,44 +319,6 @@ static void listModules(bool pretty)
319319
}
320320
}
321321

322-
// Temporary copy before new release of yyjson
323-
static bool ffyyjson_locate_pos(const char *str, size_t len, size_t pos,
324-
size_t *line, size_t *col, size_t *chr) {
325-
size_t line_sum = 0, line_pos = 0, chr_sum = 0;
326-
const uint8_t *cur = (const uint8_t *)str;
327-
const uint8_t *end = cur + pos;
328-
329-
if (!str || pos > len) {
330-
if (line) *line = 0;
331-
if (col) *col = 0;
332-
if (chr) *chr = 0;
333-
return false;
334-
}
335-
336-
while (cur < end) {
337-
uint8_t c = *cur;
338-
chr_sum += 1;
339-
if (__builtin_expect(c < 0x80, true)) { /* 0xxxxxxx (0x00-0x7F) ASCII */
340-
if (c == '\n') {
341-
line_sum += 1;
342-
line_pos = chr_sum;
343-
}
344-
cur += 1;
345-
}
346-
else if (c < 0xC0) cur += 1; /* 10xxxxxx (0x80-0xBF) Invalid */
347-
else if (c < 0xE0) cur += 2; /* 110xxxxx (0xC0-0xDF) 2-byte UTF-8 */
348-
else if (c < 0xF0) cur += 3; /* 1110xxxx (0xE0-0xEF) 3-byte UTF-8 */
349-
else if (c < 0xF8) cur += 4; /* 11110xxx (0xF0-0xF7) 4-byte UTF-8 */
350-
else cur += 1; /* 11111xxx (0xF8-0xFF) Invalid */
351-
}
352-
353-
if (line) *line = line_sum + 1;
354-
if (col) *col = chr_sum - line_pos + 1;
355-
if (chr) *chr = chr_sum;
356-
return true;
357-
}
358-
359-
360322
static bool parseJsoncFile(const char* path)
361323
{
362324
assert(!instance.state.configDoc);
@@ -371,7 +333,7 @@ static bool parseJsoncFile(const char* path)
371333
size_t row = 0, col = error.pos;
372334
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
373335
if (ffAppendFileBuffer(path, &content))
374-
ffyyjson_locate_pos(content.chars, content.length, error.pos, &row, &col, NULL);
336+
yyjson_locate_pos(content.chars, content.length, error.pos, &row, &col, NULL);
375337
fprintf(stderr, "Error: failed to parse JSON config file `%s` at (%zu, %zu): %s\n", path, row, col, error.msg);
376338
exit(477);
377339
}

0 commit comments

Comments
 (0)