diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index 9b5120b..ddb77f2 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -480,12 +480,27 @@ namespace etk { fileRead(&value[0], sizeof(T), fileSize()/sizeof(T)); return value; } + std::string fileReadAllString() { + std::string value; + value.resize(fileSize()); + fileRead(&value[0], sizeof(char), fileSize()/sizeof(char)); + return value; + } + std::u32string fileReadAllU32String() { + return utf8::convertUnicode(fileReadAllString()); + } /** * @brief Write all the vector in a file */ template void fileWriteAll(const std::vector& _value) { fileWrite(static_cast(&(_value[0])), sizeof(T), _value.size()/sizeof(T)); } + void fileWriteAll(const std::string& _value) { + fileWrite(static_cast(&(_value[0])), sizeof(char), _value.size()/sizeof(char)); + } + void fileWriteAll(const std::u32string& _value) { + fileWriteAll(u32char::convertToUtf8(_value)); + } private: /** * @brief Order the list of subnode the folder first and the alphabetical order diff --git a/etk/stdTools.cpp b/etk/stdTools.cpp index 9f5134c..b78a5a6 100644 --- a/etk/stdTools.cpp +++ b/etk/stdTools.cpp @@ -131,6 +131,11 @@ int8_t u32char::convertUtf8(char32_t _val, char _output[5]) { } } +std::string u32char::convertToUtf8(const std::u32string& _input) { + TK_TODO("implement this function ..."); + return "TODO ... std::string u32char::convertToUtf8(const std::u32string& _input)"; +} + #undef __class__ #define __class__ "utf8" @@ -227,6 +232,11 @@ bool utf8::theoricFirst(const char _input) { return false; } +std::u32string utf8::convertUnicode(const std::string& _input) { + TK_TODO("implement this function ..."); + return U"TODO ... std::u32string utf8::convertUnicode(const std::string& _input)"; +} + #undef __class__ #define __class__ "etk" diff --git a/etk/stdTools.h b/etk/stdTools.h index 603d505..684c1bf 100644 --- a/etk/stdTools.h +++ b/etk/stdTools.h @@ -41,6 +41,7 @@ namespace u32char { char32_t changeOrder(char32_t _val); int8_t convertUtf8(char32_t _val, char _output[5]); + std::string convertToUtf8(const std::u32string& _input); }; namespace utf8 { @@ -58,6 +59,7 @@ namespace utf8 { bool theoricFirst(const char _input); char32_t convertChar32(const char* _input); + std::u32string convertUnicode(const std::string& _input); }; namespace std { diff --git a/test/main.cpp b/test/main.cpp index d7721cb..a5a2331 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include #undef __class__ #define __class__ "etktest" @@ -249,7 +251,7 @@ void testRegExp() { //testRegExpSingle("'((\\\\[\\\\'])|.)*'", data); - + /* data = "ddfgdfgh"; etk::RegExp reg(".*"); reg.setMaximize(true); @@ -287,6 +289,63 @@ void testRegExp() { TK_INFO(" match [" << reg.start() << ".." << reg.stop() << "] "); TK_INFO(" ==> '" << std::string(data, reg.start(), reg.stop()-reg.start()) << "'"); } + */ + /* + std::tr1::cmatch res; + str = "

Egg prices

"; + std::tr1::regex rx("([^<]+)"); + std::tr1::regex_search(str.c_str(), res, rx); + std::cout << res[1] << ". " << res[2] << "\n"; + */ + { + std::string lines[] = {"Roses are #ff0000", + "violets are #0000ff", + "all of my base are belong to you"}; + + std::regex myRegex("#([a-f0-9]{6})"); + /* + for (const auto &line : lines) { + std::cout << line << ": " << std::regex_search(line, color_regex) << '\n'; + } + */ + + std::smatch resultMatch; + for (const auto &line : lines) { + TK_DEBUG("in line : '" << line << "'"); + std::regex_search(line, resultMatch, myRegex); + TK_DEBUG(" Find " << resultMatch.size() << " elements"); + for (size_t iii=0; iii