summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2021-02-05 14:10:53 +0100
committerRoland Reichwein <mail@reichwein.it>2021-02-05 14:10:53 +0100
commit3d7a431811748c5aa1f49c35436696fc3f05de5d (patch)
tree252cb1896ebd994ee6c4f7b09b0927bd7fa709f3 /include
parent6a12dddc641be34b323835a495399715790811e0 (diff)
Documentation, support validation via Traits
Diffstat (limited to 'include')
-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