summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-11-06 15:33:25 -0500
committerNick Mathewson <nickm@torproject.org>2018-11-06 15:33:25 -0500
commit8020d6fb05d9477e77c6ca554dc1288873f6115c (patch)
treec3498e105bfd77c8691253f7a2a5464bc3206256 /src/lib
parentba28704b296b1036151e4bfa97e7091d7639a573 (diff)
parentda716fdfbb08952b971882eba1dabca2fef9c7f3 (diff)
downloadtor-8020d6fb05d9477e77c6ca554dc1288873f6115c.tar.gz
tor-8020d6fb05d9477e77c6ca554dc1288873f6115c.zip
Merge remote-tracking branch 'tor-github/pr/464'
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/string/util_string.c13
-rw-r--r--src/lib/string/util_string.h1
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) */