summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-03-10 16:55:43 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-03-16 22:25:26 +0000
commit8a9355a98ece3d7fc9d022e759d05378060c86e2 (patch)
treed6d76f94f2688f9bcee4c961dafc4cc3ec97a6bd
parent9c329b8b6440823ef94bffebc0b1098e8b2ad622 (diff)
downloadframeworks_base-8a9355a98ece3d7fc9d022e759d05378060c86e2.zip
frameworks_base-8a9355a98ece3d7fc9d022e759d05378060c86e2.tar.gz
frameworks_base-8a9355a98ece3d7fc9d022e759d05378060c86e2.tar.bz2
Output modified bcp47 tag in ResTable_config::toString()
We expect to be able to parse the output of ResTable_config::toString(), so it should use modified bcp47 (b+en+Latn+US). Change-Id: I597a1779a1fa5cff171c473e6a0368d93b9c7722
-rw-r--r--include/androidfw/ResourceTypes.h6
-rw-r--r--libs/androidfw/ResourceTypes.cpp59
-rw-r--r--tests/Split/res/values-b+fr+Latn+CA/strings.xml4
-rw-r--r--tests/Split/res/values-fr-rCA/strings.xml4
-rw-r--r--tools/aapt/AaptAssets.cpp27
-rw-r--r--tools/aapt/AaptAssets.h2
-rw-r--r--tools/aapt/tests/AaptConfig_test.cpp2
7 files changed, 68 insertions, 36 deletions
diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h
index 8673219..65160d5 100644
--- a/include/androidfw/ResourceTypes.h
+++ b/include/androidfw/ResourceTypes.h
@@ -1195,6 +1195,12 @@ struct ResTable_config
// Example: en-US, en-Latn-US, en-POSIX.
void getBcp47Locale(char* out) const;
+ // Append to str the resource-qualifer string representation of the
+ // locale component of this Config. If the locale is only country
+ // and language, it will look like en-rUS. If it has scripts and
+ // variants, it will be a modified bcp47 tag: b+en+Latn+US.
+ void appendDirLocale(String8& str) 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.
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index d5d583c..e247150 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -2550,6 +2550,58 @@ bool ResTable_config::match(const ResTable_config& settings) const {
return true;
}
+void ResTable_config::appendDirLocale(String8& out) const {
+ if (!language[0]) {
+ return;
+ }
+
+ if (!localeScript[0] && !localeVariant[0]) {
+ // Legacy format.
+ if (out.size() > 0) {
+ out.append("-");
+ }
+
+ char buf[4];
+ size_t len = unpackLanguage(buf);
+ out.append(buf, len);
+
+ if (country[0]) {
+ out.append("-r");
+ len = unpackRegion(buf);
+ out.append(buf, len);
+ }
+ return;
+ }
+
+ // We are writing the modified bcp47 tag.
+ // It starts with 'b+' and uses '+' as a separator.
+
+ if (out.size() > 0) {
+ out.append("-");
+ }
+ out.append("b+");
+
+ char buf[4];
+ size_t len = unpackLanguage(buf);
+ out.append(buf, len);
+
+ if (localeScript[0]) {
+ out.append("+");
+ out.append(localeScript, sizeof(localeScript));
+ }
+
+ if (country[0]) {
+ out.append("+");
+ len = unpackRegion(buf);
+ out.append(buf, len);
+ }
+
+ if (localeVariant[0]) {
+ out.append("+");
+ out.append(localeVariant, sizeof(localeVariant));
+ }
+}
+
void ResTable_config::getBcp47Locale(char str[RESTABLE_MAX_LOCALE_LEN]) const {
memset(str, 0, RESTABLE_MAX_LOCALE_LEN);
@@ -2650,12 +2702,7 @@ String8 ResTable_config::toString() const {
res.appendFormat("mnc%d", dtohs(mnc));
}
- char localeStr[RESTABLE_MAX_LOCALE_LEN];
- getBcp47Locale(localeStr);
- if (strlen(localeStr) > 0) {
- if (res.size() > 0) res.append("-");
- res.append(localeStr);
- }
+ appendDirLocale(res);
if ((screenLayout&MASK_LAYOUTDIR) != 0) {
if (res.size() > 0) res.append("-");
diff --git a/tests/Split/res/values-b+fr+Latn+CA/strings.xml b/tests/Split/res/values-b+fr+Latn+CA/strings.xml
new file mode 100644
index 0000000..108a135
--- /dev/null
+++ b/tests/Split/res/values-b+fr+Latn+CA/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="test">Bonsoir!</string>
+</resources>
diff --git a/tests/Split/res/values-fr-rCA/strings.xml b/tests/Split/res/values-fr-rCA/strings.xml
new file mode 100644
index 0000000..0837a68
--- /dev/null
+++ b/tests/Split/res/values-fr-rCA/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="test">Bonjour</string>
+</resources>
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index 871e04f..d346731 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -367,33 +367,6 @@ int AaptLocaleValue::initFromDirName(const Vector<String8>& parts, const int sta
return currentIndex;
}
-
-String8 AaptLocaleValue::toDirName() const {
- String8 dirName("");
- if (language[0]) {
- dirName += language;
- } else {
- return dirName;
- }
-
- if (script[0]) {
- dirName += "-s";
- dirName += script;
- }
-
- if (region[0]) {
- dirName += "-r";
- dirName += region;
- }
-
- if (variant[0]) {
- dirName += "-v";
- dirName += variant;
- }
-
- return dirName;
-}
-
void AaptLocaleValue::initFromResTable(const ResTable_config& config) {
config.unpackLanguage(language);
config.unpackRegion(region);
diff --git a/tools/aapt/AaptAssets.h b/tools/aapt/AaptAssets.h
index 7ae5368..4fdc964 100644
--- a/tools/aapt/AaptAssets.h
+++ b/tools/aapt/AaptAssets.h
@@ -78,8 +78,6 @@ struct AaptLocaleValue {
void writeTo(ResTable_config* out) const;
- String8 toDirName() const;
-
int compare(const AaptLocaleValue& other) const {
return memcmp(this, &other, sizeof(AaptLocaleValue));
}
diff --git a/tools/aapt/tests/AaptConfig_test.cpp b/tools/aapt/tests/AaptConfig_test.cpp
index ef3860c..7618974 100644
--- a/tools/aapt/tests/AaptConfig_test.cpp
+++ b/tools/aapt/tests/AaptConfig_test.cpp
@@ -65,7 +65,7 @@ TEST(AaptConfigTest, ParseBasicQualifiers) {
TEST(AaptConfigTest, ParseLocales) {
ConfigDescription config;
EXPECT_TRUE(TestParse("en-rUS", &config));
- EXPECT_EQ(String8("en-US"), config.toString());
+ EXPECT_EQ(String8("en-rUS"), config.toString());
}
TEST(AaptConfigTest, ParseQualifierAddedInApi13) {