damus-c: add bolt11 parser from CLN

We'll need this for our lightning invoice view

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-10-19 07:45:06 -07:00
parent c4206883f2
commit dbe1260b54
44 changed files with 8280 additions and 0 deletions

View File

@@ -178,3 +178,22 @@ size_t utf8_encode(uint32_t point, char dest[UTF8_MAX_LEN])
return 4;
}
/* Check for valid UTF-8 */
bool utf8_check(const void *vbuf, size_t buflen)
{
const unsigned char *buf = vbuf;
struct utf8_state utf8_state = UTF8_STATE_INIT;
bool need_more = false;
for (size_t i = 0; i < buflen; i++) {
if (!utf8_decode(&utf8_state, buf[i])) {
need_more = true;
continue;
}
need_more = false;
if (errno != 0)
return false;
}
return !need_more;
}