cleanup messy logic for bcp qualifiers

This commit is contained in:
Connor Tumbleson 2015-04-11 11:36:31 -05:00
parent 7f487daaf2
commit da3b8c710d
3 changed files with 21 additions and 8 deletions

View File

@ -114,6 +114,22 @@ public class ResConfigFlags {
isInvalid = true;
}
if (localeScript.length != 0) {
if (localeScript[0] == '\00') {
localeScript = null;
}
} else {
localeScript = null;
}
if (localeVariant.length != 0) {
if (localeVariant[0] == '\00') {
localeVariant = null;
}
} else {
localeVariant = null;
}
this.mcc = mcc;
this.mnc = mnc;
this.language = language;
@ -375,11 +391,8 @@ public class ResConfigFlags {
// check for old style non BCP47 tags
// allows values-xx-rXX, values-xx, values-xxx-rXX
// denies values-xxx, anything else
if (language[0] != '\00' && localeScript.length == 0 && localeVariant.length == 0 &&
(region.length != 3 && language.length != 3) ||
(language.length == 3 && region.length == 2 && region[0] != '\00' &&
localeScript.length == 0 && localeVariant.length == 0)) {
if (localeVariant == null && localeScript == null && (region[0] != '\00' || language[0] != '\00') &&
region.length != 3) {
sb.append("-").append(language);
if (region[0] != '\00') {
sb.append("-r").append(region);
@ -392,13 +405,13 @@ public class ResConfigFlags {
if (language[0] != '\00') {
sb.append(language);
}
if (localeScript.length == 4) {
if (localeScript != null && localeScript.length == 4) {
sb.append("+").append(localeScript);
}
if ((region.length == 2 || region.length == 3) && region[0] != '\00') {
sb.append("+").append(region);
}
if (localeVariant.length >= 5) {
if (localeVariant != null && localeVariant.length >= 5) {
sb.append("+").append(toUpper(localeVariant));
}
}

View File

@ -204,7 +204,7 @@ public class BuildAndDecodeTest {
@Test
public void threeLetterLangBcp47Test() throws BrutException, IOException {
compareValuesFiles("values-b+ast/strings.xml");
compareValuesFiles("values-ast/strings.xml");
}
@Test