diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-17 23:19:17 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-17 23:19:17 +0000 |
commit | 2cb0c4539c1352c55b6fc844a9ece58dd3f962ac (patch) | |
tree | 0e86d2c44b4c34a7449259cf2a7ce9e26cdbefc7 /tools/json_comment_eater.py | |
parent | e35da7489de6f9ce605a5895f47040fa8bbe9613 (diff) | |
download | chromium_src-2cb0c4539c1352c55b6fc844a9ece58dd3f962ac.zip chromium_src-2cb0c4539c1352c55b6fc844a9ece58dd3f962ac.tar.gz chromium_src-2cb0c4539c1352c55b6fc844a9ece58dd3f962ac.tar.bz2 |
Improve performance of extension docs generation by 60%.
Review URL: http://codereview.chromium.org/9996002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_comment_eater.py')
-rwxr-xr-x | tools/json_comment_eater.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/json_comment_eater.py b/tools/json_comment_eater.py new file mode 100755 index 0000000..1b1e07a84 --- /dev/null +++ b/tools/json_comment_eater.py @@ -0,0 +1,40 @@ +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" Utility to remove comments from JSON files so that they can be parsed by +json.loads.""" + +def _ReadString(input, start, output): + output.append('"') + in_escape = False + for pos in xrange(start, len(input)): + output.append(input[pos]) + if in_escape: + in_escape = False + else: + if input[pos] == '\\': + in_escape = True + elif input[pos] == '"': + return pos + 1 + return pos + +def _ReadComment(input, start, output): + for pos in xrange(start, len(input)): + if input[pos] in ['\r', '\n']: + output.append(input[pos]) + return pos + 1 + return pos + +def Nom(input): + output = [] + pos = 0 + while pos < len(input): + if input[pos] == '"': + pos = _ReadString(input, pos + 1, output) + elif input[pos:pos+2] == '//': + pos = _ReadComment(input, pos + 2, output) + else: + output.append(input[pos]) + pos += 1 + return ''.join(output) |