diff --git a/Makefile b/Makefile index 1e23b7a..d66cb8b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ LIBNAME := $(shell basename $$(pwd)) MAJOR := 1 -MINOR := 1.0 +MINOR := 2.0 UNAME_S := $(shell uname -s) @@ -35,7 +35,7 @@ else CXXFLAGS += -D NDEBUG -O3 endif -LDLIBS := -lscerror +LDLIBS := -lscerror -lunistring RM := /bin/rm -f INSTALL := /usr/bin/install -c diff --git a/generics.hpp b/generics.hpp new file mode 100644 index 0000000..41919c5 --- /dev/null +++ b/generics.hpp @@ -0,0 +1,19 @@ +#ifndef GENERICS_H_ +#define GENERICS_H_ + +#include +#include + +namespace sc { + + template + T from_string(const std::string& val) { + T result; + std::istringstream iss {val}; + iss >> result; + return result; + } + +} + +#endif // GENERICS_H_ diff --git a/string_utils.cpp b/string_utils.cpp index b8a25ee..3bce5d8 100644 --- a/string_utils.cpp +++ b/string_utils.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -264,3 +265,21 @@ string sc::real_path(const string& path) { } return ""; } + +string sc::remove_accents(const string& text) { + vector buf; + buf.resize(text.size() * 2); + size_t bufsize {buf.size()}; + u8_normalize(UNINORM_NFD, + reinterpret_cast(text.data()), + text.size(), + reinterpret_cast(buf.data()), + &bufsize); + + // hack: now remove all bytes with a value higher than 127 + auto it = remove_if(buf.begin(), buf.end(), [](uint8_t c) { + return c > 127; + }); + buf.erase(it, buf.end()); + return {buf.data()}; +} diff --git a/string_utils.hpp b/string_utils.hpp index da24fbd..45f4c03 100644 --- a/string_utils.hpp +++ b/string_utils.hpp @@ -64,6 +64,8 @@ namespace sc { bool is_valid_utf8 (const std::string& str); std::string real_path (const std::string& path); + + std::string remove_accents (const std::string& text); } #endif // _string_utils_