libosmscout  1.1.1
Locale.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_LOCALE_H
2 #define OSMSCOUT_LOCALE_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2019 Lukáš Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
25 
26 #include <osmscout/util/Distance.h>
27 
28 #include <string>
29 
30 namespace osmscout {
31 
32  class OSMSCOUT_API Locale CLASS_FINAL
33  {
34  private:
36  std::string decimalSeparator{"."};
37  std::string thousandsSeparator;
38 
39  // use tiny, unbreakable space between value and unit.
40  // U+202F unicode is encoded as 0xE280AF in utf-8
41  // because unicode support in C++ is poor and platform dependent,
42  // we will use utf-8 bytes directly
43  std::string unitsSeparator{"\xE2\x80\xAF"};
44 
45  public:
52  Locale() = default;
53 
54  Locale(const DistanceUnitSystem &distanceUnits,
55  const std::string &decimalSeparator,
56  const std::string &thousandsSeparator);
57 
58  Locale(const Locale&) = default;
59  Locale(Locale&&) = default;
60  ~Locale() = default;
61  Locale &operator=(const Locale &) = default;
62  Locale &operator=(Locale &&) = default;
63 
65  {
66  return distanceUnits;
67  }
68 
70  {
71  this->distanceUnits = units;
72  }
73 
74  std::string GetDecimalSeparator() const
75  {
76  return decimalSeparator;
77  }
78 
79  void SetDecimalSeparator(const std::string &separator)
80  {
81  this->decimalSeparator = separator;
82  }
83 
84  std::string GetThousandsSeparator() const
85  {
86  return thousandsSeparator;
87  }
88 
89  void SetThousandsSeparator(const std::string &separator)
90  {
91  this->thousandsSeparator = separator;
92  }
93 
94  std::string GetUnitsSeparator() const
95  {
96  return unitsSeparator;
97  }
98 
99  void SetUnitsSeparator(const std::string &separator)
100  {
101  this->unitsSeparator = separator;
102  }
103 
104  public:
105  static Locale ByEnvironment(std::locale locale = std::locale(""));
106  };
107 }
108 
109 #endif // OSMSCOUT_LOCALE_H
DistanceUnitSystem
Definition: Distance.h:35
void SetThousandsSeparator(const std::string &separator)
Definition: Locale.h:89
Definition: Area.h:38
std::string GetUnitsSeparator() const
Definition: Locale.h:94
std::string GetThousandsSeparator() const
Definition: Locale.h:84
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
void SetDecimalSeparator(const std::string &separator)
Definition: Locale.h:79
std::string GetDecimalSeparator() const
Definition: Locale.h:74
void SetDistanceUnits(const DistanceUnitSystem &units)
Definition: Locale.h:69
void SetUnitsSeparator(const std::string &separator)
Definition: Locale.h:99
DistanceUnitSystem GetDistanceUnits() const
Definition: Locale.h:64