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

Side by Side Diff: grit/tool/toolbar_preprocess.py

Issue 7994004: Initial source commit to grit-i18n project. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 9 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 | « grit/tool/toolbar_postprocess.py ('k') | grit/tool/transl2tc.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 # Copyright (c) 2006-2008 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 import re
14 import sys
15 import codecs
16
17 class ToolbarPreProcessor(preprocess_interface.PreProcessor):
18 ''' Toolbar PreProcessing class.
19 '''
20
21 _IDS_COMMAND_MACRO = re.compile(r'(.*IDS_COMMAND)\s*\(([a-zA-Z0-9_]*)\s*,\s*([ a-zA-Z0-9_]*)\)(.*)')
22 _LINE_FEED_PH = re.compile(r'\$lf;')
23 _PH_COMMENT = re.compile(r'PHRWR')
24 _COMMENT = re.compile(r'^(\s*)//.*')
25
26
27 def Process(self, rctext, rcpath):
28 ''' Processes the data in rctext.
29 Args:
30 rctext: string containing the contents of the RC file being processed
31 rcpath: the path used to access the file.
32
33 Return:
34 The processed text.
35 '''
36
37 ret = ''
38 rclines = rctext.splitlines()
39 for line in rclines:
40
41 if self._LINE_FEED_PH.search(line):
42 # Replace "$lf;" placeholder comments by an empty line.
43 # this will not be put into the processed result
44 if self._PH_COMMENT.search(line):
45 mm = self._COMMENT.search(line)
46 if mm:
47 line = '%s//' % mm.group(1)
48
49 else:
50 # Replace $lf by the right linefeed character
51 line = self._LINE_FEED_PH.sub(r'\\n', line)
52
53 # Deal with IDS_COMMAND_MACRO stuff
54 mo = self._IDS_COMMAND_MACRO.search(line)
55 if mo:
56 line = '%s_%s_%s%s' % (mo.group(1), mo.group(2), mo.group(3), mo.group(4 ))
57
58 ret += (line + '\n')
59
60 return ret
61
62
OLDNEW
« no previous file with comments | « grit/tool/toolbar_postprocess.py ('k') | grit/tool/transl2tc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698