diff options
Diffstat (limited to 'vespalib/src/tests/text/utf8/make_url.cpp')
-rw-r--r-- | vespalib/src/tests/text/utf8/make_url.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vespalib/src/tests/text/utf8/make_url.cpp b/vespalib/src/tests/text/utf8/make_url.cpp new file mode 100644 index 00000000000..29b0cf5dcc2 --- /dev/null +++ b/vespalib/src/tests/text/utf8/make_url.cpp @@ -0,0 +1,34 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#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; +} |