added trim(...) functions to convert/text.h
void trim_first_white(std::string & str, bool check_additional_chars = true, bool treat_new_line_as_white = true); void trim_first_white(std::wstring & str, bool check_additional_chars = true, bool treat_new_line_as_white = true); void trim_last_white(std::string & str, bool check_additional_chars = true, bool treat_new_line_as_white = true); void trim_last_white(std::wstring & str, bool check_additional_chars = true, bool treat_new_line_as_white = true); void trim_white(std::string & str, bool check_additional_chars = true, bool treat_new_line_as_white = true); void trim_white(std::wstring & str, bool check_additional_chars = true, bool treat_new_line_as_white = true); void trim_first(std::string & str, wchar_t c); void trim_first(std::wstring & str, wchar_t c); void trim_last(std::string & str, wchar_t c); void trim_last(std::wstring & str, wchar_t c); void trim(std::string & str, wchar_t c); void trim(std::wstring & str, wchar_t c);
This commit is contained in:
parent
e31ef3c6c4
commit
8997284b16
|
@ -463,8 +463,76 @@ bool is_substr_nc(const std::wstring & short_str, const std::wstring & long_str)
|
|||
}
|
||||
|
||||
|
||||
void trim_first_white(std::string & str, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
pt_private::trim_first_white_generic(str, check_additional_chars, treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
void trim_first_white(std::wstring & str, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
pt_private::trim_first_white_generic(str, check_additional_chars, treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
void trim_last_white(std::string & str, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
pt_private::trim_last_white_generic(str, check_additional_chars, treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
void trim_last_white(std::wstring & str, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
pt_private::trim_last_white_generic(str, check_additional_chars, treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
void trim_white(std::string & str, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
pt_private::trim_white_generic(str, check_additional_chars, treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
void trim_white(std::wstring & str, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
pt_private::trim_white_generic(str, check_additional_chars, treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
void trim_first(std::string & str, wchar_t c)
|
||||
{
|
||||
pt_private::trim_first_generic(str, c);
|
||||
}
|
||||
|
||||
|
||||
void trim_first(std::wstring & str, wchar_t c)
|
||||
{
|
||||
pt_private::trim_first_generic(str, c);
|
||||
}
|
||||
|
||||
|
||||
void trim_last(std::string & str, wchar_t c)
|
||||
{
|
||||
pt_private::trim_last_generic(str, c);
|
||||
}
|
||||
|
||||
|
||||
void trim_last(std::wstring & str, wchar_t c)
|
||||
{
|
||||
pt_private::trim_last_generic(str, c);
|
||||
}
|
||||
|
||||
|
||||
void trim(std::string & str, wchar_t c)
|
||||
{
|
||||
pt_private::trim_generic(str, c);
|
||||
}
|
||||
|
||||
|
||||
void trim(std::wstring & str, wchar_t c)
|
||||
{
|
||||
pt_private::trim_generic(str, c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -143,6 +143,26 @@ bool is_substr_nc(const std::string & short_str, const std::string & long_str);
|
|||
bool is_substr_nc(const std::wstring & short_str, const std::wstring & long_str);
|
||||
|
||||
|
||||
void trim_first_white(std::string & str, bool check_additional_chars = true, bool treat_new_line_as_white = true);
|
||||
void trim_first_white(std::wstring & str, bool check_additional_chars = true, bool treat_new_line_as_white = true);
|
||||
|
||||
void trim_last_white(std::string & str, bool check_additional_chars = true, bool treat_new_line_as_white = true);
|
||||
void trim_last_white(std::wstring & str, bool check_additional_chars = true, bool treat_new_line_as_white = true);
|
||||
|
||||
void trim_white(std::string & str, bool check_additional_chars = true, bool treat_new_line_as_white = true);
|
||||
void trim_white(std::wstring & str, bool check_additional_chars = true, bool treat_new_line_as_white = true);
|
||||
|
||||
void trim_first(std::string & str, wchar_t c);
|
||||
void trim_first(std::wstring & str, wchar_t c);
|
||||
|
||||
void trim_last(std::string & str, wchar_t c);
|
||||
void trim_last(std::wstring & str, wchar_t c);
|
||||
|
||||
void trim(std::string & str, wchar_t c);
|
||||
void trim(std::wstring & str, wchar_t c);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -299,6 +299,112 @@ bool is_substr_nc_generic(const StringType1 * short_str, const StringType2 * lon
|
|||
|
||||
|
||||
|
||||
template<typename StringType>
|
||||
void trim_first_white_generic(StringType & s, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the beginning
|
||||
for(i=0 ; i<s.size() && is_white(s[i], check_additional_chars, treat_new_line_as_white) ; ++i);
|
||||
|
||||
// deleting white characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
|
||||
template<typename StringType>
|
||||
void trim_last_white_generic(StringType & s, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the end
|
||||
for(i=s.size()-1 ; i>0 && is_white(s[i], check_additional_chars, treat_new_line_as_white) ; --i);
|
||||
|
||||
if( i==0 && is_white(s[i], check_additional_chars, treat_new_line_as_white) )
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
template<typename StringType>
|
||||
void trim_white_generic(StringType & s, bool check_additional_chars, bool treat_new_line_as_white)
|
||||
{
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
trim_last_white_generic(s, check_additional_chars, treat_new_line_as_white);
|
||||
trim_first_white_generic(s, check_additional_chars, treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename StringType>
|
||||
void trim_first_generic(StringType & s, wchar_t c)
|
||||
{
|
||||
size_t 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);
|
||||
}
|
||||
|
||||
|
||||
template<typename StringType>
|
||||
void trim_last_generic(StringType & s, wchar_t c)
|
||||
{
|
||||
size_t 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<typename StringType>
|
||||
void trim_generic(StringType & s, wchar_t c)
|
||||
{
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
trim_last_generic(s, c);
|
||||
trim_first_generic(s, c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace pt_private
|
||||
|
||||
|
|
Loading…
Reference in New Issue