asio 0.3.8rc3 | Home | Reference | Tutorial | Examples | Design

Examples |

# http/server/test.cpp File Reference

Go to the source code of this file.

## Functions

bool | url_decode (const std::string &in, std::string &out)
int | main ()

## Function Documentation

bool url_decode | ( | const std::string & | in,
|  | std::string & | out |
| ) |  |  |

Definition at line 4 of file test.cpp.

Referenced by main().

    00005 {
    00006   out.clear();
    00007   out.reserve(in.size());
    00008   for (std::size_t i = 0; i < in.size(); ++i)
    00009   {
    00010     if (in[i] == '%')
    00011     {
    00012       if (i + 3 <= in.size())
    00013       {
    00014         int value;
    00015         std::istringstream is(in.substr(i + 1, 2));
    00016         if (is >> std::hex >> value)
    00017         {
    00018           out += static_cast<char>(value);
    00019           i += 2;
    00020         }
    00021         else
    00022         {
    00023           return false;
    00024         }
    00025       }
    00026       else
    00027       {
    00028         return false;
    00029       }
    00030     }
    00031     else
    00032     {
    00033       out += in[i];
    00034     }
    00035   }
    00036   return true;
    00037 }

int main | ( |  | ) |

Definition at line 39 of file test.cpp.

    00040 {
    00041   std::string out;
    00042   url_decode("%FE%FE%FE", out);
    00043   return 0;
    00044 }

asio 0.3.8rc3 | Home | Reference | Tutorial | Examples | Design