2 #include <zypp/base/IOStream.h>
3 #include <zypp/url/UrlUtils.h>
5 static std::string doEncode( const std::string & str_r )
6 { return zypp::url::encode( str_r ); }
8 static std::string doDecode( const std::string & str_r )
9 { return zypp::url::decode( str_r ); }
11 int main( int argc, const char * argv[] )
18 if ( *argv == std::string( "-d" ) || *argv == std::string( "--decode" ) )
20 else if ( *argv == std::string( "-h" ) || *argv == std::string( "--help" ) )
22 std::cout << "Usage: percent-encode [OPTION]" << std::endl;
23 std::cout << "Read lines from stdin and write them percent encoded to stdout." << std::endl;
24 std::cout << "" << std::endl;
25 std::cout << "Option:" << std::endl;
26 std::cout << " -d, --decode Decode lines read from stdin instead of encoding them." << std::endl;
27 std::cout << " -h --help Print this message." << std::endl;
32 std::string (*coder)( const std::string & str_r ) = encode ? doEncode: doDecode;
33 for( zypp::iostr::EachLine in( std::cin ); in; in.next() )
35 std::cout << coder( *in ) << std::endl;