Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 #ifndef UI_BASE_L10N_FORMATTER_H_ | |
| 6 #define UI_BASE_L10N_FORMATTER_H_ | |
| 7 | |
| 8 #include "base/lazy_instance.h" | |
| 9 #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.
| |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "third_party/icu/source/i18n/unicode/plurfmt.h" | |
| 12 #include "third_party/icu/source/i18n/unicode/plurrule.h" | |
| 13 #include "ui/base/l10n/time_format.h" | |
| 14 | |
| 15 namespace ui { | |
| 16 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.
| |
| 17 | |
| 18 // Formatter for a (type,length) combination. May either be instantiated with | |
| 19 // four parameters for use in TimeFormat::Simple() or with ten parameters for | |
| 20 // use in TimeFormat::Detailed(). | |
| 21 class Formatter { | |
| 22 public: | |
| 23 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.
| |
| 24 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.
| |
| 25 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.
| |
| 26 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.
| |
| 27 | |
| 28 Formatter(const Pluralities& sec_pluralities, | |
| 29 const Pluralities& min_pluralities, | |
| 30 const Pluralities& hour_pluralities, | |
| 31 const Pluralities& day_pluralities); | |
| 32 | |
| 33 Formatter(const Pluralities& sec_pluralities, | |
| 34 const Pluralities& min_pluralities, | |
| 35 const Pluralities& hour_pluralities, | |
| 36 const Pluralities& day_pluralities, | |
| 37 const Pluralities& min_sec_pluralities1, | |
| 38 const Pluralities& min_sec_pluralities2, | |
| 39 const Pluralities& hour_min_pluralities1, | |
| 40 const Pluralities& hour_min_pluralities2, | |
| 41 const Pluralities& day_hour_pluralities1, | |
| 42 const Pluralities& day_hour_pluralities2); | |
| 43 | |
| 44 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.
| |
| 45 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.
| |
| 46 icu::UnicodeString& formatted_string) const; | |
| 47 | |
| 48 private: | |
| 49 // Create a hard-coded fallback plural format. This will never be called | |
| 50 // unless translators make a mistake. | |
| 51 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.
| |
| 52 const icu::PluralRules& rules, const Pluralities& pluralities) const; | |
| 53 | |
| 54 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.
| |
| 55 | |
| 56 scoped_ptr<icu::PluralFormat> format_[kNUnit]; | |
| 57 scoped_ptr<icu::PluralFormat> detailed_format_[kNTwoUnits][2]; | |
| 58 | |
| 59 DISALLOW_IMPLICIT_CONSTRUCTORS(Formatter); | |
| 60 }; | |
| 61 | |
| 62 // Class to hold all Formatters, intended to be used in a global LazyInstance. | |
| 63 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.
| |
| 64 public: | |
| 65 FormatterContainer(); | |
| 66 ~FormatterContainer(); | |
| 67 | |
| 68 const Formatter* Get(TimeFormat::Type type, | |
| 69 TimeFormat::Length length) const; | |
| 70 | |
| 71 // 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.
| |
| 72 static bool GetFallbackForTesting() { return ForceFallback_; } | |
| 73 static void SetFallbackForTesting(bool val) { ForceFallback_ = val; } | |
| 74 | |
| 75 private: | |
| 76 Formatter* formatter_[TimeFormat::kNType][TimeFormat::kNLength]; | |
| 77 | |
| 78 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.
| |
| 79 | |
| 80 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.
| |
| 81 DISALLOW_COPY_AND_ASSIGN(FormatterContainer); | |
| 82 }; | |
| 83 | |
| 84 } // namespace ui | |
| 85 | |
| 86 #endif | |
| OLD | NEW |