[DEV] add some apis
This commit is contained in:
parent
d162f2a70d
commit
96878f539e
@ -480,12 +480,27 @@ namespace etk {
|
|||||||
fileRead(&value[0], sizeof(T), fileSize()/sizeof(T));
|
fileRead(&value[0], sizeof(T), fileSize()/sizeof(T));
|
||||||
return value;
|
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
|
* @brief Write all the vector in a file
|
||||||
*/
|
*/
|
||||||
template<typename T> void fileWriteAll(const std::vector<T>& _value) {
|
template<typename T> void fileWriteAll(const std::vector<T>& _value) {
|
||||||
fileWrite(static_cast<const void*>(&(_value[0])), sizeof(T), _value.size()/sizeof(T));
|
fileWrite(static_cast<const void*>(&(_value[0])), sizeof(T), _value.size()/sizeof(T));
|
||||||
}
|
}
|
||||||
|
void fileWriteAll(const std::string& _value) {
|
||||||
|
fileWrite(static_cast<const void*>(&(_value[0])), sizeof(char), _value.size()/sizeof(char));
|
||||||
|
}
|
||||||
|
void fileWriteAll(const std::u32string& _value) {
|
||||||
|
fileWriteAll(u32char::convertToUtf8(_value));
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief Order the list of subnode the folder first and the alphabetical order
|
* @brief Order the list of subnode the folder first and the alphabetical order
|
||||||
|
@ -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__
|
#undef __class__
|
||||||
#define __class__ "utf8"
|
#define __class__ "utf8"
|
||||||
@ -227,6 +232,11 @@ bool utf8::theoricFirst(const char _input) {
|
|||||||
return false;
|
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__
|
#undef __class__
|
||||||
#define __class__ "etk"
|
#define __class__ "etk"
|
||||||
|
@ -41,6 +41,7 @@ namespace u32char {
|
|||||||
|
|
||||||
char32_t changeOrder(char32_t _val);
|
char32_t changeOrder(char32_t _val);
|
||||||
int8_t convertUtf8(char32_t _val, char _output[5]);
|
int8_t convertUtf8(char32_t _val, char _output[5]);
|
||||||
|
std::string convertToUtf8(const std::u32string& _input);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace utf8 {
|
namespace utf8 {
|
||||||
@ -58,6 +59,7 @@ namespace utf8 {
|
|||||||
bool theoricFirst(const char _input);
|
bool theoricFirst(const char _input);
|
||||||
|
|
||||||
char32_t convertChar32(const char* _input);
|
char32_t convertChar32(const char* _input);
|
||||||
|
std::u32string convertUnicode(const std::string& _input);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include <etk/log.h>
|
#include <etk/log.h>
|
||||||
#include <etk/Color.h>
|
#include <etk/Color.h>
|
||||||
#include <etk/RegExp.h>
|
#include <etk/RegExp.h>
|
||||||
|
#include <string>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "etktest"
|
#define __class__ "etktest"
|
||||||
@ -249,7 +251,7 @@ void testRegExp() {
|
|||||||
//testRegExpSingle("'((\\\\[\\\\'])|.)*'", data);
|
//testRegExpSingle("'((\\\\[\\\\'])|.)*'", data);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
data = "ddfgdfgh";
|
data = "ddfgdfgh";
|
||||||
etk::RegExp<std::string> reg(".*");
|
etk::RegExp<std::string> reg(".*");
|
||||||
reg.setMaximize(true);
|
reg.setMaximize(true);
|
||||||
@ -287,6 +289,63 @@ void testRegExp() {
|
|||||||
TK_INFO(" match [" << reg.start() << ".." << reg.stop() << "] ");
|
TK_INFO(" match [" << reg.start() << ".." << reg.stop() << "] ");
|
||||||
TK_INFO(" ==> '" << std::string(data, reg.start(), reg.stop()-reg.start()) << "'");
|
TK_INFO(" ==> '" << std::string(data, reg.start(), reg.stop()-reg.start()) << "'");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
std::tr1::cmatch res;
|
||||||
|
str = "<h2>Egg prices</h2>";
|
||||||
|
std::tr1::regex rx("<h(.)>([^<]+)");
|
||||||
|
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<resultMatch.size(); ++iii) {
|
||||||
|
int32_t posStart = std::distance(line.begin(), resultMatch[iii].first);
|
||||||
|
int32_t posStop = std::distance(line.begin(), resultMatch[iii].second);
|
||||||
|
TK_DEBUG(" [" << iii << "] " << *resultMatch[iii].first);
|
||||||
|
TK_DEBUG(" [" << iii << "] " << *resultMatch[iii].second);
|
||||||
|
TK_DEBUG(" [" << iii << "] " << std::string(line, posStart, posStop-posStart));
|
||||||
|
/*
|
||||||
|
std::ssub_match sub_match = color_match[i];
|
||||||
|
std::string sub_match_str = sub_match.str();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const std::string myData = "void limit(const vec2& _origin, const vec2& _size);\n plop(sf)";
|
||||||
|
std::regex myRegex("\\b(\\w|_)+[ \\t]*\\(");
|
||||||
|
|
||||||
|
std::smatch resultMatch;
|
||||||
|
TK_DEBUG("in line : '" << myData << "'");
|
||||||
|
std::regex_search(myData, resultMatch, myRegex);
|
||||||
|
TK_DEBUG(" Find " << resultMatch.size() << " elements");
|
||||||
|
for (size_t iii=0; iii<resultMatch.size(); ++iii) {
|
||||||
|
int32_t posStart = std::distance(myData.begin(), resultMatch[iii].first);
|
||||||
|
int32_t posStop = std::distance(myData.begin(), resultMatch[iii].second);
|
||||||
|
TK_DEBUG(" [" << iii << "] " << *resultMatch[iii].first);
|
||||||
|
TK_DEBUG(" [" << iii << "] " << *resultMatch[iii].second);
|
||||||
|
TK_DEBUG(" [" << iii << "] " << std::string(myData, posStart, posStop-posStart));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user