added: to convert/text
wchar_t ToLower(wchar_t c) wchar_t ToUpper(wchar_t c) void ToLower(std::wstring & s) void ToUpper(std::wstring & s) template<class StringType1, class StringType2> bool EqualNoCase(const StringType1 * str1, const StringType2 * str2) template<class StringType1, class StringType2> bool EqualNoCase(const StringType1 & str1, const StringType2 & str2) template<class StringType1, class StringType2> bool EqualNoCase(const StringType1 * str1_begin, const StringType1 * str1_end, const StringType2 * str2) added: to space: Value * GetValueNoCase(const wchar_t * name); Value * GetValueNoCase(const std::wstring & name); const Value * GetValueNoCase(const wchar_t * name) const; const Value * GetValueNoCase(const std::wstring & name) const; git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1111 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
102
space/space.cpp
102
space/space.cpp
@@ -149,6 +149,53 @@ const Space::Value * Space::GetValue(const std::wstring & name) const
|
||||
|
||||
|
||||
|
||||
Space::Value * Space::GetValueNoCase(const wchar_t * name)
|
||||
{
|
||||
tmp_name = name;
|
||||
return GetValueNoCase(tmp_name);
|
||||
}
|
||||
|
||||
|
||||
Space::Value * Space::GetValueNoCase(const std::wstring & name)
|
||||
{
|
||||
Table::iterator t = table.begin();
|
||||
|
||||
for( ; t != table.end() ; ++t)
|
||||
{
|
||||
if( PT::EqualNoCase(t->first, name) )
|
||||
{
|
||||
return &t->second;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const Space::Value * Space::GetValueNoCase(const wchar_t * name) const
|
||||
{
|
||||
tmp_name = name;
|
||||
return GetValueNoCase(tmp_name);
|
||||
}
|
||||
|
||||
|
||||
const Space::Value * Space::GetValueNoCase(const std::wstring & name) const
|
||||
{
|
||||
Table::const_iterator t = table.begin();
|
||||
|
||||
for( ; t != table.end() ; ++t)
|
||||
{
|
||||
if( PT::EqualNoCase(t->first, name) )
|
||||
{
|
||||
return &t->second;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::wstring * Space::GetFirstValue(const wchar_t * name)
|
||||
{
|
||||
@@ -461,9 +508,9 @@ bool Space::ToBool(const std::wstring & value)
|
||||
const wchar_t * str_begin = SkipWhite(value.c_str());
|
||||
const wchar_t * str_end = SkipWhiteFromBack(str_begin);
|
||||
|
||||
return (EqualNoCase(str_begin, str_end, L"true") ||
|
||||
EqualNoCase(str_begin, str_end, L"yes") ||
|
||||
EqualNoCase(str_begin, str_end, L"1")
|
||||
return (PT::EqualNoCase(str_begin, str_end, L"true") ||
|
||||
PT::EqualNoCase(str_begin, str_end, L"yes") ||
|
||||
PT::EqualNoCase(str_begin, str_end, L"1")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1007,55 +1054,6 @@ bool Space::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||
|
||||
|
||||
|
||||
wchar_t Space::ToSmall(wchar_t c)
|
||||
{
|
||||
if( c >= 'A' && c <= 'Z' )
|
||||
c = c - 'A' + 'a';
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
// IMPROVE ME
|
||||
// move me to a better place
|
||||
bool Space::EqualNoCase(const wchar_t * str1, const wchar_t * str2)
|
||||
{
|
||||
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
|
||||
{
|
||||
++str1;
|
||||
++str2;
|
||||
}
|
||||
|
||||
if( *str1 == 0 && *str2 == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* the first string is trimmed
|
||||
* str1_end is pointing one character after the last valid character
|
||||
*
|
||||
*/
|
||||
// IMPROVE ME
|
||||
// move me to a better place
|
||||
bool Space::EqualNoCase(const wchar_t * str1_begin, const wchar_t * str1_end, const wchar_t * str2)
|
||||
{
|
||||
while( str1_begin < str1_end && *str2 && ToSmall(*str1_begin) == ToSmall(*str2) )
|
||||
{
|
||||
++str1_begin;
|
||||
++str2;
|
||||
}
|
||||
|
||||
if( str1_begin == str1_end && *str2 == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
those white characters here should be the same as in spaceparser.cpp
|
||||
*/
|
||||
|
Reference in New Issue
Block a user