From 1d301e54da75b90172d129594265f2b629f3125a Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 20 Dec 2009 19:39:46 +0100 Subject: rot13, demo app for StreamApp, is working :) --- Source/Applications/Shell/Applets/rot13.cpp | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Source/Applications/Shell/Applets/rot13.cpp (limited to 'Source/Applications/Shell/Applets/rot13.cpp') 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 + +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; +} + -- cgit v1.2.3 From 18454dc8be12827a84c2ebc58aa5d31bb44e1e6a Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 20 Dec 2009 19:58:34 +0100 Subject: Some reorganisation --- Source/Applications/Shell/Applets/rot13.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Applications/Shell/Applets/rot13.cpp') diff --git a/Source/Applications/Shell/Applets/rot13.cpp b/Source/Applications/Shell/Applets/rot13.cpp index 79c2124..e5638b8 100644 --- a/Source/Applications/Shell/Applets/rot13.cpp +++ b/Source/Applications/Shell/Applets/rot13.cpp @@ -11,6 +11,7 @@ APP(rot13); int rot13::run() { while (!in->eof()) { String s = in->get(); + if (in->eof() && s.empty()) break; for (u32int i = 0; i < s.size(); i++) { WChar &c = s[i]; if (c >= WChar('A') and c <= WChar('Z')) { @@ -22,7 +23,6 @@ int rot13::run() { if (c > WChar('z')) c -= 26; } } - if (in->eof() && s.empty()) break; *out << s << ENDL; } return 0; -- cgit v1.2.3