Add check before trying to second character of token

This commit is contained in:
Akbar Rahman 2019-01-18 23:05:02 +00:00
parent 75587f7b3a
commit f46662bc16
Signed by: alvierahman90
GPG Key ID: 20609519444A1269

View File

@ -11,8 +11,6 @@ def get_args():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-m", "--macros", default=["macros"], action="append", parser.add_argument("-m", "--macros", default=["macros"], action="append",
help="Extra files where macros are stored") help="Extra files where macros are stored")
parser.add_argument("-s", "--silent", default=False, action="store_true",
help="Do not print processed file")
parser.add_argument("input", help="The file to be processed") parser.add_argument("input", help="The file to be processed")
parser.add_argument("output", help="The location of the output") parser.add_argument("output", help="The location of the output")
return parser.parse_args() return parser.parse_args()
@ -58,7 +56,6 @@ def pluralize(word, macro=None):
def upper_check(token, word): def upper_check(token, word):
lowercase = False
all_caps = True all_caps = True
for letter in token: for letter in token:
@ -69,8 +66,9 @@ def upper_check(token, word):
if all_caps: if all_caps:
return word.upper() return word.upper()
if token[1].isupper(): if len(token) > 1:
return word[:1].upper() + word[1:] if token[1].isupper():
return word[:1].upper() + word[1:]
return word return word
@ -166,9 +164,6 @@ def main(args):
with open(args.output, 'w+') as file: with open(args.output, 'w+') as file:
file.write(output) file.write(output)
if not args.silent:
print(output)
return 0 return 0