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

Side by Side Diff: build/gn_helpers.py

Issue 1851723002: Let gn_helpers.py handle unicode as str (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Helper functions useful when writing scripts that integrate with GN. 5 """Helper functions useful when writing scripts that integrate with GN.
6 6
7 The main functions are ToGNString and FromGNString which convert between 7 The main functions are ToGNString and FromGNString which convert between
8 serialized GN veriables and Python variables. 8 serialized GN veriables and Python variables.
9 9
10 To use in a random python file in the build: 10 To use in a random python file in the build:
(...skipping 18 matching lines...) Expand all
29 allow_dicts indicates if this function will allow converting dictionaries 29 allow_dicts indicates if this function will allow converting dictionaries
30 to GN scopes. This is only possible at the top level, you can't nest a 30 to GN scopes. This is only possible at the top level, you can't nest a
31 GN scope in a list, so this should be set to False for recursive calls.""" 31 GN scope in a list, so this should be set to False for recursive calls."""
32 if isinstance(value, str): 32 if isinstance(value, str):
33 if value.find('\n') >= 0: 33 if value.find('\n') >= 0:
34 raise GNException("Trying to print a string with a newline in it.") 34 raise GNException("Trying to print a string with a newline in it.")
35 return '"' + \ 35 return '"' + \
36 value.replace('\\', '\\\\').replace('"', '\\"').replace('$', '\\$') + \ 36 value.replace('\\', '\\\\').replace('"', '\\"').replace('$', '\\$') + \
37 '"' 37 '"'
38 38
39 if isinstance(value, unicode):
40 return ToGNString(value.encode('utf-8'))
41
39 if isinstance(value, bool): 42 if isinstance(value, bool):
40 if value: 43 if value:
41 return "true" 44 return "true"
42 return "false" 45 return "false"
43 46
44 if isinstance(value, list): 47 if isinstance(value, list):
45 return '[ %s ]' % ', '.join(ToGNString(v) for v in value) 48 return '[ %s ]' % ', '.join(ToGNString(v) for v in value)
46 49
47 if isinstance(value, dict): 50 if isinstance(value, dict):
48 if not allow_dicts: 51 if not allow_dicts:
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 location in the input. If it does, the text is consumed and the function 282 location in the input. If it does, the text is consumed and the function
280 returns true. Otherwise, returns false and the current position is 283 returns true. Otherwise, returns false and the current position is
281 unchanged.""" 284 unchanged."""
282 end = self.cur + len(constant) 285 end = self.cur + len(constant)
283 if end > len(self.input): 286 if end > len(self.input):
284 return False # Not enough room. 287 return False # Not enough room.
285 if self.input[self.cur:end] == constant: 288 if self.input[self.cur:end] == constant:
286 self.cur = end 289 self.cur = end
287 return True 290 return True
288 return False 291 return False
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698