Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #define w2c(x) ( (char) ((x) & 0x00FF) )
- #define is_uri_ch(x) ( ((x)>32) && ((x)<128) ) // uwaga! nie odporne na skutki uboczne
- using namespace std;
- void _hex2_(wchar_t in, char* out) {
- static char lookup[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- int tmp; tmp = in & 0x000000FF; int first = tmp / 16; int second = tmp % 16;
- out[0] = lookup[first]; out[1] = lookup[second];
- }
- void hex(wchar_t* in, char* out, int max) {
- int i=0, max2=max-3, j=0;
- while(in[i]!=0) {
- if (j<max2) {
- if (is_uri_ch(in[i])) { out[j] = w2c(in[i]); ++j; }
- else { out[j] = '%'; _hex2_(in[i], out+j+1); j+=3; }
- }
- ++i;
- }
- out[j+1] = 0;
- }
- int main() {
- char buf[100];
- wchar_t uri[] = L"gżegżółka";
- hex(uri, buf, 100);
- cout << buf << endl;
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement