diff options
author | cypherpunks <cypherpunks@torproject.org> | 2018-08-29 13:32:52 +0000 |
---|---|---|
committer | cypherpunks <cypherpunks@torproject.org> | 2018-10-23 00:33:48 +0000 |
commit | 3704c4a01219cca7273fa5fa0bc6751d98ad05ac (patch) | |
tree | c6b88808549535fadcdba6bd6d93d9e951433f44 /src/lib/string | |
parent | afc22ec5396e677c8cc3f7f14ecec7dc02a75b63 (diff) | |
download | tor-3704c4a01219cca7273fa5fa0bc6751d98ad05ac.tar.gz tor-3704c4a01219cca7273fa5fa0bc6751d98ad05ac.zip |
string: add BOM helper
Diffstat (limited to 'src/lib/string')
-rw-r--r-- | src/lib/string/util_string.c | 13 | ||||
-rw-r--r-- | src/lib/string/util_string.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/string/util_string.c b/src/lib/string/util_string.c index b2b85d151d..e76e73046f 100644 --- a/src/lib/string/util_string.c +++ b/src/lib/string/util_string.c @@ -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); +} diff --git a/src/lib/string/util_string.h b/src/lib/string/util_string.h index 746ece0d33..99467a27c3 100644 --- a/src/lib/string/util_string.h +++ b/src/lib/string/util_string.h @@ -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_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) */ |