aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/tutorial/xml_escape.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src/tests/tutorial/xml_escape.cpp')
-rw-r--r--vespalib/src/tests/tutorial/xml_escape.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/vespalib/src/tests/tutorial/xml_escape.cpp b/vespalib/src/tests/tutorial/xml_escape.cpp
new file mode 100644
index 00000000000..4bbc1445318
--- /dev/null
+++ b/vespalib/src/tests/tutorial/xml_escape.cpp
@@ -0,0 +1,19 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+int main() {
+ char c[2] = "x";
+ while (fread(&c, 1, 1, stdin) == 1) {
+ const char *out = c;
+ switch (c[0]) {
+ case '<': out = "&lt;"; break;
+ case '>': out = "&gt;"; break;
+ case '&': out = "&amp;"; break;
+ case '"': out = "&quot;"; break;
+ }
+ fwrite(out, 1, strlen(out), stdout);
+ }
+ return 0;
+}