Index: ui/base/l10n/formatter.h |
diff --git a/ui/base/l10n/formatter.h b/ui/base/l10n/formatter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6ed77b0ea54a60c5d4fe67f1808f44b83799aa2a |
--- /dev/null |
+++ b/ui/base/l10n/formatter.h |
@@ -0,0 +1,86 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef UI_BASE_L10N_FORMATTER_H_ |
+#define UI_BASE_L10N_FORMATTER_H_ |
+ |
+#include "base/lazy_instance.h" |
+#include "base/macros.h" |
bartfab (slow)
2014/02/18 12:04:04
Nit: We usually include "base/basictypes.h" instea
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+#include "base/memory/scoped_ptr.h" |
+#include "third_party/icu/source/i18n/unicode/plurfmt.h" |
+#include "third_party/icu/source/i18n/unicode/plurrule.h" |
+#include "ui/base/l10n/time_format.h" |
+ |
+namespace ui { |
+struct Pluralities; |
bartfab (slow)
2014/02/18 12:04:04
Nit: Add a blank line before this.
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ |
+// Formatter for a (type,length) combination. May either be instantiated with |
+// four parameters for use in TimeFormat::Simple() or with ten parameters for |
+// use in TimeFormat::Detailed(). |
+class Formatter { |
+ public: |
+ enum { kNUnit = 4 }; |
bartfab (slow)
2014/02/18 12:04:04
This is not how we do enums in Chrome. See comment
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ enum Unit { SEC, MIN, HOUR, DAY }; |
bartfab (slow)
2014/02/18 12:04:04
Nit: Put each enum entry on its own line.
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ enum { kNTwoUnits = 3 }; |
bartfab (slow)
2014/02/18 12:04:04
This is not how we do enums in Chrome. See comment
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ enum TwoUnits { MIN_SEC, HOUR_MIN, DAY_HOUR }; |
bartfab (slow)
2014/02/18 12:04:04
Nit: Put each enum entry on its own line.
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ |
+ Formatter(const Pluralities& sec_pluralities, |
+ const Pluralities& min_pluralities, |
+ const Pluralities& hour_pluralities, |
+ const Pluralities& day_pluralities); |
+ |
+ Formatter(const Pluralities& sec_pluralities, |
+ const Pluralities& min_pluralities, |
+ const Pluralities& hour_pluralities, |
+ const Pluralities& day_pluralities, |
+ const Pluralities& min_sec_pluralities1, |
+ const Pluralities& min_sec_pluralities2, |
+ const Pluralities& hour_min_pluralities1, |
+ const Pluralities& hour_min_pluralities2, |
+ const Pluralities& day_hour_pluralities1, |
+ const Pluralities& day_hour_pluralities2); |
+ |
+ void Format(Unit unit, int value, icu::UnicodeString& formatted_string) const; |
bartfab (slow)
2014/02/18 12:04:04
Nit: Forward-declare icu::UnicodeString.
Thiemo Nagel
2014/02/19 17:08:44
I've tried it, it doesn't work. I can't forward d
bartfab (slow)
2014/02/20 16:31:22
Makes sense. With third-party stuff, there is some
Thiemo Nagel
2014/02/22 21:44:09
Done.
|
+ void Format(TwoUnits units, int value1, int value2, |
bartfab (slow)
2014/02/18 12:04:04
Nit: Per the style guide, a declaration/definition
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ icu::UnicodeString& formatted_string) const; |
+ |
+ private: |
+ // Create a hard-coded fallback plural format. This will never be called |
+ // unless translators make a mistake. |
+ icu::PluralFormat* CreateFallbackFormat( |
bartfab (slow)
2014/02/18 12:04:04
1) This passes ownership. Return a scoped_ptr inst
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ const icu::PluralRules& rules, const Pluralities& pluralities) const; |
+ |
+ icu::PluralFormat* InitFormat(const Pluralities& pluralities); |
bartfab (slow)
2014/02/18 12:04:04
This passes ownership. Return a scoped_ptr instead
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ |
+ scoped_ptr<icu::PluralFormat> format_[kNUnit]; |
+ scoped_ptr<icu::PluralFormat> detailed_format_[kNTwoUnits][2]; |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(Formatter); |
+}; |
+ |
+// Class to hold all Formatters, intended to be used in a global LazyInstance. |
+class UI_BASE_EXPORT FormatterContainer { |
bartfab (slow)
2014/02/18 12:04:04
Nit: #include "ui/base/ui_base_export.h"
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ public: |
+ FormatterContainer(); |
+ ~FormatterContainer(); |
+ |
+ const Formatter* Get(TimeFormat::Type type, |
+ TimeFormat::Length length) const; |
+ |
+ // Implemented in header file to avoid code generation in production builds. |
bartfab (slow)
2014/02/18 12:04:04
Nit 1: For trivial getters and setters, implementa
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ static bool GetFallbackForTesting() { return ForceFallback_; } |
+ static void SetFallbackForTesting(bool val) { ForceFallback_ = val; } |
+ |
+ private: |
+ Formatter* formatter_[TimeFormat::kNType][TimeFormat::kNLength]; |
+ |
+ static bool ForceFallback_; |
bartfab (slow)
2014/02/18 12:04:04
Nit: user hacker_style, not CamelCase for member n
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ |
+ friend struct base::DefaultLazyInstanceTraits<FormatterContainer>; |
bartfab (slow)
2014/02/18 12:04:04
Nit: It is customary to have the friend declaratio
Thiemo Nagel
2014/02/19 17:08:44
Done.
|
+ DISALLOW_COPY_AND_ASSIGN(FormatterContainer); |
+}; |
+ |
+} // namespace ui |
+ |
+#endif |