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

View File

@ -541,3 +541,16 @@ string_is_utf8(const char *str, size_t len)
} }
return true; 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);
}

View File

@ -53,5 +53,6 @@ const char *find_str_at_start_of_line(const char *haystack,
int string_is_C_identifier(const char *string); int string_is_C_identifier(const char *string);
int string_is_utf8(const char *str, size_t len); int string_is_utf8(const char *str, size_t len);
int string_is_utf8_no_bom(const char *str, size_t len);
#endif /* !defined(TOR_UTIL_STRING_H) */ #endif /* !defined(TOR_UTIL_STRING_H) */