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.
5 """ Utility to remove comments from JSON files so that they can be parsed by
8 def _ReadString(input, start
, output
):
11 for pos
in xrange(start
, len(input)):
12 output
.append(input[pos
])
16 if input[pos
] == '\\':
18 elif input[pos
] == '"':
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
])
32 while pos
< len(input):
34 pos
= _ReadString(input, pos
+ 1, output
)
35 elif input[pos
:pos
+2] == '//':
36 pos
= _ReadComment(input, pos
+ 2, output
)
38 output
.append(input[pos
])
40 return ''.join(output
)