ensuring UTF-8 strings

This commit is contained in:
rjawor 2017-10-15 18:54:15 +02:00
parent 61631c52a3
commit bd4ff81e32

View File

@ -2,6 +2,8 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/case_conv.hpp>
#include <boost/locale.hpp> #include <boost/locale.hpp>
#include "utf8/utf8.h"
TextUtils::TextUtils() { TextUtils::TextUtils() {
_lowerConverter = _lowerConverter =
@ -11,6 +13,9 @@ TextUtils::TextUtils() {
} }
std::string TextUtils::toLowerCase(const std::string & text) { std::string TextUtils::toLowerCase(const std::string & text) {
if (!utf8::is_valid(text.begin(), text.end())) {
throw ConcordiaException("Bad input encoding, use UTF-8");
}
return simpleConvert(*_lowerConverter, text); return simpleConvert(*_lowerConverter, text);
} }