Author: jkupec Date: Wed Sep 24 19:11:06 2008 New Revision: 11148 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11148&view=rev Log: - str::escape(string, char) added - escape aliases in the history file (the rest of the values should not contain '|') Modified: trunk/libzypp/tests/zypp/base/String_test.cc trunk/libzypp/zypp/HistoryLog.cc trunk/libzypp/zypp/base/String.cc trunk/libzypp/zypp/base/String.h Modified: trunk/libzypp/tests/zypp/base/String_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/base/String_te... ============================================================================== --- trunk/libzypp/tests/zypp/base/String_test.cc (original) +++ trunk/libzypp/tests/zypp/base/String_test.cc Wed Sep 24 19:11:06 2008 @@ -85,5 +85,12 @@ v.clear(); str::splitEscaped( s, std::back_inserter(v), "o" ); BOOST_CHECK_EQUAL( s, str::joinEscaped( v.begin(), v.end(), 'o' ) ); +} + +BOOST_AUTO_TEST_CASE(test_escape) +{ + string badass = "bad|ass\|worse"; + string escaped = str::escape(badass, '|'); + BOOST_CHECK_EQUAL( escaped, "bad\|ass\\\|worse" ); } Modified: trunk/libzypp/zypp/HistoryLog.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/HistoryLog.cc?rev=11... ============================================================================== --- trunk/libzypp/zypp/HistoryLog.cc (original) +++ trunk/libzypp/zypp/HistoryLog.cc Wed Sep 24 19:11:06 2008 @@ -303,7 +303,7 @@ _log << timestamp() // 1 timestamp << _sep << HistoryActionID::REPO_REMOVE.asString(true) // 2 action - << _sep << repo.alias() // 3 alias + << _sep << str::escape(repo.alias(), _sep) // 3 alias << endl; } @@ -316,8 +316,8 @@ _log << timestamp() // 1 timestamp << _sep << HistoryActionID::REPO_CHANGE_ALIAS.asString(true) // 2 action - << _sep << oldrepo.alias() // 3 old alias - << _sep << newrepo.alias(); // 4 new alias + << _sep << str::escape(oldrepo.alias(), _sep) // 3 old alias + << _sep << str::escape(newrepo.alias(), _sep); // 4 new alias } if (*oldrepo.baseUrlsBegin() != *newrepo.baseUrlsBegin()) @@ -325,8 +325,8 @@ _log << timestamp() // 1 timestamp << _sep << HistoryActionID::REPO_CHANGE_URL.asString(true) // 2 action - << _sep << oldrepo.alias() // 3 old url - << _sep << newrepo.alias(); // 4 new url + << _sep << str::escape(oldrepo.alias(), _sep) // 3 old url + << _sep << *newrepo.baseUrlsBegin(); // 4 new url } } Modified: trunk/libzypp/zypp/base/String.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.cc?rev=1... ============================================================================== --- trunk/libzypp/zypp/base/String.cc (original) +++ trunk/libzypp/zypp/base/String.cc Wed Sep 24 19:11:06 2008 @@ -260,6 +260,30 @@ return str; } + + std::string escape( const std::string & str_r, const char sep_r ) + { + std::vector<char> buf; + for_( s, str_r.begin(), str_r.end() ) + { + switch ( *s ) + { + case '"': + case ''': + case '\': + buf.push_back( '\' ); + buf.push_back( *s ); + break; + default: + if ( *s == sep_r ) + buf.push_back( '\' ); + buf.push_back( *s ); + } + } + return std::string( buf.begin(), buf.end() ); + } + + /****************************************************************** ** ** Modified: trunk/libzypp/zypp/base/String.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.h?rev=11... ============================================================================== --- trunk/libzypp/zypp/base/String.h (original) +++ trunk/libzypp/zypp/base/String.h Wed Sep 24 19:11:06 2008 @@ -566,6 +566,17 @@ return std::string( buf.begin(), buf.end() ); } + + /** + * Escape desired character \a c using a backslash. + * + * For use when printing \a c separated values, and where + * \ref joinEscaped() is too heavy. + */ + std::string escape(const std::string & str_r, const char c = ' ' ); + + //! \todo unsecape() + //@} /////////////////////////////////////////////////////////////////// -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org