display repo priority in tool
[platform/upstream/libzypp.git] / tools / percent-encode.cc
1 #include <iostream>
2 #include <zypp/base/IOStream.h>
3 #include <zypp/url/UrlUtils.h>
4
5 static std::string doEncode( const std::string & str_r )
6 { return zypp::url::encode( str_r ); }
7
8 static std::string doDecode( const std::string & str_r )
9 { return zypp::url::decode( str_r ); }
10
11 int main( int argc, const char * argv[] )
12 {
13   bool encode( true );
14
15   --argc,++argv;
16   if ( argc )
17   {
18     if ( *argv == std::string( "-d" ) || *argv == std::string( "--decode" ) )
19       encode = false;
20     else if ( *argv == std::string( "-h" ) || *argv == std::string( "--help" ) )
21     {
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;
28       return 0;
29     }
30   }
31
32   std::string (*coder)( const std::string & str_r ) = encode ? doEncode: doDecode;
33   for( zypp::iostr::EachLine in( std::cin ); in; in.next() )
34   {
35     std::cout << coder( *in ) << std::endl;
36   }
37   return 0;
38 }