summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-01-21 15:32:36 +0000
committerNarayan Kamath <narayan@google.com>2014-02-14 14:08:57 +0000
commit788fa41482b9d398591b7db8b0b01839029611ad (patch)
treeab94d4040351d79cca717a8b7e21fc6be5d0fcb5 /include
parent48620f1d1b03e1cb4e0dce4999e0a4c2daf3a1b2 (diff)
downloadframeworks_base-788fa41482b9d398591b7db8b0b01839029611ad.zip
frameworks_base-788fa41482b9d398591b7db8b0b01839029611ad.tar.gz
frameworks_base-788fa41482b9d398591b7db8b0b01839029611ad.tar.bz2
Extended locales in AAPT / AssetManager.
Support 3 letter language codes, script codes & variants. The bulk of the changes are related to the implementation of command line filtering of locales etc. The previous code assumed that the value of each "axis" (locale, density, size etc.) could be represented by a 4 byte type. This is no longer the case. This change introduces a new class, AaptLocaleValue which holds a (normalized) locale parsed from a directory name or a filter string. This class takes responsibility for parsing locales as well as writing them to ResTable_config structures, which is their representation in the resource table. This includes minor changes at the java / JNI level for AssetManager. We now call locale.toLanguageTag() to give the native layer a well formed BCP-47 tag. I've removed some duplicated parsing code in AssetManager.cpp and replaced them with functions on ResTable_config. The native getLocales function has been changed to return well formed BCP-47 locales as well, so that the corresponding java function can use Locale.forLanguageTag to construct a Locale object out of it. Finally, this change introduces default and copy constructors for ResTable_config to prevent having to memset() the associated memory to 0 on every stack allocation. (cherry-picked from commit 91447d88f2bdf9c2bf8d1a53570efef6172fba74) Change-Id: I1b43086860661012f949fb8e5deb7df44519b854
Diffstat (limited to 'include')
-rw-r--r--include/androidfw/ResourceTypes.h41
1 files changed, 27 insertions, 14 deletions
diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h
index b21977c..a0bae12 100644
--- a/include/androidfw/ResourceTypes.h
+++ b/include/androidfw/ResourceTypes.h
@@ -1053,7 +1053,7 @@ struct ResTable_config
// The ISO-15924 short name for the script corresponding to this
// configuration. (eg. Hant, Latn, etc.). Interpreted in conjunction with
- // the locale field
+ // the locale field.
char localeScript[4];
// A single BCP-47 variant subtag. Will vary in length between 5 and 8
@@ -1118,14 +1118,23 @@ struct ResTable_config
bool match(const ResTable_config& settings) const;
// Get the string representation of the locale component of this
- // Config. This will contain the language along with the prefixed script,
- // region and variant of this config, separated by underscores.
+ // Config. The maximum size of this representation will be
+ // |RESTABLE_MAX_LOCALE_LEN| (including a terminating '\0').
//
- // 'r' is the region prefix, 's' is the script prefix and 'v' is the
- // variant prefix.
- //
- // Example: en_rUS, en_sLatn_rUS, en_vPOSIX.
- void getLocale(char str[RESTABLE_MAX_LOCALE_LEN]) const;
+ // Example: en-US, en-Latn-US, en-POSIX.
+ void getBcp47Locale(char* out) const;
+
+ // Sets the values of language, region, script and variant to the
+ // well formed BCP-47 locale contained in |in|. The input locale is
+ // assumed to be valid and no validation is performed.
+ void setBcp47Locale(const char* in);
+
+ inline void clearLocale() {
+ locale = 0;
+ memset(localeScript, 0, sizeof(localeScript));
+ memset(localeVariant, 0, sizeof(localeVariant));
+ }
+
// Get the 2 or 3 letter language code of this configuration. Trailing
// bytes are set to '\0'.
size_t unpackLanguage(char language[4]) const;
@@ -1133,12 +1142,16 @@ struct ResTable_config
// bytes are set to '\0'.
size_t unpackRegion(char region[4]) const;
- // Sets the language code of this configuration from |language|. If |language|
- // is a 2 letter code, the trailing byte is expected to be '\0'.
- void packLanguage(const char language[3]);
- // Sets the region code of this configuration from |region|. If |region|
- // is a 2 letter code, the trailing byte is expected to be '\0'.
- void packRegion(const char region[3]);
+ // Sets the language code of this configuration to the first three
+ // chars at |language|.
+ //
+ // If |language| is a 2 letter code, the trailing byte must be '\0' or
+ // the BCP-47 separator '-'.
+ void packLanguage(const char* language);
+ // Sets the region code of this configuration to the first three bytes
+ // at |region|. If |region| is a 2 letter code, the trailing byte must be '\0'
+ // or the BCP-47 separator '-'.
+ void packRegion(const char* region);
// Returns a positive integer if this config is more specific than |o|
// with respect to their locales, a negative integer if |o| is more specific