MCPcopy Index your code
hub / github.com/nodejs/node / _CopyStringsFile

Method _CopyStringsFile

tools/gyp/pylib/gyp/mac_tool.py:134–153  ·  view source on GitHub ↗

Copies a .strings file using iconv to reconvert the input into UTF-16.

(self, source, dest)

Source from the content-addressed store, hash-verified

132 )
133
134 def _CopyStringsFile(self, source, dest):
135 """Copies a .strings file using iconv to reconvert the input into UTF-16."""
136 input_code = self._DetectInputEncoding(source) or "UTF-8"
137
138 # Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call
139 # CFPropertyListCreateFromXMLData() behind the scenes; at least it prints
140 # CFPropertyListCreateFromXMLData(): Old-style plist parser: missing
141 # semicolon in dictionary.
142 # on invalid files. Do the same kind of validation.
143 import CoreFoundation # noqa: PLC0415
144
145 with open(source, "rb") as in_file:
146 s = in_file.read()
147 d = CoreFoundation.CFDataCreate(None, s, len(s))
148 _, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None)
149 if error:
150 return
151
152 with open(dest, "wb") as fp:
153 fp.write(s.decode(input_code).encode("UTF-16"))
154
155 def _DetectInputEncoding(self, file_name):
156 """Reads the first few bytes from file_name and tries to guess the text

Callers 1

Calls 6

_DetectInputEncodingMethod · 0.95
encodeMethod · 0.80
decodeMethod · 0.65
openFunction · 0.50
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected