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

Side by Side Diff: pylib/gyp/xcodeproj_file.py

Issue 23892016: Fix XCObject._EncodeString() for unicode characters. (Closed) Base URL: http://gyp.googlecode.com/svn/trunk
Patch Set: Check tab escaping.wq Created 7 years, 3 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
« no previous file with comments | « no previous file | test/mac/gyptest-unicode-settings.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 Google Inc. 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 """Xcode project file generator. 5 """Xcode project file generator.
6 6
7 This module is both an Xcode project file generator and a documentation of the 7 This module is both an Xcode project file generator and a documentation of the
8 Xcode project file format. Knowledge of the project file format was gained 8 Xcode project file format. Knowledge of the project file format was gained
9 based on extensive experience with Xcode, and by making changes to projects in 9 based on extensive experience with Xcode, and by making changes to projects in
10 Xcode.app and observing the resultant changes in the associated project files. 10 Xcode.app and observing the resultant changes in the associated project files.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 # characters listed with "+", for 1 or more occurrences: if a string is empty, 162 # characters listed with "+", for 1 or more occurrences: if a string is empty,
163 # it must not match this pattern, because it needs to be encoded as "". 163 # it must not match this pattern, because it needs to be encoded as "".
164 _unquoted = re.compile('^[A-Za-z0-9$./_]+$') 164 _unquoted = re.compile('^[A-Za-z0-9$./_]+$')
165 165
166 # Strings that match this pattern are quoted regardless of what _unquoted says. 166 # Strings that match this pattern are quoted regardless of what _unquoted says.
167 # Oddly, Xcode will quote any string with a run of three or more underscores. 167 # Oddly, Xcode will quote any string with a run of three or more underscores.
168 _quoted = re.compile('___') 168 _quoted = re.compile('___')
169 169
170 # This pattern should match any character that needs to be escaped by 170 # This pattern should match any character that needs to be escaped by
171 # XCObject._EncodeString. See that function. 171 # XCObject._EncodeString. See that function.
172 _escaped = re.compile('[\\\\"]|[^ -~]') 172 _escaped = re.compile('[\\\\"]|[\x00-\x1f]')
173 173
174 174
175 # Used by SourceTreeAndPathFromPath 175 # Used by SourceTreeAndPathFromPath
176 _path_leading_variable = re.compile('^\$\((.*?)\)(/(.*))?$') 176 _path_leading_variable = re.compile('^\$\((.*?)\)(/(.*))?$')
177 177
178 def SourceTreeAndPathFromPath(input_path): 178 def SourceTreeAndPathFromPath(input_path):
179 """Given input_path, returns a tuple with sourceTree and path values. 179 """Given input_path, returns a tuple with sourceTree and path values.
180 180
181 Examples: 181 Examples:
182 input_path (source_tree, output_path) 182 input_path (source_tree, output_path)
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 # 127 ^? DEL is passed through as-is without escaping 550 # 127 ^? DEL is passed through as-is without escaping
551 # - In PBXFileReference and PBXBuildFile objects: 551 # - In PBXFileReference and PBXBuildFile objects:
552 # 9 ^I HT is passed through as-is without escaping 552 # 9 ^I HT is passed through as-is without escaping
553 # 10 ^J NL is passed through as-is without escaping 553 # 10 ^J NL is passed through as-is without escaping
554 # 13 ^M CR is passed through as-is without escaping 554 # 13 ^M CR is passed through as-is without escaping
555 # - In other objects: 555 # - In other objects:
556 # 9 ^I HT is encoded as "\t" 556 # 9 ^I HT is encoded as "\t"
557 # 10 ^J NL is encoded as "\n" 557 # 10 ^J NL is encoded as "\n"
558 # 13 ^M CR is encoded as "\n" rendering it indistinguishable from 558 # 13 ^M CR is encoded as "\n" rendering it indistinguishable from
559 # 10 ^J NL 559 # 10 ^J NL
560 # All other nonprintable characters within the ASCII range (0 through 127 560 # All other characters within the ASCII control character range (0 through
561 # inclusive) are encoded as "\U001f" referring to the Unicode code point in 561 # 31 inclusive) are encoded as "\U001f" referring to the Unicode code point
562 # hexadecimal. For example, character 14 (^N SO) is encoded as "\U000e". 562 # in hexadecimal. For example, character 14 (^N SO) is encoded as "\U000e".
563 # Characters above the ASCII range are passed through to the output encoded 563 # Characters above the ASCII range are passed through to the output encoded
564 # as UTF-8 without any escaping. These mappings are contained in the 564 # as UTF-8 without any escaping. These mappings are contained in the
565 # class' _encode_transforms list. 565 # class' _encode_transforms list.
566 566
567 if _unquoted.search(value) and not _quoted.search(value): 567 if _unquoted.search(value) and not _quoted.search(value):
568 return value 568 return value
569 569
570 return '"' + _escaped.sub(self._EncodeTransform, value) + '"' 570 return '"' + _escaped.sub(self._EncodeTransform, value) + '"'
571 571
572 def _XCPrint(self, file, tabs, line): 572 def _XCPrint(self, file, tabs, line):
(...skipping 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 self._XCPrint(file, 0, '/* Begin ' + class_name + ' section */\n') 2861 self._XCPrint(file, 0, '/* Begin ' + class_name + ' section */\n')
2862 for object in sorted(objects_by_class[class_name], 2862 for object in sorted(objects_by_class[class_name],
2863 cmp=lambda x, y: cmp(x.id, y.id)): 2863 cmp=lambda x, y: cmp(x.id, y.id)):
2864 object.Print(file) 2864 object.Print(file)
2865 self._XCPrint(file, 0, '/* End ' + class_name + ' section */\n') 2865 self._XCPrint(file, 0, '/* End ' + class_name + ' section */\n')
2866 2866
2867 if self._should_print_single_line: 2867 if self._should_print_single_line:
2868 self._XCPrint(file, 0, '}; ') 2868 self._XCPrint(file, 0, '}; ')
2869 else: 2869 else:
2870 self._XCPrint(file, 1, '};\n') 2870 self._XCPrint(file, 1, '};\n')
OLDNEW
« no previous file with comments | « no previous file | test/mac/gyptest-unicode-settings.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698