blob: 1c46e3b47f0c0eb2c3a9e3e6592d4bf987cbb7c9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/text/utf8.h>
void printCodepoint(unsigned long codepoint)
{
vespalib::string data;
vespalib::Utf8Writer w(data);
w.putChar(codepoint);
printf("URL encoding of codepoint U+%04lX entity &#%lu; string value '%s' is:\n",
codepoint, codepoint, data.c_str());
for (size_t i = 0; i < data.size(); ++i) {
unsigned char byte = data[i];
printf("%%%02X", byte);
}
printf("\n");
}
int main(int argc, char **argv)
{
if (argc == 2) {
unsigned long codepoint = 0;
if (sscanf(argv[1], "U+%lx", &codepoint) == 1) {
printCodepoint(codepoint);
return 0;
} else if (sscanf(argv[1], "\\u%lx", &codepoint) == 1) {
printCodepoint(codepoint);
return 0;
}
}
fprintf(stderr, "Usage: %s U+XXXX\n", argv[0]);
return 1;
}
|