concordia-library/concordia/common/text_utils.cpp
2018-12-13 17:43:01 +01:00

36 lines
1014 B
C++

#include "concordia/common/text_utils.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/locale.hpp>
#include <string>
#include <algorithm>
#include "utf8/utf8.h"
TextUtils::TextUtils() {
_lowerConverter =
StringCaseConverterManager::getInstance().getLowerCaseConverter("pl");
_upperConverter =
StringCaseConverterManager::getInstance().getUpperCaseConverter("pl");
}
char TextUtils::_easytolower(char in) {
if(in <= 'Z' && in >= 'A') {
return in - ('Z' - 'z');
}
return in;
}
std::string TextUtils::toLowerCase(const std::string & text) {
if (!utf8::is_valid(text.begin(), text.end())) {
std::string data = text;
std::transform(data.begin(), data.end(), data.begin(), TextUtils::_easytolower);
return data;
}
return simpleConvert(*_lowerConverter, text);
}
std::string TextUtils::toUpperCase(const std::string & text) {
return simpleConvert(*_upperConverter, text);
}