[DEV] correction of stl-port
This commit is contained in:
parent
c8dc0b0100
commit
b946a5f7c6
@ -73,11 +73,11 @@ namespace etk {
|
||||
(uint8_t)(etk_avg(0,_b,255)),
|
||||
(uint8_t)(etk_avg(0,_a,255)) );
|
||||
}
|
||||
std::u32string getHexString(void) const {
|
||||
return U"0x" + to_u32string<uint32_t>(get(), std::hex);
|
||||
std::string getHexString(void) const {
|
||||
return "0x" + to_string<uint32_t>(get(), std::hex);
|
||||
};
|
||||
std::u32string getString(void) const {
|
||||
return U"#" + to_u32string<uint32_t>(get(), std::hex);
|
||||
std::string getString(void) const {
|
||||
return "#" + to_string<uint32_t>(get(), std::hex);
|
||||
};
|
||||
MY_TYPE r(void) const {
|
||||
return m_r;
|
||||
|
44
etk/RegExp.h
44
etk/RegExp.h
@ -917,7 +917,7 @@ template<class CLASS_TYPE> class RegExpNodePTheseElem : public RegExpNode<CLASS_
|
||||
std::vector<char32_t> tmpData;
|
||||
while (pos < RegExpNode<CLASS_TYPE>::m_RegExpData.size()) {
|
||||
tmpData.clear();
|
||||
switch (RegExpNode<CLASS_TYPE>::m_RegExpData[pos].get()) {
|
||||
switch (RegExpNode<CLASS_TYPE>::m_RegExpData[pos]) {
|
||||
case REGEXP_OPCODE_PTHESE_IN:
|
||||
{
|
||||
elementSize=getLenOfPThese(RegExpNode<CLASS_TYPE>::m_RegExpData, pos);
|
||||
@ -1221,32 +1221,45 @@ template<class CLASS_TYPE> class RegExp
|
||||
* @param[in,out] _exp Regular expression to parse
|
||||
*/
|
||||
RegExp(const std::u32string &_exp=U"") :
|
||||
m_expressionRequested(U""),
|
||||
m_isOk(false),
|
||||
m_notBeginWithChar(false),
|
||||
m_notEndWithChar(false)
|
||||
{
|
||||
m_expressionRequested(U""),
|
||||
m_isOk(false),
|
||||
m_notBeginWithChar(false),
|
||||
m_notEndWithChar(false) {
|
||||
m_areaFind.start=0;
|
||||
m_areaFind.stop=0;
|
||||
if (_exp.size() != 0) {
|
||||
setRegExp(_exp);
|
||||
}
|
||||
};
|
||||
RegExp(const std::string &_exp="") :
|
||||
m_expressionRequested(U""),
|
||||
m_isOk(false),
|
||||
m_notBeginWithChar(false),
|
||||
m_notEndWithChar(false) {
|
||||
m_areaFind.start=0;
|
||||
m_areaFind.stop=0;
|
||||
if (_exp.size() != 0) {
|
||||
setRegExp(to_u32string(_exp));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~RegExp(void)
|
||||
{
|
||||
~RegExp(void) {
|
||||
m_isOk = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Set a new regular expression matching
|
||||
* @param[in] _regexp the new expression to search
|
||||
* @param[in] _exp the new expression to search
|
||||
*/
|
||||
void setRegExp(const std::u32string &_regexp)
|
||||
{
|
||||
void setRegExp(const std::string &_exp) {
|
||||
if (_exp.size() != 0) {
|
||||
setRegExp(to_u32string(_exp));
|
||||
}
|
||||
}
|
||||
void setRegExp(const std::u32string &_regexp) {
|
||||
m_expressionRequested = _regexp;
|
||||
std::vector<char32_t> tmpExp;
|
||||
|
||||
@ -1382,8 +1395,10 @@ template<class CLASS_TYPE> class RegExp
|
||||
* @brief Get the regular expression string
|
||||
* @return the string representing the RegExp
|
||||
*/
|
||||
const std::u32string& getRegExp(void) const
|
||||
{
|
||||
std::string getRegExp(void) const {
|
||||
return to_u8string(m_expressionRequested);
|
||||
};
|
||||
const std::u32string& getURegExp(void) const {
|
||||
return m_expressionRequested;
|
||||
};
|
||||
|
||||
@ -1392,8 +1407,7 @@ template<class CLASS_TYPE> class RegExp
|
||||
* @return true : the regExp is correctly parsed
|
||||
* @return false : an error occcured (check log ...)
|
||||
*/
|
||||
bool getStatus(void)
|
||||
{
|
||||
bool getStatus(void) {
|
||||
return m_isOk;
|
||||
};
|
||||
// process the regular expression
|
||||
|
@ -315,7 +315,7 @@ bool start_with(const std::string& _obj, const std::string& _val, bool _caseSens
|
||||
}
|
||||
if (true == _caseSensitive) {
|
||||
for( size_t iii = 0;
|
||||
iii < _obj.size();
|
||||
iii < _val.size();
|
||||
iii++) {
|
||||
if (_obj[iii] != _val[iii]) {
|
||||
return false;
|
||||
@ -324,7 +324,7 @@ bool start_with(const std::string& _obj, const std::string& _val, bool _caseSens
|
||||
return true;
|
||||
}
|
||||
for( size_t iii = 0;
|
||||
iii < _obj.size();
|
||||
iii < _val.size();
|
||||
iii++) {
|
||||
if (tolower(_val[iii]) != tolower(_obj[iii])) {
|
||||
return false;
|
||||
@ -342,7 +342,7 @@ bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _ca
|
||||
}
|
||||
if (true == _caseSensitive) {
|
||||
for( size_t iii = 0;
|
||||
iii < _obj.size();
|
||||
iii < _val.size();
|
||||
iii++) {
|
||||
if (_obj[iii] != _val[iii]) {
|
||||
return false;
|
||||
@ -351,7 +351,7 @@ bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _ca
|
||||
return true;
|
||||
}
|
||||
for( size_t iii = 0;
|
||||
iii < _obj.size();
|
||||
iii < _val.size();
|
||||
iii++) {
|
||||
if (tolower(_val[iii]) != tolower(_obj[iii])) {
|
||||
return false;
|
||||
@ -400,12 +400,12 @@ std::string extract_line(const std::string& _obj, int32_t _pos) {
|
||||
stopPos = _obj.size();
|
||||
}
|
||||
}
|
||||
if (startPos < 0) {
|
||||
if (startPos == std::string::npos) {
|
||||
startPos = 0;
|
||||
} else if (startPos >= _obj.size() ) {
|
||||
return "";
|
||||
}
|
||||
if (stopPos < 0) {
|
||||
if (stopPos == std::string::npos) {
|
||||
return "";
|
||||
} else if (stopPos >= _obj.size() ) {
|
||||
stopPos = _obj.size();
|
||||
@ -429,12 +429,12 @@ std::u32string extract_line(const std::u32string& _obj, int32_t _pos) {
|
||||
stopPos = _obj.size();
|
||||
}
|
||||
}
|
||||
if (startPos < 0) {
|
||||
if (startPos == std::string::npos) {
|
||||
startPos = 0;
|
||||
} else if (startPos >= _obj.size() ) {
|
||||
return U"";
|
||||
}
|
||||
if (stopPos < 0) {
|
||||
if (stopPos == std::string::npos) {
|
||||
return U"";
|
||||
} else if (stopPos >= _obj.size() ) {
|
||||
stopPos = _obj.size();
|
||||
@ -444,7 +444,7 @@ std::u32string extract_line(const std::u32string& _obj, int32_t _pos) {
|
||||
|
||||
std::vector<std::string> string_split(const std::string& _input, char _val) {
|
||||
std::vector<std::string> list;
|
||||
size_t lastStartPos=0;
|
||||
size_t lastStartPos = 0;
|
||||
for(size_t iii=0; iii<_input.size(); iii++) {
|
||||
if (_input[iii]==_val) {
|
||||
list.push_back(std::string(_input, lastStartPos, iii));
|
||||
|
@ -315,10 +315,10 @@ std::u32string to_upper(const std::u32string& _obj);
|
||||
std::string to_lower(const std::string& _obj);
|
||||
std::string to_upper(const std::string& _obj);
|
||||
|
||||
bool end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = false);
|
||||
bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false);
|
||||
bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = false);
|
||||
bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false);
|
||||
bool end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = true);
|
||||
bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true);
|
||||
bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = true);
|
||||
bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true);
|
||||
|
||||
bool compare_no_case(const std::u32string& _obj, const std::u32string& _val);
|
||||
bool compare_no_case(const std::string& _obj, const std::string& _val);
|
||||
|
@ -74,14 +74,14 @@ namespace etk {
|
||||
m_floats[1] = false;
|
||||
// copy to permit to modify it :
|
||||
std::string tmpStr = _str;
|
||||
if (_str[0] == '(') {
|
||||
if (tmpStr.front() == '(') {
|
||||
tmpStr.erase(tmpStr.begin());
|
||||
}
|
||||
if (*tmpStr.end() == ')') {
|
||||
tmpStr.erase(tmpStr.end());
|
||||
if (tmpStr.back() == ')') {
|
||||
tmpStr.pop_back();
|
||||
}
|
||||
size_t posComa = tmpStr.find(',');
|
||||
if (posComa == 0) {
|
||||
if (posComa == std::string::npos) {
|
||||
// no coma ...
|
||||
// in every case, we parse the first element :
|
||||
m_floats[0] = stobool(tmpStr);
|
||||
@ -98,14 +98,14 @@ namespace etk {
|
||||
m_floats[1] = false;
|
||||
// copy to permit to modify it :
|
||||
std::u32string tmpStr = _str;
|
||||
if (_str[0] == '(') {
|
||||
if (tmpStr.front() == '(') {
|
||||
tmpStr.erase(tmpStr.begin());
|
||||
}
|
||||
if (*tmpStr.end() == ')') {
|
||||
tmpStr.erase(tmpStr.end());
|
||||
if (tmpStr.back() == ')') {
|
||||
tmpStr.pop_back();
|
||||
}
|
||||
size_t posComa = tmpStr.find(',');
|
||||
if (posComa == 0) {
|
||||
if (posComa == std::string::npos) {
|
||||
// no coma ...
|
||||
// in every case, we parse the first element :
|
||||
m_floats[0] = stobool(tmpStr);
|
||||
@ -142,15 +142,15 @@ namespace etk {
|
||||
m_floats[1] = 0;
|
||||
// copy to permit to modify it :
|
||||
std::string tmpStr = _str;
|
||||
if (_str[0] == '(') {
|
||||
if (tmpStr.front() == '(') {
|
||||
tmpStr.erase(tmpStr.begin());
|
||||
}
|
||||
if (*tmpStr.end() == ')') {
|
||||
tmpStr.erase(tmpStr.end());
|
||||
if (tmpStr.back() == ')') {
|
||||
tmpStr.pop_back();
|
||||
}
|
||||
|
||||
size_t posComa = tmpStr.find(',');
|
||||
if (posComa == 0) {
|
||||
if (posComa == std::string::npos) {
|
||||
// no coma ...
|
||||
// in every case, we parse the first element :
|
||||
m_floats[0] = stoi(tmpStr);
|
||||
@ -167,11 +167,11 @@ namespace etk {
|
||||
m_floats[1] = 0;
|
||||
// copy to permit to modify it :
|
||||
std::u32string tmpStr = _str;
|
||||
if (_str[0] == '(') {
|
||||
if (tmpStr.front() == '(') {
|
||||
tmpStr.erase(tmpStr.begin());
|
||||
}
|
||||
if (*tmpStr.end() == ')') {
|
||||
tmpStr.erase(tmpStr.end());
|
||||
if (tmpStr.back() == ')') {
|
||||
tmpStr.pop_back();
|
||||
}
|
||||
|
||||
size_t posComa = tmpStr.find(',');
|
||||
@ -214,14 +214,14 @@ namespace etk {
|
||||
m_floats[1] = 0;
|
||||
// copy to permit to modify it :
|
||||
std::string tmpStr = _str;
|
||||
if (_str[0] == '(') {
|
||||
if (tmpStr.front() == '(') {
|
||||
tmpStr.erase(tmpStr.begin());
|
||||
}
|
||||
if (*tmpStr.end() == ')') {
|
||||
tmpStr.erase(tmpStr.end());
|
||||
if (tmpStr.back() == ')') {
|
||||
tmpStr.pop_back();
|
||||
}
|
||||
size_t posComa = tmpStr.find(',');
|
||||
if (posComa == 0) {
|
||||
if (posComa == std::string::npos) {
|
||||
// no coma ...
|
||||
// in every case, we parse the first element :
|
||||
m_floats[0] = stoi(tmpStr);
|
||||
@ -239,14 +239,14 @@ namespace etk {
|
||||
m_floats[1] = 0;
|
||||
// copy to permit to modify it :
|
||||
std::u32string tmpStr = _str;
|
||||
if (_str[0] == '(') {
|
||||
if (tmpStr.front() == '(') {
|
||||
tmpStr.erase(tmpStr.begin());
|
||||
}
|
||||
if (*tmpStr.end() == ')') {
|
||||
tmpStr.erase(tmpStr.end());
|
||||
if (tmpStr.back() == ')') {
|
||||
tmpStr.pop_back();
|
||||
}
|
||||
size_t posComa = tmpStr.find(',');
|
||||
if (posComa == 0) {
|
||||
if (posComa == std::string::npos) {
|
||||
// no coma ...
|
||||
// in every case, we parse the first element :
|
||||
m_floats[0] = stoi(tmpStr);
|
||||
@ -283,14 +283,14 @@ namespace etk {
|
||||
m_floats[1] = 0;
|
||||
// copy to permit to modify it :
|
||||
std::string tmpStr = _str;
|
||||
if (_str[0] == '(') {
|
||||
if (tmpStr.front() == '(') {
|
||||
tmpStr.erase(tmpStr.begin());
|
||||
}
|
||||
if (*tmpStr.end() == ')') {
|
||||
tmpStr.erase(tmpStr.end());
|
||||
if (tmpStr.back() == ')') {
|
||||
tmpStr.pop_back();
|
||||
}
|
||||
size_t posComa = tmpStr.find(',');
|
||||
if (posComa == 0) {
|
||||
if (posComa == std::string::npos) {
|
||||
// no coma ...
|
||||
// in every case, we parse the first element :
|
||||
m_floats[0] = stof(tmpStr);
|
||||
@ -307,14 +307,14 @@ namespace etk {
|
||||
m_floats[1] = 0;
|
||||
// copy to permit to modify it :
|
||||
std::u32string tmpStr = _str;
|
||||
if (_str[0] == '(') {
|
||||
if (tmpStr.front() == '(') {
|
||||
tmpStr.erase(tmpStr.begin());
|
||||
}
|
||||
if (*tmpStr.end() == ')') {
|
||||
tmpStr.erase(tmpStr.end());
|
||||
if (tmpStr.back() == ')') {
|
||||
tmpStr.pop_back();
|
||||
}
|
||||
size_t posComa = tmpStr.find(',');
|
||||
if (posComa == 0) {
|
||||
if (posComa == std::string::npos) {
|
||||
// no coma ...
|
||||
// in every case, we parse the first element :
|
||||
m_floats[0] = stof(tmpStr);
|
||||
|
@ -36,66 +36,52 @@ extern "C" {
|
||||
|
||||
|
||||
|
||||
static std::string simplifyPathAbstractPath(std::string _input)
|
||||
{
|
||||
int32_t findStartPos = _input.find('/') + 1;
|
||||
int32_t findPos = _input.find('/', findStartPos);
|
||||
//TK_DEBUG("Siplify : \"" << input << "\"");
|
||||
int32_t preventBadCode = 0;
|
||||
while (findPos!=0) {
|
||||
//TK_DEBUG(" string=\"" << input << "\"");
|
||||
//TK_DEBUG(" '/' @" << findPos);
|
||||
if (_input.size()<findPos+1) {
|
||||
// no more element ...
|
||||
break;
|
||||
}
|
||||
if( _input[findPos+1] == '/'
|
||||
|| ( _input[findPos+1] == '.'
|
||||
&& _input.size()==findPos+2 )) {
|
||||
// cleane the element path
|
||||
_input.erase(findPos+1, 1);
|
||||
//TK_DEBUG(" Remove // string=\"" << input << "\"");
|
||||
} else {
|
||||
if (_input.size()<findPos+2) {
|
||||
// no more element ...
|
||||
break;
|
||||
}
|
||||
if( _input[findPos+1] == '.'
|
||||
&& _input[findPos+2] == '.') {
|
||||
// cleane the element path
|
||||
_input.erase(findStartPos, findPos+3 - findStartPos );
|
||||
//TK_DEBUG(" Remove xxx/.. string=\"" << input << "\"");
|
||||
} else if( _input[findPos+1] == '.'
|
||||
&& _input[findPos+2] == '/') {
|
||||
// cleane the element path
|
||||
_input.erase(findPos+1, 2);
|
||||
//TK_DEBUG(" Remove ./ string=\"" << input << "\"");
|
||||
} else {
|
||||
findStartPos = findPos+1;
|
||||
}
|
||||
}
|
||||
findPos = _input.find('/', findStartPos);
|
||||
preventBadCode++;
|
||||
if (preventBadCode>5000) {
|
||||
TK_CRITICAL("ERROR when getting the small path ... this is loop prevention...");
|
||||
break;
|
||||
std::string etk::simplifyPath(std::string _input) {
|
||||
// step 1 : for windows change \ in /:
|
||||
TK_DEBUG("Siplify(1) : \"" << _input << "\"");
|
||||
size_t currentPos = 0;
|
||||
while(currentPos <= _input.size()) {
|
||||
if (_input[currentPos] == '\\') {
|
||||
_input[currentPos] = '/';
|
||||
}
|
||||
currentPos++;
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
#ifndef __TARGET_OS__Windows
|
||||
// for the target that supported the Realpath system :
|
||||
char buf[MAX_FILE_NAME];
|
||||
memset(buf, 0, MAX_FILE_NAME);
|
||||
char * ok = realpath(input.c_str(), buf);
|
||||
if (!ok) {
|
||||
TK_ERROR("Error to get the real path");
|
||||
input = "/";
|
||||
} else {
|
||||
input = buf;
|
||||
// step 2 : remove all '//'
|
||||
TK_DEBUG("Siplify(2) : \"" << _input << "\"");
|
||||
currentPos = 0;
|
||||
while(currentPos <= _input.size()-1) {
|
||||
if ( _input[currentPos] != '/'
|
||||
|| _input[currentPos+1] != '/') {
|
||||
currentPos++;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
//TK_DEBUG(" ==> \"" << input << "\"");
|
||||
_input.erase(currentPos, 1);
|
||||
}
|
||||
// step 3 remove xxx/..
|
||||
TK_DEBUG("Siplify(3) : \"" << _input << "\"");
|
||||
size_t lastSlashPos = std::string::npos;
|
||||
currentPos = 0;
|
||||
while(currentPos <= _input.size()-2) {
|
||||
if ( _input[currentPos] != '/'
|
||||
|| _input[currentPos+1] != '.'
|
||||
|| _input[currentPos+2] != '.') {
|
||||
if (_input[currentPos] == '/') {
|
||||
lastSlashPos = currentPos;
|
||||
}
|
||||
currentPos++;
|
||||
continue;
|
||||
}
|
||||
if (lastSlashPos == std::string::npos) {
|
||||
currentPos++;
|
||||
continue;
|
||||
}
|
||||
_input.erase(lastSlashPos, currentPos+2-lastSlashPos+1);
|
||||
TK_DEBUG("update : \"" << _input << "\"");
|
||||
lastSlashPos = std::string::npos;
|
||||
currentPos = 0;
|
||||
}
|
||||
TK_DEBUG("Siplify(4) : \"" << _input << "\"");
|
||||
return _input;
|
||||
}
|
||||
|
||||
@ -224,7 +210,7 @@ std::string getApplicationPath(void) {
|
||||
TK_VERBOSE("Parse arg0 = '" << l_argZero << "' start with '/' ???");
|
||||
if (l_argZero[0] == '/') {
|
||||
binaryName = l_argZero;
|
||||
return simplifyPathAbstractPath(binaryName);
|
||||
return etk::simplifyPath(binaryName);
|
||||
}
|
||||
TK_VERBOSE("Parse arg0 = '" << l_argZero << "' try add PWD");
|
||||
char * basicPathPWD = getenv("PWD");
|
||||
@ -240,7 +226,7 @@ std::string getApplicationPath(void) {
|
||||
//Normal case when the file does not exist ... ==> the it was in unknow mode ...
|
||||
binaryName = testCompleatePath;
|
||||
TK_VERBOSE("find real name = '" << binaryName << "'");
|
||||
return simplifyPathAbstractPath(binaryName);
|
||||
return etk::simplifyPath(binaryName);
|
||||
}
|
||||
}
|
||||
//char * basicPathPATH = getenv("PATH");
|
||||
@ -288,9 +274,9 @@ void etk::initDefaultFolder(const char* _applName) {
|
||||
#ifndef __TARGET_OS__Android
|
||||
std::string binaryPath = getApplicationPath();
|
||||
binaryPath = replace(binaryPath, '\\', '/');
|
||||
int32_t pos = binaryPath.rfind('/');
|
||||
size_t pos = binaryPath.rfind('/');
|
||||
std::string binaryName(binaryPath, pos);
|
||||
binaryPath.erase(binaryName.begin() + pos, binaryName.end());
|
||||
binaryPath.erase(binaryPath.begin() + pos, binaryPath.end());
|
||||
TK_INFO("Bianry name : '" << binaryPath << "' && '" << binaryName << "'" );
|
||||
#ifdef __TARGET_OS__Windows
|
||||
baseFolderData = binaryPath;
|
||||
@ -321,7 +307,7 @@ void etk::initDefaultFolder(const char* _applName) {
|
||||
baseFolderData += binaryName;
|
||||
baseFolderData += "/";
|
||||
#endif
|
||||
baseFolderData = simplifyPathAbstractPath(baseFolderData);
|
||||
baseFolderData = simplifyPath(baseFolderData);
|
||||
}
|
||||
baseFolderDataUser = baseFolderHome;
|
||||
baseFolderDataUser += "/.local/share/";
|
||||
@ -623,7 +609,7 @@ void etk::FSNode::privateSetName(const std::string& _newName) {
|
||||
|
||||
// Now we reduce the path with all un-needed ../ and other thinks ...
|
||||
// TODO : Do it whith link and the other sub thinks ...
|
||||
m_userFileName = simplifyPathAbstractPath(m_userFileName);
|
||||
m_userFileName = simplifyPath(m_userFileName);
|
||||
TK_DBG_MODE("4 : Path simplification : [" << m_type << "]->\"" << m_userFileName << "\"");
|
||||
|
||||
// Now we generate the real FS path:
|
||||
@ -700,7 +686,7 @@ void etk::FSNode::generateFileSystemPath(void) {
|
||||
std::string themeName("");
|
||||
std::string basicName(m_userFileName);
|
||||
size_t firstPos = m_userFileName.find(':');
|
||||
if (0 != firstPos) {
|
||||
if (firstPos != std::string::npos) {
|
||||
// we find a theme name : We extracted it :
|
||||
themeName = std::string(m_userFileName, 0, firstPos);
|
||||
basicName = std::string(m_userFileName, firstPos+1);
|
||||
@ -831,7 +817,7 @@ void etk::FSNode::setName(const std::u32string& _newName) {
|
||||
|
||||
std::string etk::FSNode::getNameFolder(void) const {
|
||||
size_t lastPos = m_systemFileName.rfind('/');
|
||||
if (0 != lastPos) {
|
||||
if (lastPos != std::string::npos) {
|
||||
return std::string(m_systemFileName, 0, lastPos);
|
||||
}
|
||||
return "";
|
||||
@ -886,7 +872,7 @@ std::u32string etk::FSNode::getUName(void) const {
|
||||
|
||||
std::string etk::FSNode::getNameFile(void) const {
|
||||
size_t lastPos = m_systemFileName.rfind('/');
|
||||
if (0 != lastPos) {
|
||||
if (lastPos != std::string::npos) {
|
||||
return std::string(m_systemFileName, lastPos+1);
|
||||
}
|
||||
return "";
|
||||
@ -898,12 +884,11 @@ std::u32string etk::FSNode::getUNameFile(void) const {
|
||||
std::string etk::FSNode::getRelativeFolder(void) const {
|
||||
std::string tmppp = getName();
|
||||
TK_DBG_MODE("get REF folder : " << tmppp );
|
||||
switch (m_typeNode)
|
||||
{
|
||||
switch (m_typeNode) {
|
||||
case etk::FSN_UNKNOW:
|
||||
case etk::FSN_FOLDER:
|
||||
case etk::FSN_LINK:
|
||||
if (*tmppp.end() == '/') {
|
||||
if (tmppp.back() == '/') {
|
||||
TK_DBG_MODE(" ==> : " << tmppp );
|
||||
return tmppp;
|
||||
} else {
|
||||
@ -922,13 +907,13 @@ std::string etk::FSNode::getRelativeFolder(void) const {
|
||||
break;
|
||||
}
|
||||
size_t lastPos = tmppp.rfind('/');
|
||||
if (0 != lastPos) {
|
||||
TK_DBG_MODE(" ==> : " << tmppp.extract(0, lastPos+1) );
|
||||
if (lastPos != std::string::npos) {
|
||||
TK_DBG_MODE(" ==> : " << std::string(tmppp, 0, lastPos+1) );
|
||||
return std::string(tmppp, 0, lastPos+1);
|
||||
}
|
||||
lastPos = tmppp.rfind(':');
|
||||
if (0 != lastPos) {
|
||||
TK_DBG_MODE(" ==> : " << tmppp.extract(0, lastPos+1) );
|
||||
if (lastPos != std::string::npos) {
|
||||
TK_DBG_MODE(" ==> : " << std::string(tmppp, 0, lastPos+1) );
|
||||
return std::string(tmppp, 0, lastPos+1);
|
||||
}
|
||||
TK_DBG_MODE(" ==> : \"\"" );
|
||||
@ -994,8 +979,8 @@ uint64_t etk::FSNode::timeCreated(void) const {
|
||||
std::string etk::FSNode::timeCreatedString(void) const {
|
||||
time_t tmpVal = (int32_t)m_timeCreate;
|
||||
std::string tmpTime = ctime(&tmpVal);
|
||||
if (tmpTime[tmpTime.size()-1] == '\n') {
|
||||
tmpTime.erase(tmpTime.end());
|
||||
if (tmpTime.back() == '\n') {
|
||||
tmpTime.pop_back();
|
||||
}
|
||||
return tmpTime;
|
||||
}
|
||||
@ -1010,8 +995,8 @@ uint64_t etk::FSNode::timeModified(void) const {
|
||||
std::string etk::FSNode::timeModifiedString(void) const {
|
||||
time_t tmpVal = (int32_t)m_timeModify;
|
||||
std::string tmpTime = ctime(&tmpVal);
|
||||
if (tmpTime[tmpTime.size()-1] == '\n') {
|
||||
tmpTime.erase(tmpTime.end());
|
||||
if (tmpTime.back() == '\n') {
|
||||
tmpTime.pop_back();
|
||||
}
|
||||
return tmpTime;
|
||||
}
|
||||
@ -1026,8 +1011,8 @@ uint64_t etk::FSNode::timeAccessed(void) const {
|
||||
std::string etk::FSNode::timeAccessedString(void) const {
|
||||
time_t tmpVal = (int32_t)m_timeAccess;
|
||||
std::string tmpTime = ctime(&tmpVal);
|
||||
if (tmpTime[tmpTime.size()-1] == '\n') {
|
||||
tmpTime.erase(tmpTime.end());
|
||||
if (tmpTime.back() == '\n') {
|
||||
tmpTime.pop_back();
|
||||
}
|
||||
return tmpTime;
|
||||
}
|
||||
@ -1320,7 +1305,7 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector<std::u32string>& _output,
|
||||
*/
|
||||
bool etk::FSNode::fileHasExtention(void) {
|
||||
size_t lastPos = m_userFileName.rfind('.');
|
||||
if( 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file
|
||||
if( lastPos != std::string::npos // Find a . at the fist position .jdlskjdfklj ==> hiden file
|
||||
&& m_userFileName.size() != lastPos ) { // Remove file ended with .
|
||||
return true;
|
||||
} else {
|
||||
@ -1330,7 +1315,7 @@ bool etk::FSNode::fileHasExtention(void) {
|
||||
|
||||
std::string etk::FSNode::fileGetExtention(void) {
|
||||
size_t lastPos = m_userFileName.rfind('.');
|
||||
if( 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file
|
||||
if( lastPos != std::string::npos // Find a . at the fist position .jdlskjdfklj ==> hiden file
|
||||
&& m_userFileName.size() != lastPos ) { // Remove file ended with .
|
||||
// Get the FileName
|
||||
return std::string(m_userFileName, lastPos+1);
|
||||
|
@ -20,9 +20,9 @@
|
||||
|
||||
//http://developer.android.com/guide/topics/data/data-storage.html
|
||||
|
||||
namespace etk
|
||||
{
|
||||
namespace etk {
|
||||
void setArgZero(const std::string& _val);
|
||||
std::string simplifyPath(std::string _input);
|
||||
/**
|
||||
* List of Type that a node can have (this wrap some type that not exist on Windows)
|
||||
*/
|
||||
|
@ -178,53 +178,7 @@ void etk::FSNodeRight::setOtherRunable(bool _newStatus)
|
||||
}
|
||||
|
||||
std::u32string etk::FSNodeRight::getURight(void) const {
|
||||
std::u32string tmp;
|
||||
if (isUserReadable() == true) {
|
||||
tmp += U"r";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
if (isUserWritable() == true) {
|
||||
tmp += U"w";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
if (isUserRunable() == true) {
|
||||
tmp += U"x";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
if (isGroupReadable() == true) {
|
||||
tmp += U"r";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
if (isGroupWritable() == true) {
|
||||
tmp += U"w";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
if (isGroupRunable() == true) {
|
||||
tmp += U"x";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
if (isOtherReadable() == true) {
|
||||
tmp += U"r";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
if (isOtherWritable() == true) {
|
||||
tmp += U"w";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
if (isOtherRunable() == true) {
|
||||
tmp += U"x";
|
||||
} else {
|
||||
tmp += U"-";
|
||||
}
|
||||
return tmp;
|
||||
return to_u32string(getRight());
|
||||
}
|
||||
|
||||
std::string etk::FSNodeRight::getRight(void) const {
|
||||
|
63
etk/tool.cpp
63
etk/tool.cpp
@ -69,66 +69,3 @@ bool etk::tool::strnCmpNoCase(const char * _input1, const char * _input2, int32_
|
||||
}
|
||||
|
||||
|
||||
std::u32string etk::tool::simplifyPath(std::u32string _input)
|
||||
{
|
||||
size_t findStartPos = _input.find('/') + 1;
|
||||
size_t findPos = _input.find('/', findStartPos);
|
||||
//TK_DEBUG("Siplify : \"" << input << "\"");
|
||||
int32_t preventBadCode = 0;
|
||||
while (findPos!=0)
|
||||
{
|
||||
//TK_DEBUG(" string=\"" << input << "\"");
|
||||
//TK_DEBUG(" '/' @" << findPos);
|
||||
if (_input.size()<findPos+1) {
|
||||
// no more element ...
|
||||
break;
|
||||
}
|
||||
if( _input[findPos+1] == '/'
|
||||
|| ( _input[findPos+1] == '.'
|
||||
&& _input.size()==findPos+2 )) {
|
||||
// cleane the element path
|
||||
_input.erase(findPos+1, 1);
|
||||
//TK_DEBUG(" Remove // string=\"" << input << "\"");
|
||||
} else {
|
||||
if (_input.size()<findPos+2) {
|
||||
// no more element ...
|
||||
break;
|
||||
}
|
||||
if( _input[findPos+1] == '.'
|
||||
&& _input[findPos+2] == '.') {
|
||||
// cleane the element path
|
||||
_input.erase(findStartPos, findPos+3 - findStartPos );
|
||||
//TK_DEBUG(" Remove xxx/.. string=\"" << input << "\"");
|
||||
} else if( _input[findPos+1] == '.'
|
||||
&& _input[findPos+2] == '/') {
|
||||
// cleane the element path
|
||||
_input.erase(findPos+1, 2);
|
||||
//TK_DEBUG(" Remove ./ string=\"" << input << "\"");
|
||||
} else {
|
||||
findStartPos = findPos+1;
|
||||
}
|
||||
}
|
||||
findPos = _input.find('/', findStartPos);
|
||||
preventBadCode++;
|
||||
if (preventBadCode>5000) {
|
||||
TK_CRITICAL("ERROR when getting the small path ... this is loop prevention...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifndef __TARGET_OS__Windows
|
||||
// for the target that supported the Realpath system :
|
||||
char buf[MAX_FILE_NAME];
|
||||
memset(buf, 0, MAX_FILE_NAME);
|
||||
char * ok = realpath(to_u8string(_input).c_str(), buf);
|
||||
if (!ok) {
|
||||
TK_ERROR("Error to get the real path");
|
||||
_input = U"/";
|
||||
} else {
|
||||
_input = to_u32string(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
//TK_DEBUG(" ==> \"" << input << "\"");
|
||||
return _input;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ namespace etk {
|
||||
|
||||
void sortList(std::vector<std::u32string *>& _list);
|
||||
bool strnCmpNoCase(const char* _input1, const char* _input2, int32_t _maxLen);
|
||||
std::u32string simplifyPath(std::u32string _input);
|
||||
|
||||
};
|
||||
};
|
||||
|
@ -24,37 +24,9 @@ void testUChar(void) {
|
||||
|
||||
}
|
||||
|
||||
void testUString(void) {
|
||||
|
||||
for(int32_t iii=0; iii<64; iii++) {
|
||||
int64_t kkk=((int64_t)1)<<iii;
|
||||
std::u32string plop(kkk, std::u32string::printModeBinary);
|
||||
TK_DEBUG(" test : " << plop);
|
||||
}
|
||||
for(int32_t iii=0; iii<64; iii++) {
|
||||
int64_t kkk=((int64_t)1)<<iii;
|
||||
std::u32string plop(kkk, std::u32string::printModeOctal);
|
||||
TK_DEBUG(" test : " << plop);
|
||||
}
|
||||
|
||||
for(int32_t iii=0; iii<64; iii++) {
|
||||
int64_t kkk=((int64_t)1)<<iii;
|
||||
std::u32string plop(kkk, std::u32string::printModeDecimal);
|
||||
TK_DEBUG(" test : " << plop);
|
||||
int64_t resTest = plop.toInt32();
|
||||
TK_DEBUG(" test : " << resTest);
|
||||
}
|
||||
|
||||
for(int32_t iii=0; iii<64; iii++) {
|
||||
int64_t kkk=((int64_t)1)<<iii;
|
||||
std::u32string plop(kkk, std::u32string::printModeHexadecimal);
|
||||
TK_DEBUG(" test : " << plop);
|
||||
}
|
||||
}
|
||||
|
||||
void testHash(void) {
|
||||
TK_INFO("==> Start test of Hach table");
|
||||
etk::Hash<std::u32string> testData;
|
||||
etk::Hash<std::string> testData;
|
||||
testData.add("TEST", "testData");
|
||||
testData.add("TEST", "testData333");
|
||||
testData.add("TEST2", "22222222222222222");
|
||||
@ -72,32 +44,51 @@ void testHash(void) {
|
||||
|
||||
void testFSNode(void) {
|
||||
TK_INFO("==> Start test of FSNode");
|
||||
std::u32string fileName("USERDATA:myFileTest.txt");
|
||||
std::string fileName("USERDATA:myFileTest.txt");
|
||||
etk::FSNode myNodeTest1(fileName);
|
||||
TK_INFO("********************************************");
|
||||
TK_INFO("** Filename=\"" << fileName << "\"");
|
||||
TK_INFO("********************************************");
|
||||
TK_INFO(" GetNameFolder() =\"" <<myNodeTest1.getNameFolder() << "\"");
|
||||
TK_INFO(" GetName() =\"" <<myNodeTest1.getName() << "\"");
|
||||
TK_INFO(" GetNameFile() =\"" <<myNodeTest1.getNameFile() << "\"");
|
||||
TK_INFO(" GetRelativeFolder() =\"" <<myNodeTest1.getRelativeFolder() << "\"");
|
||||
TK_INFO(" exist =" <<myNodeTest1.exist());
|
||||
TK_INFO(" GetNameFolder() ='" << myNodeTest1.getNameFolder() << "'");
|
||||
TK_INFO(" GetName() ='" << myNodeTest1.getName() << "'");
|
||||
TK_INFO(" GetNameFile() ='" << myNodeTest1.getNameFile() << "'");
|
||||
TK_INFO(" GetRelativeFolder() ='" << myNodeTest1.getRelativeFolder() << "'");
|
||||
TK_INFO(" getFileSystemName() ='" << myNodeTest1.getFileSystemName() << "'");
|
||||
TK_INFO(" exist =" << myNodeTest1.exist());
|
||||
if (true==myNodeTest1.exist()) {
|
||||
TK_ERROR(" ==> remove the file ==> bad for the test");
|
||||
} else {
|
||||
TK_INFO(" Display time when file does not exist :");
|
||||
TK_INFO(" TimeCreatedString() =\"" <<myNodeTest1.timeCreatedString() << "\"");
|
||||
TK_INFO(" TimeModifiedString() =\"" <<myNodeTest1.timeModifiedString() << "\"");
|
||||
TK_INFO(" TimeAccessedString() =\"" <<myNodeTest1.timeAccessedString() << "\"");
|
||||
TK_INFO(" TimeCreatedString() ='" << myNodeTest1.timeCreatedString() << "'");
|
||||
TK_INFO(" TimeModifiedString() ='" << myNodeTest1.timeModifiedString() << "'");
|
||||
TK_INFO(" TimeAccessedString() ='" << myNodeTest1.timeAccessedString() << "'");
|
||||
}
|
||||
myNodeTest1.touch();
|
||||
if (false==myNodeTest1.exist()) {
|
||||
TK_ERROR(" ==> Error, can not create the file ....");
|
||||
} else {
|
||||
TK_INFO(" Display time when file does exist :");
|
||||
TK_INFO(" TimeCreatedString() =\"" <<myNodeTest1.timeCreatedString() << "\"");
|
||||
TK_INFO(" TimeModifiedString() =\"" <<myNodeTest1.timeModifiedString() << "\"");
|
||||
TK_INFO(" TimeAccessedString() =\"" <<myNodeTest1.timeAccessedString() << "\"");
|
||||
TK_INFO(" TimeCreatedString() ='" << myNodeTest1.timeCreatedString() << "'");
|
||||
TK_INFO(" TimeModifiedString() ='" << myNodeTest1.timeModifiedString() << "'");
|
||||
TK_INFO(" TimeAccessedString() ='" << myNodeTest1.timeAccessedString() << "'");
|
||||
}
|
||||
etk::FSNode myNodeTest2(fileName);
|
||||
TK_INFO("********************************************");
|
||||
TK_INFO("** Filename2=\"" << myNodeTest2<< "\"");
|
||||
TK_INFO("********************************************");
|
||||
TK_INFO(" GetNameFolder() ='" << myNodeTest2.getNameFolder() << "'");
|
||||
TK_INFO(" GetName() ='" << myNodeTest2.getName() << "'");
|
||||
TK_INFO(" GetNameFile() ='" << myNodeTest2.getNameFile() << "'");
|
||||
TK_INFO(" GetRelativeFolder() ='" << myNodeTest2.getRelativeFolder() << "'");
|
||||
TK_INFO(" getFileSystemName() ='" << myNodeTest2.getFileSystemName() << "'");
|
||||
TK_INFO(" exist =" << myNodeTest2.exist());
|
||||
if (false==myNodeTest1.exist()) {
|
||||
TK_ERROR(" ==> Error, can not create the file ....");
|
||||
} else {
|
||||
TK_INFO(" Display time when file does exist :");
|
||||
TK_INFO(" TimeCreatedString() ='" << myNodeTest2.timeCreatedString() << "'");
|
||||
TK_INFO(" TimeModifiedString() ='" << myNodeTest2.timeModifiedString() << "'");
|
||||
TK_INFO(" TimeAccessedString() ='" << myNodeTest2.timeAccessedString() << "'");
|
||||
}
|
||||
// Try remove the file :
|
||||
myNodeTest1.remove();
|
||||
@ -141,11 +132,13 @@ void testDimension(void) {
|
||||
int main(int argc, const char *argv[]) {
|
||||
// the only one init for etk:
|
||||
debug::setGeneralLevel(etk::logLevelVerbose);
|
||||
etk::setArgZero(argv[0]);
|
||||
etk::initDefaultFolder("ewolApplNoName");
|
||||
//testVector();
|
||||
//testUChar();
|
||||
//testUString();
|
||||
testHash();
|
||||
//testFSNode();
|
||||
testFSNode();
|
||||
//testDimension();
|
||||
testArchive();
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user