Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / base / l10n / l10n_util_plurals.cc
blob177e263cf24429218c6ae9394d9a37566f0df94f
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/l10n/l10n_util_plurals.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/base/l10n/l10n_util.h"
11 namespace l10n_util {
13 scoped_ptr<icu::PluralRules> BuildPluralRules() {
14 UErrorCode err = U_ZERO_ERROR;
15 scoped_ptr<icu::PluralRules> rules(
16 icu::PluralRules::forLocale(icu::Locale::getDefault(), err));
17 if (U_FAILURE(err)) {
18 err = U_ZERO_ERROR;
19 icu::UnicodeString fallback_rules("one: n is 1", -1, US_INV);
20 rules.reset(icu::PluralRules::createRules(fallback_rules, err));
21 DCHECK(U_SUCCESS(err));
23 return rules.Pass();
26 void FormatNumberInPlural(const icu::MessageFormat& format, int number,
27 icu::UnicodeString* result, UErrorCode* err) {
28 if (U_FAILURE(*err)) return;
29 icu::Formattable formattable(number);
30 icu::FieldPosition ignore(icu::FieldPosition::DONT_CARE);
31 format.format(&formattable, 1, *result, ignore, *err);
32 DCHECK(U_SUCCESS(*err));
33 return;
37 } // namespace l10n_util