2014-04-24 08:36:48 +02:00
|
|
|
#include "concordia/common/text_utils.hpp"
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
|
|
|
#include <boost/locale.hpp>
|
2018-12-13 17:43:01 +01:00
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
2017-10-15 18:54:15 +02:00
|
|
|
#include "utf8/utf8.h"
|
|
|
|
|
2014-04-24 08:36:48 +02:00
|
|
|
|
2014-04-24 14:26:35 +02:00
|
|
|
TextUtils::TextUtils() {
|
|
|
|
_lowerConverter =
|
|
|
|
StringCaseConverterManager::getInstance().getLowerCaseConverter("pl");
|
|
|
|
_upperConverter =
|
|
|
|
StringCaseConverterManager::getInstance().getUpperCaseConverter("pl");
|
|
|
|
}
|
2014-04-29 14:46:04 +02:00
|
|
|
|
2018-12-13 17:43:01 +01:00
|
|
|
char TextUtils::_easytolower(char in) {
|
|
|
|
if(in <= 'Z' && in >= 'A') {
|
|
|
|
return in - ('Z' - 'z');
|
|
|
|
}
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-04-15 14:14:10 +02:00
|
|
|
std::string TextUtils::toLowerCase(const std::string & text) {
|
2017-10-15 18:54:15 +02:00
|
|
|
if (!utf8::is_valid(text.begin(), text.end())) {
|
2018-12-13 17:43:01 +01:00
|
|
|
std::string data = text;
|
|
|
|
std::transform(data.begin(), data.end(), data.begin(), TextUtils::_easytolower);
|
|
|
|
return data;
|
2017-10-15 18:54:15 +02:00
|
|
|
}
|
2014-04-24 14:26:35 +02:00
|
|
|
return simpleConvert(*_lowerConverter, text);
|
2014-04-24 08:36:48 +02:00
|
|
|
}
|
|
|
|
|
2015-04-15 14:14:10 +02:00
|
|
|
std::string TextUtils::toUpperCase(const std::string & text) {
|
2014-04-24 14:26:35 +02:00
|
|
|
return simpleConvert(*_upperConverter, text);
|
2014-04-24 08:36:48 +02:00
|
|
|
}
|