Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: tools/json_comment_eater.py

Issue 13599004: Fix some low hanging inefficiencies in the docs server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """ Utility to remove comments from JSON files so that they can be parsed by
6 json.loads."""
7
8 def _ReadString(input, start, output):
9 output.append('"')
10 in_escape = False
11 for pos in xrange(start, len(input)):
12 output.append(input[pos])
13 if in_escape:
14 in_escape = False
15 else:
16 if input[pos] == '\\':
17 in_escape = True
18 elif input[pos] == '"':
19 return pos + 1
20 return pos
21
22 def _ReadComment(input, start, output):
23 for pos in xrange(start, len(input)):
24 if input[pos] in ['\r', '\n']:
25 output.append(input[pos])
26 return pos + 1
27 return pos
28
29 def Nom(input):
30 output = []
31 pos = 0
32 while pos < len(input):
33 if input[pos] == '"':
34 pos = _ReadString(input, pos + 1, output)
35 elif input[pos:pos+2] == '//':
36 pos = _ReadComment(input, pos + 2, output)
37 else:
38 output.append(input[pos])
39 pos += 1
40 return ''.join(output)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/preview.py ('k') | tools/json_comment_eater/everything.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698