summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2011-09-22 23:02:57 +0200
committermakefu <github@syntax-fehler.de>2011-09-22 23:02:57 +0200
commit7d3d099f8de3891e897112906d47cd8428d27122 (patch)
treedd3c0baf1d6ddba906f132a98098aeef4451e04a /crypto
parentec72c5e1d4e0478879e7b679a0ea082ffc644456 (diff)
ukrepl: chain modes
ukrepl is able to chain modes e.g. echo "aidsballs" | ./ukrepl cf => а і d s b а l l s
Diffstat (limited to 'crypto')
-rwxr-xr-xcrypto/bin/ukrepl21
1 files changed, 11 insertions, 10 deletions
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,