Exemplo n.º 1
0
                /// <summary>
                /// The entrypoint method delegates to helper methods for each of the types of tables
                /// found in the currency data.
                /// </summary>
                public override void Put(ResourceKey key, ResourceValue value, bool isRoot)
                {
                    if (noRoot && isRoot)
                    {
                        // Don't consume the root bundle
                        return;
                    }

                    switch (entrypointTable)
                    {
                    case EntrypointTable.TOP:
                        ConsumeTopTable(key, value);
                        break;

                    case EntrypointTable.CURRENCIES:
                        ConsumeCurrenciesEntry(key, value);
                        break;

                    case EntrypointTable.CURRENCY_PLURALS:
                        ConsumeCurrencyPluralsEntry(key, value);
                        break;

                    case EntrypointTable.CURRENCY_NARROW:
                        ConsumeCurrenciesNarrowEntry(key, value);
                        break;

                    case EntrypointTable.CURRENCY_SPACING:
                        ConsumeCurrencySpacingTable(key, value);
                        break;

                    case EntrypointTable.CURRENCY_UNIT_PATTERNS:
                        ConsumeCurrencyUnitPatternsTable(key, value);
                        break;
                    }
                }
Exemplo n.º 2
0
            public override void Put(ResourceKey key, ResourceValue value, bool noFallback)
            {
                IResourceTable contextsTable = value.GetTable();

                for (int i = 0; contextsTable.GetKeyAndValue(i, key, value); ++i)
                {
                    CapitalizationContextUsage usage;
                    if (!contextUsageTypeMap.TryGetValue(key.ToString(), out usage))
                    {
                        continue;
                    }


                    int[] intVector = value.GetInt32Vector();
                    if (intVector.Length < 2)
                    {
                        continue;
                    }

                    int titlecaseInt = (outerInstance.capitalization == DisplayContext.CapitalizationForUIListOrMenu)
                            ? intVector[0] : intVector[1];
                    if (titlecaseInt == 0)
                    {
                        continue;
                    }

                    outerInstance.capitalizationUsage[(int)usage] = true;
                    hasCapitalizationUsage = true;
                }
            }
Exemplo n.º 3
0
 /// <summary>
 ///  Currencies%narrow{
 ///      AOA{"Kz"}
 ///      ARS{"$"}
 ///      ...
 ///  }
 /// </summary>
 internal void ConsumeCurrenciesNarrowEntry(ResourceKey key, ResourceValue value)
 {
     Debug.Assert(narrowSymbol != null);
     // No extra structure to traverse.
     if (narrowSymbol.narrowSymbol == null)
     {
         narrowSymbol.narrowSymbol = value.GetString();
     }
 }
Exemplo n.º 4
0
                /// <summary>
                ///  Currencies%variant{
                ///      TRY{"TL"}
                ///  }
                /// </summary>
                internal void ConsumeCurrenciesVariantTable(ResourceKey key, ResourceValue value)
                {
                    // Note: This data is used for parsing but not formatting.
                    Debug.Assert(parsingData != null);
                    IResourceTable table = value.GetTable();

                    for (int i = 0; table.GetKeyAndValue(i, key, value); i++)
                    {
                        string isoCode = key.ToString();
                        parsingData.symbolToIsoCode[value.GetString()] = isoCode;
                    }
                }
Exemplo n.º 5
0
                /// <summary>
                ///  CurrencyUnitPatterns{
                ///      other{"{0} {1}"}
                ///      ...
                ///  }
                /// </summary>
                internal void ConsumeCurrencyUnitPatternsTable(ResourceKey key, ResourceValue value)
                {
                    Debug.Assert(unitPatterns != null);
                    IResourceTable table = value.GetTable();

                    for (int i = 0; table.GetKeyAndValue(i, key, value); i++)
                    {
                        String pluralKeyword = key.ToString();
                        if (unitPatterns.Get(pluralKeyword) == null)
                        {
                            unitPatterns[pluralKeyword] = value.GetString();
                        }
                    }
                }
