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 From cc74c033c19db59069f9bb5e12670e9916eadcf9 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 23 Sep 2011 12:01:21 +0200 Subject: ukrepl: add punctuation mode --- crypto/bin/ukrepl | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'crypto') diff --git a/crypto/bin/ukrepl b/crypto/bin/ukrepl index 867f1858..f40e93ea 100755 --- a/crypto/bin/ukrepl +++ b/crypto/bin/ukrepl @@ -1,11 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- import sys + wont_change = { ' ' : ' ' , '\n' : '\n' } -fixed_active = False -def fixed_width_replace(char): +def fixed_width_replace(char): #f if char in wont_change: return unicode(char) else: try: @@ -14,7 +14,6 @@ def fixed_width_replace(char): except: return char -cyr_active = False cyrillic_dict = { 'A' : u'А', 'a' : 'а','Ä' : u'Ӓ', 'ä' : u'ӓ', 'B' : u'В', @@ -32,9 +31,42 @@ cyrillic_dict = { 'T' : u'г' } -def cyrillic_replace(char): +def cyrillic_replace(char): #c return cyrillic_dict.get(char,unicode(char)) +historic_latin_dict = { + 'B' : u'Ɓ', + 'b' : u'ƅ', + 'u' : u'ư', + 'U' : u'Ư', + '' : 'Ǟ', + #'5' : 'ƽ', + 'o' : 'ơ', + 'O' : 'Ơ', + '5' : 'Ƽ' + } +def historic_latin(char): #H + return historic_latin_dict.get(char,unicode(char)) +punctuation_dict = { + '!' : u'ǃ', + '\'': u'’', + '\"': u'ˮ', + '(' : u'⟨', + ')' : u'⟩', + ':' : u'ː', + #'-' : u'‒', + #'-' : u'—', + #'-' : u'―', + #'-' : u'‐', + #'-' : u'⁃', + '-' : u'–', + '_' : u'−', + '~' : u'⁓', + #'~' : u'∼', + #'~' : u'〜', + } +def punctuation(char): #p + return punctuation_dict.get(char,unicode(char)) def helpme(): print "usage %s [modes]" % sys.argv[0] print "modes:" @@ -57,6 +89,10 @@ for line in sys.stdin: char = cyrillic_replace(char) elif mode is 'f': char = fixed_width_replace(char) + elif mode is 'H': + char = historic_latin(char) + elif mode is 'p': + char = punctuation(char) else: print "unknown mode %c" % mode helpme() -- cgit v1.2.3 From 41c07676d37dff4a46ca5e18aaa05fbe970acb63 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 23 Sep 2011 17:41:40 +0200 Subject: ukrepl: add new modes to help message punctuation and historic latin are now part of the help message --- crypto/bin/ukrepl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crypto') diff --git a/crypto/bin/ukrepl b/crypto/bin/ukrepl index f40e93ea..b3b25db9 100755 --- a/crypto/bin/ukrepl +++ b/crypto/bin/ukrepl @@ -72,6 +72,8 @@ def helpme(): print "modes:" print " c -- cyrillic replace" print " f -- fixed width" + print " p -- replace punctuation" + print " H -- replace with historic latin chars" print " h -- this message" sys.exit(0) -- cgit v1.2.3