diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-04-06 20:56:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-04-06 20:56:05 +0000 |
commit | 1fd5d21e0da2f1e467827fa5cd634be77021a69d (patch) | |
tree | efc331c83d9c311a736549e73518927398e0c6fc /tools/layoutlib | |
parent | b677e0a49643d265eb0fa5efc3666a1e9362477f (diff) | |
parent | d654b6f981dbef7c6a6a57c8725fc9f510dd7a09 (diff) | |
download | frameworks_base-1fd5d21e0da2f1e467827fa5cd634be77021a69d.zip frameworks_base-1fd5d21e0da2f1e467827fa5cd634be77021a69d.tar.gz frameworks_base-1fd5d21e0da2f1e467827fa5cd634be77021a69d.tar.bz2 |
Merge "Be lenient in accepting version strings."
Diffstat (limited to 'tools/layoutlib')
-rwxr-xr-x | tools/layoutlib/rename_font/build_font.py | 13 | ||||
-rwxr-xr-x | tools/layoutlib/rename_font/build_font_single.py | 13 |
2 files changed, 16 insertions, 10 deletions
diff --git a/tools/layoutlib/rename_font/build_font.py b/tools/layoutlib/rename_font/build_font.py index c747d92..9713a4c 100755 --- a/tools/layoutlib/rename_font/build_font.py +++ b/tools/layoutlib/rename_font/build_font.py @@ -209,15 +209,18 @@ def ends_in_regular(string): def get_version(string): - # The string must begin with 'Version n.nn ' - # to extract n.nn, we return the second entry in the split strings. string = string.strip() - if not string.startswith('Version '): - raise InvalidFontException('mal-formed font version') - return sanitize(string.split()[1]) + # The spec says that the version string should start with "Version ". But not + # all fonts do. So, we return the complete string if it doesn't start with + # the prefix, else we return the rest of the string after sanitizing it. + prefix = 'Version ' + if string.startswith(prefix): + string = string[len(prefix):] + return sanitize(string) def sanitize(string): + """ Remove non-standard chars. """ return re.sub(r'[^\w-]+', '', string) if __name__ == '__main__': diff --git a/tools/layoutlib/rename_font/build_font_single.py b/tools/layoutlib/rename_font/build_font_single.py index 5f7dad9..4245cdc 100755 --- a/tools/layoutlib/rename_font/build_font_single.py +++ b/tools/layoutlib/rename_font/build_font_single.py @@ -193,15 +193,18 @@ def ends_in_regular(string): def get_version(string): - # The string must begin with 'Version n.nn ' - # to extract n.nn, we return the second entry in the split strings. string = string.strip() - if not string.startswith('Version '): - raise InvalidFontException('mal-formed font version') - return sanitize(string.split()[1]) + # The spec says that the version string should start with "Version ". But not + # all fonts do. So, we return the complete string if it doesn't start with + # the prefix, else we return the rest of the string after sanitizing it. + prefix = 'Version ' + if string.startswith(prefix): + string = string[len(prefix):] + return sanitize(string) def sanitize(string): + """ Remove non-standard chars. """ return re.sub(r'[^\w-]+', '', string) if __name__ == '__main__': |