string: add BOM helper

This commit is contained in:
cypherpunks
2018-08-29 13:32:52 +00:00
parent afc22ec539
commit 3704c4a012
2 changed files with 14 additions and 0 deletions
+13
View File
@@ -541,3 +541,16 @@ string_is_utf8(const char *str, size_t len)
}
return true;
}
/** As string_is_utf8(), but returns false if the string begins with a UTF-8
* byte order mark (BOM).
*/
int
string_is_utf8_no_bom(const char *str, size_t len)
{
if (len >= 3 && (!strcmpstart(str, "\uFEFF") ||
!strcmpstart(str, "\uFFFE"))) {
return false;
}
return string_is_utf8(str, len);
}