[zypp-commit] r10026 - in /trunk/libzypp/zypp/base: String.cc String.h
Author: mlandres Date: Fri May 9 18:58:16 2008 New Revision: 10026 URL: http://svn.opensuse.org/viewcvs/zypp?rev=10026&view=rev Log: add str::stripLastWord Modified: trunk/libzypp/zypp/base/String.cc trunk/libzypp/zypp/base/String.h Modified: trunk/libzypp/zypp/base/String.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.cc?rev=10026&r1=10025&r2=10026&view=diff ============================================================================== --- trunk/libzypp/zypp/base/String.cc (original) +++ trunk/libzypp/zypp/base/String.cc Fri May 9 18:58:16 2008 @@ -152,12 +152,11 @@ return ret; } + /****************************************************************** ** ** FUNCTION NAME : stripFirstWord ** FUNCTION TYPE : std::string - ** - ** DESCRIPTION : */ std::string stripFirstWord( std::string & line, const bool ltrim_first ) { @@ -187,6 +186,39 @@ return ret; } + /****************************************************************** + ** + ** FUNCTION NAME : stripLastWord + ** FUNCTION TYPE : std::string + */ + std::string stripLastWord( std::string & line, const bool rtrim_first ) + { + if ( rtrim_first ) + line = rtrim( line ); + + if ( line.empty() ) + return line; + + std::string ret; + std::string::size_type p = line.find_last_of( " \t" ); + + if ( p == std::string::npos ) { + // no ws on line + ret = line; + line.erase(); + } else if ( p == line.size()-1 ) { + // ends with ws + // ret remains empty + line = rtrim( line ); + } + else { + // strip word and rtim line + ret = line.substr( p+1 ); + line = rtrim( line.erase( p ) ); + } + return ret; + } + string gsub(const string& sData, const string& sFrom, const string& sTo) { string sNew = sData; Modified: trunk/libzypp/zypp/base/String.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.h?rev=10026&r1=10025&r2=10026&view=diff ============================================================================== --- trunk/libzypp/zypp/base/String.h (original) +++ trunk/libzypp/zypp/base/String.h Fri May 9 18:58:16 2008 @@ -392,7 +392,7 @@ cont = (escCount % 2 == 1); // find some non escaped escape char cur++; //skip quote } - + std::string s( beg+1, cur-beg-2 ); //without quotes //transform escaped escape replace_all( s, "\\\\", "\\" ); @@ -419,7 +419,7 @@ std::string s( beg, cur-beg ); //transform escaped escape replace_all( s, "\\\\", "\\" ); - + const char *delimeter = sepchars_r; while ( *delimeter ) { @@ -522,6 +522,8 @@ std::string stripFirstWord( std::string & line, const bool ltrim_first ); + std::string stripLastWord( std::string & line, const bool rtrim_first ); + std::string getline( std::istream & str, bool trim = false ); std::string getline( std::istream & str, const Trim trim_r ); -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
mlandres@svn.opensuse.org