summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatish Sampath <satish@android.com>2009-06-03 15:26:05 +0100
committerSatish Sampath <satish@android.com>2009-06-03 18:00:59 +0100
commitba528383e4d840fc942d2a03f1bf748132a09048 (patch)
treefe7931e69370c2bc406eca3543d16a6c96977d39
parente178fb528229d5e2c7f3e8e8b5b9a32fc901b5bd (diff)
downloadWebSearchProvider-ba528383e4d840fc942d2a03f1bf748132a09048.tar.gz
Remove c++ comments and fix faulty regex.
- The regex to search for the pattern ' name =' or ' name=' was broken and fixed in this change. - Also added ability to look for c++ style // comments in each line and if present remove them before parsing the rest of the data. - Also added ability to detect '@' and '?' at the beginning of a string and inject a backslash before them, so that the aapt tool compiles them properly without thinking that they are references to other resources.
-rwxr-xr-xtools/get_search_engines.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/get_search_engines.py b/tools/get_search_engines.py
index 6e008d6..e3f594e 100755
--- a/tools/get_search_engines.py
+++ b/tools/get_search_engines.py
@@ -58,6 +58,8 @@ class SearchEngineManager(object):
if str.startswith('L"'):
str = str[2:]
+ if str.startswith('@') or str.startswith('?'):
+ str = '\\' + str
str = str.strip('"').replace('\\x', '&#x')
str = str.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
@@ -74,7 +76,7 @@ class SearchEngineManager(object):
"""
# Find the first occurance of this search engine name in the form
# " <name> =" in the chrome data file.
- re_exp = '\s' + name + '[\s=]'
+ re_exp = '\s' + name + '\s*='
search_obj = re.search(re_exp, self.chrome_data)
if not search_obj:
print ('Unable to find data for search engine ' + name +
@@ -86,6 +88,15 @@ class SearchEngineManager(object):
end_pos = self.chrome_data.find('};', start_pos);
engine_data_str = self.chrome_data[start_pos:end_pos]
+ # Remove c++ style '//' comments at the ends of each line
+ engine_data_lines = engine_data_str.split('\n')
+ engine_data_str = ""
+ for line in engine_data_lines:
+ start_pos = line.find(' // ')
+ if start_pos != -1:
+ line = line[:start_pos]
+ engine_data_str = engine_data_str + line + '\n'
+
# Join multiple line strings into a single string.
engine_data_str = re.sub('\"\s+\"', '', engine_data_str)
engine_data_str = re.sub('\"\s+L\"', '', engine_data_str)