OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 ''' Toolbar preprocessing code. Turns all IDS_COMMAND macros in the RC file | |
7 into simpler constructs that can be understood by GRIT. Also deals with | |
8 expansion of $lf; placeholders into the correct linefeed character. | |
9 ''' | |
10 | |
11 import preprocess_interface | |
12 | |
13 from grit import lazy_re | |
14 | |
15 class ToolbarPreProcessor(preprocess_interface.PreProcessor): | |
16 ''' Toolbar PreProcessing class. | |
17 ''' | |
18 | |
19 _IDS_COMMAND_MACRO = lazy_re.compile( | |
20 r'(.*IDS_COMMAND)\s*\(([a-zA-Z0-9_]*)\s*,\s*([a-zA-Z0-9_]*)\)(.*)') | |
21 _LINE_FEED_PH = lazy_re.compile(r'\$lf;') | |
22 _PH_COMMENT = lazy_re.compile(r'PHRWR') | |
23 _COMMENT = lazy_re.compile(r'^(\s*)//.*') | |
24 | |
25 | |
26 def Process(self, rctext, rcpath): | |
27 ''' Processes the data in rctext. | |
28 Args: | |
29 rctext: string containing the contents of the RC file being processed | |
30 rcpath: the path used to access the file. | |
31 | |
32 Return: | |
33 The processed text. | |
34 ''' | |
35 | |
36 ret = '' | |
37 rclines = rctext.splitlines() | |
38 for line in rclines: | |
39 | |
40 if self._LINE_FEED_PH.search(line): | |
41 # Replace "$lf;" placeholder comments by an empty line. | |
42 # this will not be put into the processed result | |
43 if self._PH_COMMENT.search(line): | |
44 mm = self._COMMENT.search(line) | |
45 if mm: | |
46 line = '%s//' % mm.group(1) | |
47 | |
48 else: | |
49 # Replace $lf by the right linefeed character | |
50 line = self._LINE_FEED_PH.sub(r'\\n', line) | |
51 | |
52 # Deal with IDS_COMMAND_MACRO stuff | |
53 mo = self._IDS_COMMAND_MACRO.search(line) | |
54 if mo: | |
55 line = '%s_%s_%s%s' % (mo.group(1), mo.group(2), mo.group(3), mo.group(4
)) | |
56 | |
57 ret += (line + '\n') | |
58 | |
59 return ret | |
60 | |
61 | |
OLD | NEW |