public void SubTagComponentDescription_HasBeginningParenthesis_RemovesParens() { Assert.AreEqual( "Hiragana + Katakana", StandardTags.SubTagComponentDescription("Description: (Hiragana + Katakana)") ); }
public void SubTagComponentDescription_HasForwardSlash_ReplacesWithPipe() { Assert.AreEqual( "=|Kx'au||'ein", StandardTags.SubTagComponentDescription("Description: =/Kx'au//'ein") ); }
public void SubTagComponentDescription_HasAliasFor_RemovesAliasFor() { Assert.AreEqual( "Japanese (Han + Hiragana + Katakana)", StandardTags.SubTagComponentDescription("Description: Japanese (alias for Han + Hiragana + Katakana)") ); }
public static string ValidVariantString(string unknownString) { // var1-var2-var3 // var1-privateUse1-x-privateUse2 unknownString = unknownString.Trim(); unknownString = Regex.Replace(unknownString, @"[ ,.]", "-"); unknownString = Regex.Replace(unknownString, @"-+", "-"); var tokens = unknownString.Split('-'); var variants = new List <string>(); var privateUse = new List <string>(); bool haveSeenX = false; foreach (var token in tokens) { if (token == "x") { haveSeenX = true; continue; } if (!haveSeenX && StandardTags.IsValidRegisteredVariant(token)) { variants.Add(token); } else { privateUse.Add(token); } } string combinedVariant = String.Join("-", variants.ToArray()); string combinedPrivateUse = String.Join("-", privateUse.ToArray()); string variantString = combinedVariant; if (!String.IsNullOrEmpty(combinedPrivateUse)) { variantString = "x-" + combinedPrivateUse; if (!String.IsNullOrEmpty(combinedVariant)) { variantString = combinedVariant + "-" + variantString; } } return(variantString); }
public void IsValidIso3166Region_QM_ReturnsTrue() { Assert.IsTrue(StandardTags.IsValidIso3166Region("QM")); Assert.IsTrue(StandardTags.IsValidIso3166Region("qm")); }
public void IsValidIso639LanguageCode_two_ReturnTrue() { // Yes it's true Assert.IsTrue(StandardTags.IsValidIso639LanguageCode("two")); }
public void IsValidIso639LanguageCode_fonipa_ReturnFalse() { Assert.IsFalse(StandardTags.IsValidIso639LanguageCode("fonipa")); }
public void IsValidRegisteredVariant_en_ReturnsFalse() { Assert.IsFalse(StandardTags.IsValidRegisteredVariant("en")); }
public void IsValidIso639LanguageCode_qaa_ReturnsTrue() { Assert.IsTrue(StandardTags.IsValidIso639LanguageCode("qaa")); }
public void IsValidIso3166Region_fonipa_ReturnsFalse() { Assert.IsFalse(StandardTags.IsValidIso3166Region("fonipa")); }
public void IsValidRegisteredVariant_fonipa_ReturnsTrue() { Assert.IsTrue(StandardTags.IsValidRegisteredVariant("fonipa")); }
public void Clean() { // Migrate legacy ISO3 language codes to IANA 2 letter language codes, if there's a match. // Do this before we look for valid codes, otherwise the 3-letter ones come up as invalid and // get moved to private use. However, only do this to languages not identified as private-use. if (!Language.StartsWith("x-", StringComparison.OrdinalIgnoreCase)) { string migrateFrom = ""; string migrateTo = ""; foreach (string part in _languageSubTag.AllParts) { if (part.Equals("x", StringComparison.OrdinalIgnoreCase)) { break; // don't migrate language code parts already explicitly marked private-use. } if (String.IsNullOrEmpty(migrateFrom)) { foreach (var code in StandardTags.ValidIso639LanguageCodes) { if (code.ISO3Code.Equals(part)) { migrateFrom = part; migrateTo = code.Code; break; } } } } if (!String.IsNullOrEmpty(migrateFrom)) { _languageSubTag.RemoveParts(migrateFrom); _languageSubTag.AddToSubtag(migrateTo); } } // The very next thing, before anything else gets moved to private use, is to move the parts whose position we // care about to the appropriate position in the private use section. // In the process we may remove anything non-alphanumeric, since otherwise we may move a marker that later // disappears (pathologically). MoveFirstPartToPrivateUseIfNecessary(_languageSubTag, StandardTags.IsValidIso639LanguageCode, "qaa", true); MoveFirstPartToPrivateUseIfNecessary(_scriptSubTag, StandardTags.IsValidIso15924ScriptCode, "Qaaa", false); MoveFirstPartToPrivateUseIfNecessary(_regionSubTag, StandardTags.IsValidIso3166Region, "QM", false); //This fixes a bug where the LdmlAdaptorV1 was writing out Zxxx as part of the variant to mark an audio writing system if (_variantSubTag.Contains(WellKnownSubTags.Audio.Script)) { MoveTagsMatching(_variantSubTag, _scriptSubTag, tag => tag.Equals(WellKnownSubTags.Audio.Script)); _privateUseSubTag.AddToSubtag(WellKnownSubTags.Audio.PrivateUseSubtag); } // Fixes various legacy problems. if (Language.Equals("cmn", StringComparison.OrdinalIgnoreCase)) { Language = "zh"; } if (Language.Equals("pes", StringComparison.OrdinalIgnoreCase)) { Language = "fa"; } if (Language.Equals("arb", StringComparison.OrdinalIgnoreCase)) { Language = "ar"; } if (Language.Equals("zh", StringComparison.OrdinalIgnoreCase) && String.IsNullOrEmpty(Region)) { Region = "CN"; } // If the language tag contains an x- , then move the string behind the x- to private use MovePartsToPrivateUseIfNecessary(_languageSubTag); // Move script, region, and variant present in the langauge tag to their proper subtag. MoveTagsMatching(_languageSubTag, _scriptSubTag, StandardTags.IsValidIso15924ScriptCode, StandardTags.IsValidIso639LanguageCode); MoveTagsMatching(_languageSubTag, _regionSubTag, StandardTags.IsValidIso3166Region, StandardTags.IsValidIso639LanguageCode); MoveTagsMatching(_languageSubTag, _variantSubTag, StandardTags.IsValidRegisteredVariant, StandardTags.IsValidIso639LanguageCode); // Move all other tags that don't belong to the private use subtag. //keep track of everything that we moved var tempSubTag = new SubTag(); MoveTagsMatching( _languageSubTag, tempSubTag, tag => !StandardTags.IsValidIso639LanguageCode(tag) ); //place all the moved parts in private use. foreach (var part in tempSubTag.AllParts) { _privateUseSubTag.AddToSubtag(part); //if it looks like we moved a custom script set the subtag to mark that we've moved it if (_scriptSubTag.IsEmpty && part.Length == 4 && //potential custom script tag !WellKnownSubTags.Ipa.PhonemicPrivateUseSubtag.EndsWith(part) && !WellKnownSubTags.Ipa.PhoneticPrivateUseSubtag.EndsWith(part)) { _scriptSubTag = new SubTag("Qaaa"); } } MoveTagsMatching( _scriptSubTag, _privateUseSubTag, tag => !StandardTags.IsValidIso15924ScriptCode(tag) ); MoveTagsMatching( _regionSubTag, _privateUseSubTag, tag => !StandardTags.IsValidIso3166Region(tag) ); MoveTagsMatching( _variantSubTag, _privateUseSubTag, tag => !StandardTags.IsValidRegisteredVariant(tag) ); _languageSubTag.KeepFirstAndMoveRemainderTo(_privateUseSubTag); _scriptSubTag.KeepFirstAndMoveRemainderTo(_privateUseSubTag); _regionSubTag.KeepFirstAndMoveRemainderTo(_privateUseSubTag); if (_privateUseSubTag.Contains(WellKnownSubTags.Audio.PrivateUseSubtag)) { // Move every tag that's not a Zxxx to private use if (!_scriptSubTag.IsEmpty && !_scriptSubTag.Contains(WellKnownSubTags.Audio.Script)) { MoveTagsMatching(_scriptSubTag, _privateUseSubTag, tag => !_privateUseSubTag.Contains(tag)); } // If we don't have a Zxxx already, set it. This protects tags already present, but with unusual case if (!_scriptSubTag.Contains(WellKnownSubTags.Audio.Script)) { _scriptSubTag = new SubTag(WellKnownSubTags.Audio.Script); } } //These two methods may produce duplicates that will subsequently be removed. Do we care? - TA 29/3/2011 _privateUseSubTag.TruncatePartsToNumCharacters(8); _privateUseSubTag.RemoveNonAlphaNumericCharacters(); _variantSubTag.RemoveDuplicates(); _privateUseSubTag.RemoveDuplicates(); // Any 'x' in the other tags will have arrived in the privateUse tag, so remove them. _privateUseSubTag.RemoveParts("x"); // if language is empty, we need to add qaa, unless only a privateUse is present (e.g. x-blah is a valid rfc5646 tag) if ((_languageSubTag.IsEmpty && (!_scriptSubTag.IsEmpty || !_regionSubTag.IsEmpty || !_variantSubTag.IsEmpty)) || (_languageSubTag.IsEmpty && _scriptSubTag.IsEmpty && _regionSubTag.IsEmpty && _variantSubTag.IsEmpty && _privateUseSubTag.IsEmpty)) { _languageSubTag.AddToSubtag("qaa"); } // Two more legacy problems. We don't allow -etic or -emic without fonipa, so insert if needed. // If it has some other standard variant we won't be able to fix it...not sure what the right answer would be. // At least we catch the more common case. foreach (var part in _privateUseSubTag.AllParts) { if (string.IsNullOrEmpty(Variant) && (part.Equals("etic", StringComparison.OrdinalIgnoreCase) || part.Equals("emic", StringComparison.OrdinalIgnoreCase))) { Variant = "fonipa"; } } }
public void IsStandardIso3166Region_QM_ReturnsFalse() { Assert.IsFalse(StandardTags.IsStandardIso3166Region("QM")); }
public void IsStandardIso3166Region_US_ReturnsTrue() { Assert.IsTrue(StandardTags.IsStandardIso3166Region("US")); }
public void IsValidIso15924ScriptCode_fonipa_ReturnsFalse() { Assert.IsFalse(StandardTags.IsValidIso15924ScriptCode("fonipa")); }
public void IsStandardIso15924ScriptCode_Latn_ReturnsTrue() { Assert.IsTrue(StandardTags.IsStandardIso15924ScriptCode("Latn")); }
public void IsStandardIso15924ScriptCode_Qaaa_ReturnsFalse() { Assert.IsFalse(StandardTags.IsStandardIso15924ScriptCode("Qaaa")); }
public void IsValidIso15924ScriptCode_Qaaa_ReturnsTrue() { Assert.IsTrue(StandardTags.IsValidIso15924ScriptCode("Qaaa")); }