# HG changeset patch # User David Barts # Date 1579108015 28800 # Node ID dc30266d4d5ba5f044e7228abfc4ea1b858e419f # Parent a771878f6cf4d5302e22a818b76148885647f967 Add --backtick mode. diff -r a771878f6cf4 -r dc30266d4d5b curlyq --- a/curlyq Mon Dec 30 08:16:24 2019 -0800 +++ b/curlyq Wed Jan 15 09:06:55 2020 -0800 @@ -25,6 +25,11 @@ CODECS_TO_NAME[codecs.lookup(i)] = i del i +# For feet/inches/min/sec +BACKT = "`" +FTMIN = "'" +INSEC = '"' + # C l a s s e s class SafeWorkspace(Workspace): @@ -46,6 +51,7 @@ if line == "" or line == "\n": if args.force: uncurl(ws) curler.feed() + if args.backtick: fims(ws) output_fp.write(str(ws)) ws.clear() if line == "": @@ -62,6 +68,7 @@ ws.append(line) if args.force: uncurl(ws) curler.feed() + if args.backtick: fims(ws) output_fp.write(str(ws)) ws.clear() @@ -79,12 +86,25 @@ uncurl(ws) output_fp.write(str(ws)) +def fims(buf): + pos = 0 + while True: + pos = buf.find(BACKT) + if pos < 0: + break + if buf[pos+1] == BACKT: + buf[pos:pos+2] = INSEC + else: + buf[pos] = FTMIN + pos += 1 + # M a i n P r o g r a m # Parse arguments parser = argparse.ArgumentParser( description='Make straight quotes curly.', prog=MYNAME) group = parser.add_mutually_exclusive_group() +parser.add_argument("--backtick", action="store_true", help="Use backticks on input for ft/in/min/sec.") group.add_argument("--flowed", action="store_true", help="Input is flowed text.") group.add_argument("--html", action="store_true", help="Input is HTML.") group.add_argument("--uncurl", action="store_true", help="Uncurl quotes instead of curling them.") @@ -99,6 +119,11 @@ except SystemExit: sys.exit(2) +# Sanity check +if args.html and args.backtick: + sys.stderr.write(MYNAME + ": --backtick not supported in --html mode\n") + sys.exit(2) + # Sanity-check codings try: codec = codecs.lookup(args.icoding)