summaryrefslogblamecommitdiff
path: root/Source/Applications/Shell/Applets/rot13.cpp
blob: e5638b8f791d212f7a0fc6d9a5ca5ebbaebca88c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                   
                                                  










                                                                  




                                  
#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();
		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')) {
				c += 13;
				if (c > WChar('Z')) c -= 26;
			}
			if (c >= WChar('a') and c <= WChar('z')) {
				c += 13;
				if (c > WChar('z')) c -= 26;
			}
		}
		*out << s << ENDL;
	}
	return 0;
}