X-Git-Url: https://git.nirgal.com/?p=decoratedstr.git;a=blobdiff_plain;f=decoratedstr.py;h=1dc8737028190caf7a99f3a9ac66320ddc7e78fc;hp=50aff673004e6642a9ad68eec898c80cb9463411;hb=6ef7d1c732fe4046d0f56233c7e6682f82da139d;hpb=530b060b213233a896ee9f53c8dcf5b2d5738f11;ds=sidebyside diff --git a/decoratedstr.py b/decoratedstr.py index 50aff67..1dc8737 100755 --- a/decoratedstr.py +++ b/decoratedstr.py @@ -112,10 +112,20 @@ def decorated_match(txt, casesensitive=False): if __name__ == '__main__': import sys - if len(sys.argv)<2: + from optparse import OptionParser + parser = OptionParser(usage='%prog [options] string') + parser.add_option('--charset', help="set charset. default=%default", action='store', dest='charset', default='utf-8') + parser.add_option('-r', '--regexp', help="generate regular expression.", action='store_true', dest='regexp') + (options, args) = parser.parse_args() + + if not args: print >> sys.stderr, u'Missing required parameter. Try "Œuf"' sys.exit(1) - input = unicode(' '.join(sys.argv[1:]), 'utf-8') - print "input:", input # Œuf - print "undecorated:", remove_decoration(input) # Oeuf - print "regex:", decorated_match(input) # (œ|Œ|[oòóôöøōŏőOÒÓÔÖØŌŎŐ][eèéêëēĕėęěEÈÉÊËĒĔĖĘĚ])[uùúûüũūŭůűųUÙÚÛÜŨŪŬŮŰŲ][fF] + input = unicode(' '.join(args), options.charset) + #print "input:", input # Œuf + #print "undecorated:", remove_decoration(input) # Oeuf + #print "regex:", decorated_match(input) # (œ|Œ|[oòóôöøōŏőOÒÓÔÖØŌŎŐ][eèéêëēĕėęěEÈÉÊËĒĔĖĘĚ])[uùúûüũūŭůűųUÙÚÛÜŨŪŬŮŰŲ][fF] + if options.regexp: + print decorated_match(input).encode(options.charset) + else: + print remove_decoration(input).encode(options.charset)