/// <summary> /// Advance index past variant, and accumulate normalized variant in buffer. This ignores /// the codepage information from POSIX ids. Index must be immediately after the country /// or script. Index is left at the keyword separator or at the end of the text. Return /// the start of the variant code in the buffer. /// </summary> /// <remarks> /// In standard form, we can have the following forms: /// <list type="bullet"> /// <item><description>ll__VVVV</description></item> /// <item><description>ll_CC_VVVV</description></item> /// <item><description>ll_Ssss_VVVV</description></item> /// <item><description>ll_Ssss_CC_VVVV</description></item> /// </list> /// <para/> /// This also handles POSIX ids, which can have the following forms (pppp is code page id): /// <list type="bullet"> /// <item><description>ll_CC.pppp --> ll_CC</description></item> /// <item><description>ll_CC.pppp@VVVV --> ll_CC_VVVV</description></item> /// <item><description>ll_CC@VVVV --> ll_CC_VVVV</description></item> /// </list> /// <para/> /// We identify this use of '@' in POSIX ids by looking for an '=' following /// the '@'. If there is one, we consider '@' to start a keyword list, instead of /// being part of a POSIX id. /// <para/> /// Note: since it was decided that we want an option to not handle POSIX ids, this /// becomes a bit more complex. /// </remarks> private int ParseVariant() { int oldBlen = buffer.Length; bool start = true; bool needSeparator = true; bool skipping = false; char c; bool firstPass = true; while ((c = Next()) != DONE) { if (c == DOT) { start = false; skipping = true; } else if (c == KEYWORD_SEPARATOR) { if (HaveKeywordAssign()) { break; } skipping = false; start = false; needSeparator = true; // add another underscore if we have more text } else if (start) { start = false; if (c != UNDERSCORE && c != HYPHEN) { index--; } } else if (!skipping) { if (needSeparator) { needSeparator = false; if (firstPass && !hadCountry) { // no country, we'll need two AddSeparator(); ++oldBlen; // for sure } AddSeparator(); if (firstPass) { // only for the first separator ++oldBlen; firstPass = false; } } c = AsciiUtil.ToUpper(c); if (c == HYPHEN || c == COMMA) { c = UNDERSCORE; } Append(c); } } --index; // unget return(oldBlen); }
/// <summary> /// Returns the value for the named keyword, or null if the keyword is not /// present. /// </summary> public string GetKeywordValue(string keywordName) { var m = GetKeywordMap(); return(!m.Any() ? null : m.Get(AsciiUtil.ToLower(keywordName.Trim()))); }
/// <summary> /// Returns the value for the named keyword, or null if the keyword is not /// present. /// </summary> public string GetKeywordValue(string keywordName) { var m = GetKeywords(); return(m.Count == 0 ? null : m.Get(AsciiUtil.ToLower(keywordName.Trim()))); }