updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...] added: generic ezc functions: and, any (the same as and), or, one (the same as or), not, cmp, trim to_lower, to_upper, index changed: in misc: added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite() TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now (they were templates before) added: IsInt(), IsSize(), IsFloat() changed: version to 0.6.4 git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
139
core/misc.h
139
core/misc.h
@@ -243,94 +243,70 @@ PT::WTextStream IPToStr(int ip);
|
||||
|
||||
|
||||
|
||||
bool IsWhite(wchar_t s);
|
||||
bool IsWhite(wchar_t s, bool treat_new_line_as_white = false);
|
||||
bool IsWhite(const wchar_t * str, bool treat_new_line_as_white = false);
|
||||
bool IsWhite(const std::wstring & str, bool treat_new_line_as_white = false);
|
||||
|
||||
void TrimWhite(std::wstring & s, bool trim_new_line_too = false);
|
||||
|
||||
const wchar_t * SkipWhite(const wchar_t * s, bool treat_new_line_as_white = false);
|
||||
|
||||
|
||||
void TrimFirst(std::wstring & s, wchar_t c);
|
||||
void TrimLast(std::wstring & s, wchar_t c);
|
||||
void Trim(std::wstring & s, wchar_t c);
|
||||
|
||||
|
||||
bool IsLastSlash(const std::wstring & path);
|
||||
|
||||
template<class StringType>
|
||||
void TrimWhite(StringType & s)
|
||||
{
|
||||
typename StringType::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the end
|
||||
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
|
||||
|
||||
if( i==0 && IsWhite(s[i]) )
|
||||
{
|
||||
// the whole string has white characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting white characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, StringType::npos);
|
||||
|
||||
// looking for white characters at the beginning
|
||||
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
|
||||
|
||||
// deleting white characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
/*
|
||||
* returns true if str is an integer number
|
||||
* white strings at the beginning and at the end are ignored
|
||||
* e.g. returns true for:
|
||||
* " 10 "
|
||||
* " -20 "
|
||||
* e.g. returns false for:
|
||||
* ""
|
||||
* "- 20"
|
||||
* "z"
|
||||
*/
|
||||
bool IsInt(const wchar_t * str, bool treat_new_line_as_white = false);
|
||||
bool IsInt(const std::wstring & str, bool treat_new_line_as_white = false);
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TrimFirst(StringType & s, wchar_t c)
|
||||
{
|
||||
typename StringType::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for the 'c' characters at the beginning
|
||||
for(i=0 ; i<s.size() && s[i]==c ; ++i);
|
||||
|
||||
// deleting the 'c' characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
/*
|
||||
* returns true if str is a non-negative integer number
|
||||
* white strings at the beginning and at the end are ignored
|
||||
* e.g. returns true for:
|
||||
* " 0 "
|
||||
* " 10 "
|
||||
* " 20 "
|
||||
* e.g. returns false for:
|
||||
* ""
|
||||
* " -20 "
|
||||
* "z"
|
||||
*/
|
||||
bool IsSize(const wchar_t * str, bool treat_new_line_as_white = false);
|
||||
bool IsSize(const std::wstring & str, bool treat_new_line_as_white = false);
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TrimLast(StringType & s, wchar_t c)
|
||||
{
|
||||
typename StringType::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for the 'c' characters at the end
|
||||
for(i=s.size()-1 ; i>0 && s[i]==c ; --i);
|
||||
|
||||
if( i==0 && s[i]==c )
|
||||
{
|
||||
// the whole string has the 'c' characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting 'c' characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, StringType::npos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void Trim(StringType & s, wchar_t c)
|
||||
{
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
TrimLast(s, c);
|
||||
TrimFirst(s, c);
|
||||
}
|
||||
|
||||
/*
|
||||
* returns true if str is a floating point number
|
||||
* white strings at the beginning and at the end are ignored
|
||||
* as a decimal comma can be a dot or a comma
|
||||
* e.g. returns true for:
|
||||
* " 10 "
|
||||
* " -20.3 "
|
||||
* " 30,5 "
|
||||
* e.g. returns false for:
|
||||
* ""
|
||||
* "- 20.1"
|
||||
* "20.1.2"
|
||||
* "z"
|
||||
*/
|
||||
bool IsFloat(const wchar_t * str, bool treat_new_line_as_white = false);
|
||||
bool IsFloat(const std::wstring & str, bool treat_new_line_as_white = false);
|
||||
|
||||
|
||||
void Overwrite(std::string & str);
|
||||
@@ -391,8 +367,7 @@ bool was_comma = false;
|
||||
wchar_t ToSmall(wchar_t c);
|
||||
void ToSmall(std::wstring & s);
|
||||
|
||||
const char * SkipWhite(const char * s);
|
||||
const wchar_t * SkipWhite(const wchar_t * s);
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user