Exemplo n.º 6
0
                /// <summary>
                ///  currencySpacing{
                ///      afterCurrency{
                ///          currencyMatch{"[:^S:]"}
                ///          insertBetween{" "}
                ///          surroundingMatch{"[:digit:]"}
                ///      }
                ///      beforeCurrency{
                ///          currencyMatch{"[:^S:]"}
                ///          insertBetween{" "}
                ///          surroundingMatch{"[:digit:]"}
                ///      }
                ///  }
                /// </summary>
                internal void ConsumeCurrencySpacingTable(ResourceKey key, ResourceValue value)
                {
                    Debug.Assert(spacingInfo != null);
                    IResourceTable spacingTypesTable = value.GetTable();

                    for (int i = 0; spacingTypesTable.GetKeyAndValue(i, key, value); ++i)
                    {
                        CurrencySpacingInfo.SpacingType type;
                        if (key.ContentEquals("beforeCurrency"))
                        {
                            type = CurrencySpacingInfo.SpacingType.Before;
                            spacingInfo.HasBeforeCurrency = true;
                        }
                        else if (key.ContentEquals("afterCurrency"))
                        {
                            type = CurrencySpacingInfo.SpacingType.After;
                            spacingInfo.HasAfterCurrency = true;
                        }
                        else
                        {
                            continue;
                        }

                        IResourceTable patternsTable = value.GetTable();
                        for (int j = 0; patternsTable.GetKeyAndValue(j, key, value); ++j)
                        {
                            CurrencySpacingInfo.SpacingPattern pattern;
                            if (key.ContentEquals("currencyMatch"))
                            {
                                pattern = CurrencySpacingInfo.SpacingPattern.CurrencyMatch;
                            }
                            else if (key.ContentEquals("surroundingMatch"))
                            {
                                pattern = CurrencySpacingInfo.SpacingPattern.SurroundingMatch;
                            }
                            else if (key.ContentEquals("insertBetween"))
                            {
                                pattern = CurrencySpacingInfo.SpacingPattern.InsertBetween;
                            }
                            else
                            {
                                continue;
                            }

                            spacingInfo.SetSymbolIfNull(type, pattern, value.GetString());
                        }
                    }
                }
Exemplo n.º 7
0
                internal void ConsumeCurrencyPluralsEntry(ResourceKey key, ResourceValue value)
                {
                    Debug.Assert(pluralsData != null);
                    IResourceTable pluralsTable = value.GetTable();

                    for (int j = 0; pluralsTable.GetKeyAndValue(j, key, value); j++)
                    {
                        StandardPlural?plural = StandardPluralUtil.OrNullFromString(key.ToString());
                        if (plural == null)
                        {
                            throw new ICUException("Could not make StandardPlural from keyword " + key);
                        }

                        if (pluralsData[1 + (int)plural] == null)
                        {
                            pluralsData[1 + (int)plural] = value.GetString();
                        }
                    }
                }
Exemplo n.º 8
0
                private void ConsumeTopTable(ResourceKey key, ResourceValue value)
                {
                    IResourceTable table = value.GetTable();

                    for (int i = 0; table.GetKeyAndValue(i, key, value); i++)
                    {
                        if (key.ContentEquals("Currencies"))
                        {
                            ConsumeCurrenciesTable(key, value);
                        }
                        else if (key.ContentEquals("Currencies%variant"))
                        {
                            ConsumeCurrenciesVariantTable(key, value);
                        }
                        else if (key.ContentEquals("CurrencyPlurals"))
                        {
                            ConsumeCurrencyPluralsTable(key, value);
                        }
                    }
                }
Exemplo n.º 9
0
                /// <summary>
                ///  CurrencyPlurals{
                ///      BYB{
                ///          one{"Belarusian new rouble (1994–1999)"}
                ///          other{"Belarusian new roubles (1994–1999)"}
                ///      }
                ///      ...
                ///  }
                /// </summary>
                internal void ConsumeCurrencyPluralsTable(ResourceKey key, ResourceValue value)
                {
                    // The full CurrencyPlurals table is consumed for parsing only.
                    Debug.Assert(parsingData != null);
                    IResourceTable table = value.GetTable();

                    for (int i = 0; table.GetKeyAndValue(i, key, value); i++)
                    {
                        string         isoCode      = key.ToString();
                        IResourceTable pluralsTable = value.GetTable();
                        for (int j = 0; pluralsTable.GetKeyAndValue(j, key, value); j++)
                        {
                            StandardPlural?plural = StandardPluralUtil.OrNullFromString(key.ToString());
                            if (plural == null)
                            {
                                throw new ICUException("Could not make StandardPlural from keyword " + key);
                            }

                            parsingData.nameToIsoCode[value.GetString()] = isoCode;
                        }
                    }
                }
