fc::vector<header> parse_urlencoded_params( const fc::string& f ) { int num_args = 0; for( size_t i = 0; i < f.size(); ++i ) { if( f[i] == '=' ) ++num_args; } fc::vector<header> h(num_args); int arg = 0; for( size_t i = 0; i < f.size(); ++i ) { while( f[i] != '=' && i < f.size() ) { if( f[i] == '%' ) { h[arg].key += char((fc::from_hex(f[i+1]) << 4) | fc::from_hex(f[i+2])); i += 3; } else { h[arg].key += f[i]; ++i; } } ++i; while( i < f.size() && f[i] != '&' ) { if( f[i] == '%' ) { h[arg].val += char((fc::from_hex(f[i+1]) << 4) | fc::from_hex(f[i+2])); i += 3; } else { h[arg].val += f[i] == '+' ? ' ' : f[i]; ++i; } } ++arg; } return h; }
fc::string pretty_print( const fc::string& v, uint8_t indent ) { int level = 0; fc::stringstream ss; bool first = false; bool quote = false; bool escape = false; for( uint32_t i = 0; i < v.size(); ++i ) { switch( v[i] ) { case '\\': if( !escape ) { if( quote ) escape = true; } else { escape = false; } ss<<v[i]; break; case ':': if( !quote ) { ss<<": "; } else { ss<<':'; } break; case '"': if( first ) { ss<<'\n'; for( int i = 0; i < level*indent; ++i ) ss<<' '; first = false; } if( !escape ) { quote = !quote; } escape = false; ss<<'"'; break; case '{': case '[': ss<<v[i]; if( !quote ) { ++level; first = true; }else { escape = false; } break; case '}': case ']': if( !quote ) { if( v[i-1] != '[' && v[i-1] != '{' ) { ss<<'\n'; } --level; if( !first ) { for( int i = 0; i < level*indent; ++i ) ss<<' '; } first = false; ss<<v[i]; break; } else { escape = false; ss<<v[i]; } break; case ',': if( !quote ) { ss<<','; first = true; } else { escape = false; ss<<','; } break; case 'n': //If we're in quotes and see a \n, just print it literally but unset the escape flag. if( quote && escape ) escape = false; //No break; fall through to default case default: if( first ) { ss<<'\n'; for( int i = 0; i < level*indent; ++i ) ss<<' '; first = false; } ss << v[i]; } } return ss.str(); }