summaryrefslogtreecommitdiffhomepage
path: root/include/unicode.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/unicode.h')
-rw-r--r--include/unicode.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/unicode.h b/include/unicode.h
index df61ac3..2424fb1 100644
--- a/include/unicode.h
+++ b/include/unicode.h
@@ -562,6 +562,7 @@ namespace unicode {
return result;
}
+ // basic type version
template<typename T>
bool is_valid_utf(const std::basic_string<T>& s)
{
@@ -573,5 +574,17 @@ namespace unicode {
return true;
}
+ // Facet version
+ template<typename Facet>
+ bool is_valid_utf(const std::basic_string<typename Facet::value_type>& s)
+ {
+ try {
+ std::for_each(Facet::begin(s), Facet::end(s), [](const char32_t& c){});
+ } catch (const std::invalid_argument&) {
+ return false;
+ }
+ return true;
+ }
+
} // namespace unicode