Exemplo n.º 10
0
                /// <summary>
                ///  Currencies{
                ///      ...
                ///      USD{
                ///          "US$",        => symbol
                ///          "US Dollar",  => display name
                ///      }
                ///      ...
                ///      ESP{
                ///          "₧",                  => symbol
                ///          "pesseta espanyola",  => display name
                ///          {
                ///              "¤ #,##0.00",     => currency-specific pattern
                ///              ",",              => currency-specific grouping separator
                ///              ".",              => currency-specific decimal separator
                ///          }
                ///      }
                ///      ...
                ///  }
                /// </summary>
                internal void ConsumeCurrenciesTable(ResourceKey key, ResourceValue value)
                {
                    // The full Currencies table is consumed for parsing only.
                    Debug.Assert(parsingData != null);
                    IResourceTable table = value.GetTable();

                    for (int i = 0; table.GetKeyAndValue(i, key, value); i++)
                    {
                        string isoCode = key.ToString();
                        if (value.Type != UResourceType.Array)
                        {
                            throw new ICUException("Unexpected data type in Currencies table for " + isoCode);
                        }
                        IResourceArray array = value.GetArray();

                        parsingData.symbolToIsoCode[isoCode] = isoCode; // Add the ISO code itself as a symbol
                        array.GetValue(0, value);
                        parsingData.symbolToIsoCode[value.GetString()] = isoCode;
                        array.GetValue(1, value);
                        parsingData.nameToIsoCode[value.GetString()] = isoCode;
                    }
                }
Exemplo n.º 11
0
                internal void ConsumeCurrenciesEntry(ResourceKey key, ResourceValue value)
                {
                    Debug.Assert(formattingData != null);
                    string isoCode = key.ToString();

                    if (value.Type != UResourceType.Array)
                    {
                        throw new ICUException("Unexpected data type in Currencies table for " + isoCode);
                    }
                    IResourceArray array = value.GetArray();

                    if (formattingData.symbol == null)
                    {
                        array.GetValue(0, value);
                        formattingData.symbol = value.GetString();
                    }
                    if (formattingData.displayName == null)
                    {
                        array.GetValue(1, value);
                        formattingData.displayName = value.GetString();
                    }

                    // If present, the third element is the currency format info.
                    // TODO: Write unit test to ensure that this data is being used by number formatting.
                    if (array.Length > 2 && formattingData.formatInfo == null)
                    {
                        array.GetValue(2, value);
                        IResourceArray formatArray = value.GetArray();
                        formatArray.GetValue(0, value);
                        string formatPattern = value.GetString();
                        formatArray.GetValue(1, value);
                        string decimalSeparator = value.GetString();
                        formatArray.GetValue(2, value);
                        string groupingSeparator = value.GetString();
                        formattingData.formatInfo = new CurrencyFormatInfo(
                            isoCode, formatPattern, decimalSeparator, groupingSeparator);
                    }
                }
Exemplo n.º 12
0
 /// <summary>
 /// Called once for each bundle (child-parent-...-root).
 /// The value is normally an array or table resource,
 /// and implementations of this method normally iterate over the
 /// tree of resource items stored there.
 /// </summary>
 /// <param name="key">Initially the key string of the enumeration-start resource.
 /// Empty if the enumeration starts at the top level of the bundle.
 /// Reuse for output values from <see cref="IResourceArray"/> and <see cref="IResourceTable"/> getters.</param>
 /// <param name="value">Call <see cref="ResourceValue.GetArray()"/> or <see cref="ResourceValue.GetTable()"/> as appropriate.
 /// Then reuse for output values from <see cref="IResourceArray"/> and <see cref="IResourceTable"/> getters.</param>
 /// <param name="noFallback">true if the bundle has no parent;
 /// that is, its top-level table has the nofallback attribute,
 /// or it is the root bundle of a locale tree.</param>
 public abstract void Put(ResourceKey key, ResourceValue value, bool noFallback);