| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 Google Inc. All rights reserved. | 2 # Copyright (c) 2011 Google Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 ref_types = {} | 55 ref_types = {} |
| 56 | 56 |
| 57 def full_qualified_type_id(domain_name, type_id): | 57 def full_qualified_type_id(domain_name, type_id): |
| 58 if type_id.find(".") == -1: | 58 if type_id.find(".") == -1: |
| 59 return "%s.%s" % (domain_name, type_id) | 59 return "%s.%s" % (domain_name, type_id) |
| 60 return type_id | 60 return type_id |
| 61 | 61 |
| 62 | 62 |
| 63 def fix_camel_case(name): | 63 def fix_camel_case(name): |
| 64 prefix = "" |
| 65 if name[0] == "-": |
| 66 prefix = "Negative" |
| 67 name = name[1:] |
| 64 refined = re.sub(r'-(\w)', lambda pat: pat.group(1).upper(), name) | 68 refined = re.sub(r'-(\w)', lambda pat: pat.group(1).upper(), name) |
| 65 refined = to_title_case(refined) | 69 refined = to_title_case(refined) |
| 66 return re.sub(r'(?i)HTML|XML|WML|API', lambda pat: pat.group(0).upper(), ref
ined) | 70 return prefix + re.sub(r'(?i)HTML|XML|WML|API', lambda pat: pat.group(0).upp
er(), refined) |
| 67 | 71 |
| 68 | 72 |
| 69 def to_title_case(name): | 73 def to_title_case(name): |
| 70 return name[:1].upper() + name[1:] | 74 return name[:1].upper() + name[1:] |
| 71 | 75 |
| 72 | 76 |
| 73 def generate_enum(name, json): | 77 def generate_enum(name, json): |
| 74 enum_members = [] | 78 enum_members = [] |
| 75 for member in json["enum"]: | 79 for member in json["enum"]: |
| 76 enum_members.append(" %s: \"%s\"" % (fix_camel_case(member), member)) | 80 enum_members.append(" %s: \"%s\"" % (fix_camel_case(member), member)) |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 import sys | 242 import sys |
| 239 import os.path | 243 import os.path |
| 240 program_name = os.path.basename(__file__) | 244 program_name = os.path.basename(__file__) |
| 241 if len(sys.argv) < 5 or sys.argv[1] != "-o": | 245 if len(sys.argv) < 5 or sys.argv[1] != "-o": |
| 242 sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE_1 INPUT_FILE_2\n"
% program_name) | 246 sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE_1 INPUT_FILE_2\n"
% program_name) |
| 243 exit(1) | 247 exit(1) |
| 244 output_path = sys.argv[2] | 248 output_path = sys.argv[2] |
| 245 input_path_1 = sys.argv[3] | 249 input_path_1 = sys.argv[3] |
| 246 input_path_2 = sys.argv[4] | 250 input_path_2 = sys.argv[4] |
| 247 generate_protocol_externs(output_path, input_path_1, input_path_2) | 251 generate_protocol_externs(output_path, input_path_1, input_path_2) |
| OLD | NEW |