Calendar Picker: remove unnecessary code from calendarPicker.{css,js}
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2012 06:33:14 +0000 (06:33 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2012 06:33:14 +0000 (06:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=83685

Reviewed by Kentaro Hara.

Remove the followings from input files:
 - multi line comments /*...*/ (.js and .css)
 - single line comment //... (.js)
 - repeating whitespace (.js and .css)
 - leading and trailing whitespace (.js and .css)
 - empty lines (.js and .css)

This doesn't work for arbitrary JavaScript or CSS inputs, but
works well for expected input files like
css/make-css-file-arrays.pl

* make-file-arrays.py:
(strip_whitespace_and_comments):
(main):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114090 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/make-file-arrays.py

index 0b368a1..993b703 100644 (file)
@@ -1,3 +1,25 @@
+2012-04-12  Kent Tamura  <tkent@chromium.org>
+
+        Calendar Picker: remove unnecessary code from calendarPicker.{css,js}
+        https://bugs.webkit.org/show_bug.cgi?id=83685
+
+        Reviewed by Kentaro Hara.
+
+        Remove the followings from input files:
+         - multi line comments /*...*/ (.js and .css)
+         - single line comment //... (.js)
+         - repeating whitespace (.js and .css)
+         - leading and trailing whitespace (.js and .css)
+         - empty lines (.js and .css)
+
+        This doesn't work for arbitrary JavaScript or CSS inputs, but
+        works well for expected input files like
+        css/make-css-file-arrays.pl
+
+        * make-file-arrays.py:
+        (strip_whitespace_and_comments):
+        (main):
+
 2012-04-12  Sailesh Agrawal  <sail@chromium.org>
 
         Chromium: Fix scrollbar tickmark drawing on Mountain Lion
index 99b4dbe..ece706b 100755 (executable)
@@ -47,6 +47,34 @@ def make_variable_name_and_read(file_name):
     return (variable_name, content)
 
 
+def strip_whitespace_and_comments(file_name, content):
+    result = re.match(r".*\.([^.]+)", file_name)
+    if not result:
+        print "The file name has no extension:", file_name
+        sys.exit(1)
+    extension = result.group(1).lower()
+    multi_line_comment = re.compile(r"/\*.*?\*/", re.MULTILINE | re.DOTALL)
+    single_line_comment = re.compile(r"//.*$", re.MULTILINE)
+    repeating_space = re.compile(r"[ \t]+", re.MULTILINE)
+    leading_space = re.compile(r"^[ \t]+", re.MULTILINE)
+    trailing_space = re.compile(r"[ \t]+$", re.MULTILINE)
+    empty_line = re.compile(r"\n+")
+    if extension == "js":
+        content = multi_line_comment.sub("", content)
+        content = single_line_comment.sub("", content)
+        content = repeating_space.sub(" ", content)
+        content = leading_space.sub("", content)
+        content = trailing_space.sub("", content)
+        content = empty_line.sub("\n", content)
+    elif extension == "css":
+        content = multi_line_comment.sub("", content)
+        content = repeating_space.sub(" ", content)
+        content = leading_space.sub("", content)
+        content = trailing_space.sub("", content)
+        content = empty_line.sub("\n", content)
+    return content
+
+
 def main():
     parser = OptionParser()
     parser.add_option("--out-h", dest="out_header")
@@ -74,6 +102,7 @@ def main():
 
     for file_name in args:
         (variable_name, content) = make_variable_name_and_read(file_name)
+        content = strip_whitespace_and_comments(file_name, content)
         size = len(content)
         header_file.write("extern const char %s[%d];\n" % (variable_name, size))
         cpp_file.write("const char %s[%d] = {\n" % (variable_name, size))