summaryrefslogtreecommitdiff
path: root/Source/Applications/Shell/Applets/rot13.cpp
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-12-20 19:39:46 +0100
committerAlexis211 <alexis211@gmail.com>2009-12-20 19:39:46 +0100
commit1d301e54da75b90172d129594265f2b629f3125a (patch)
tree1eb918a01ef7677c4328ef1d23a2538647448f0b /Source/Applications/Shell/Applets/rot13.cpp
parent13d720389a01161a327a30918ad7ac9eec4a3d6c (diff)
downloadMelon-1d301e54da75b90172d129594265f2b629f3125a.tar.gz
Melon-1d301e54da75b90172d129594265f2b629f3125a.zip
rot13, demo app for StreamApp, is working :)
Diffstat (limited to 'Source/Applications/Shell/Applets/rot13.cpp')
-rw-r--r--Source/Applications/Shell/Applets/rot13.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/Source/Applications/Shell/Applets/rot13.cpp b/Source/Applications/Shell/Applets/rot13.cpp
new file mode 100644
index 0000000..79c2124
--- /dev/null
+++ b/Source/Applications/Shell/Applets/rot13.cpp
@@ -0,0 +1,30 @@
+#include <App/StreamApp.proto.h>
+
+class rot13 : public StreamApp {
+ public:
+ rot13() : StreamApp("rot13", "Cat a file, but ROT13 it") {}
+ int run();
+};
+
+APP(rot13);
+
+int rot13::run() {
+ while (!in->eof()) {
+ String s = in->get();
+ for (u32int i = 0; i < s.size(); i++) {
+ WChar &c = s[i];
+ if (c >= WChar('A') and c <= WChar('Z')) {
+ c += 13;
+ if (c > WChar('Z')) c -= 26;
+ }
+ if (c >= WChar('a') and c <= WChar('z')) {
+ c += 13;
+ if (c > WChar('z')) c -= 26;
+ }
+ }
+ if (in->eof() && s.empty()) break;
+ *out << s << ENDL;
+ }
+ return 0;
+}
+