From 7d3d099f8de3891e897112906d47cd8428d27122 Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 22 Sep 2011 23:02:57 +0200 Subject: ukrepl: chain modes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ukrepl is able to chain modes e.g. echo "aidsballs" | ./ukrepl cf => а і d s b а l l s --- crypto/bin/ukrepl | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'crypto') diff --git a/crypto/bin/ukrepl b/crypto/bin/ukrepl index 21aa4d84..867f1858 100755 --- a/crypto/bin/ukrepl +++ b/crypto/bin/ukrepl @@ -6,12 +6,13 @@ wont_change = { ' ' : ' ' , } fixed_active = False def fixed_width_replace(char): - if char in wont_change: print char, + if char in wont_change: return unicode(char) else: try: - print unichr(0xFF00 + ord(char)-32), + if not 32 < ord(char) < 126: raise Exception("not in range") + return unichr(0xFF00 + ord(char)-32) except: - print char, + return char cyr_active = False cyrillic_dict = { @@ -32,7 +33,7 @@ cyrillic_dict = { } def cyrillic_replace(char): - print cyrillic_dict.get(char,char), + return cyrillic_dict.get(char,unicode(char)) def helpme(): print "usage %s [modes]" % sys.argv[0] @@ -49,14 +50,14 @@ if not modes : modes = "f" if 'h' in modes: helpme() -for mode in modes: - for line in sys.stdin: - for char in line: +for line in sys.stdin: + for char in line: + for mode in modes: if mode is 'c': - cyrillic_replace(char) + char = cyrillic_replace(char) elif mode is 'f': - fixed_width_replace(char) + char = fixed_width_replace(char) else: print "unknown mode %c" % mode helpme() - + print char, -- cgit v1.2.3