From Jason Turner

[conversions.string]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjk9xv5km/{from.md → to.md} +26 -21
tmp/tmpjk9xv5km/{from.md → to.md} RENAMED
@@ -1,18 +1,17 @@
1
  ##### `string` conversions <a id="conversions.string">[[conversions.string]]</a>
2
 
3
  Class template `wstring_convert` performs conversions between a wide
4
  string and a byte string. It lets you specify a code conversion facet
5
  (like class template `codecvt`) to perform the conversions, without
6
- affecting any streams or locales. Say, for example, you have a code
7
- conversion facet called `codecvt_utf8` that you want to use to output to
8
- `cout` a UTF-8 multibyte sequence corresponding to a wide string, but
9
- you don’t want to alter the locale for `cout`. You can write something
10
- like:
11
 
12
  ``` cpp
13
- wstring_convert<codecvt_utf8<wchar_t>> myconv;
14
  std::string mbstring = myconv.to_bytes(L"Hello\n");
15
  std::cout << mbstring;
16
  ```
17
 
18
  ``` cpp
@@ -24,27 +23,30 @@ template<class Codecvt, class Elem = wchar_t,
24
  typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
25
  typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
26
  typedef typename Codecvt::state_type state_type;
27
  typedef typename wide_string::traits_type::int_type int_type;
28
 
29
- wstring_convert(Codecvt *pcvt = new Codecvt);
30
  wstring_convert(Codecvt* pcvt, state_type state);
31
- wstring_convert(const byte_string& byte_err,
32
  const wide_string& wide_err = wide_string());
33
  ~wstring_convert();
34
 
 
 
 
35
  wide_string from_bytes(char byte);
36
  wide_string from_bytes(const char* ptr);
37
  wide_string from_bytes(const byte_string& str);
38
  wide_string from_bytes(const char* first, const char* last);
39
 
40
  byte_string to_bytes(Elem wchar);
41
  byte_string to_bytes(const Elem* wptr);
42
  byte_string to_bytes(const wide_string& wstr);
43
  byte_string to_bytes(const Elem* first, const Elem* last);
44
 
45
- size_t converted() const;
46
  state_type state() const;
47
  private:
48
  byte_string byte_err_string; // exposition only
49
  wide_string wide_err_string; // exposition only
50
  Codecvt* cvtptr; // exposition only
@@ -57,15 +59,14 @@ template<class Codecvt, class Elem = wchar_t,
57
  The class template describes an object that controls conversions between
58
  wide string objects of class `std::basic_string<Elem, char_traits<Elem>,
59
  Wide_alloc>` and byte string objects of class `std::\\basic_string<char,
60
  char_traits<char>, Byte_alloc>`. The class template defines the types
61
  `wide_string` and `byte_string` as synonyms for these two types.
62
- Conversion between a sequence of `Elem` values (stored in a wide_string
63
- object) and multibyte sequences (stored in a byte_string object) is
64
- performed by an object of class `Codecvt<Elem, char, std::mbstate_t>`,
65
- which meets the requirements of the standard code-conversion facet
66
- `std::codecvt<Elem,
67
  char, std::mbstate_t>`.
68
 
69
  An object of this class template stores:
70
 
71
  - `byte_err_string` — a byte string to display on errors
@@ -74,17 +75,18 @@ An object of this class template stores:
74
  freed when the `wstring_convert` object is destroyed)
75
  - `cvtstate` — a conversion state object
76
  - `cvtcount` — a conversion count
77
 
78
  ``` cpp
79
- typedef std::basic_string<char> byte_string;
80
  ```
81
 
82
- The type shall be a synonym for `std::basic_string<char>`
 
83
 
84
  ``` cpp
85
- size_t converted() const;
86
  ```
87
 
88
  *Returns:* `cvtcount`.
89
 
90
  ``` cpp
@@ -160,22 +162,25 @@ return the converted byte string. Otherwise, if the object was
160
  constructed with a byte-error string, the member function shall return
161
  the byte-error string. Otherwise, the member function shall throw an
162
  object of class `std::range_error`.
163
 
164
  ``` cpp
165
- typedef std::basic_string<Elem> wide_string;
166
  ```
167
 
168
- The type shall be a synonym for `std::basic_string<Elem>`.
 
169
 
170
  ``` cpp
171
- wstring_convert(Codecvt *pcvt = new Codecvt);
172
  wstring_convert(Codecvt* pcvt, state_type state);
173
- wstring_convert(const byte_string& byte_err,
174
  const wide_string& wide_err = wide_string());
175
  ```
176
 
 
 
177
  *Effects:* The first constructor shall store `pcvt` in `cvtptr` and
178
  default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
179
  The second constructor shall store `pcvt` in `cvtptr`, `state` in
180
  `cvtstate`, and default values in `byte_err_string` and
181
  `wide_err_string`; moreover the stored state shall be retained between
 
1
  ##### `string` conversions <a id="conversions.string">[[conversions.string]]</a>
2
 
3
  Class template `wstring_convert` performs conversions between a wide
4
  string and a byte string. It lets you specify a code conversion facet
5
  (like class template `codecvt`) to perform the conversions, without
6
+ affecting any streams or locales. If you want to use the code conversion
7
+ facet `codecvt_utf8` to output to `cout` a UTF-8 multibyte sequence
8
+ corresponding to a wide string, but you don’t want to alter the locale
9
+ for `cout`, you can write something like:
 
10
 
11
  ``` cpp
12
+ wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
13
  std::string mbstring = myconv.to_bytes(L"Hello\n");
14
  std::cout << mbstring;
15
  ```
16
 
17
  ``` cpp
 
23
  typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
24
  typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
25
  typedef typename Codecvt::state_type state_type;
26
  typedef typename wide_string::traits_type::int_type int_type;
27
 
28
+ explicit wstring_convert(Codecvt* pcvt = new Codecvt);
29
  wstring_convert(Codecvt* pcvt, state_type state);
30
+ explicit wstring_convert(const byte_string& byte_err,
31
  const wide_string& wide_err = wide_string());
32
  ~wstring_convert();
33
 
34
+ wstring_convert(const wstring_convert&) = delete;
35
+ wstring_convert& operator=(const wstring_convert&) = delete;
36
+
37
  wide_string from_bytes(char byte);
38
  wide_string from_bytes(const char* ptr);
39
  wide_string from_bytes(const byte_string& str);
40
  wide_string from_bytes(const char* first, const char* last);
41
 
42
  byte_string to_bytes(Elem wchar);
43
  byte_string to_bytes(const Elem* wptr);
44
  byte_string to_bytes(const wide_string& wstr);
45
  byte_string to_bytes(const Elem* first, const Elem* last);
46
 
47
+ size_t converted() const noexcept;
48
  state_type state() const;
49
  private:
50
  byte_string byte_err_string; // exposition only
51
  wide_string wide_err_string; // exposition only
52
  Codecvt* cvtptr; // exposition only
 
59
  The class template describes an object that controls conversions between
60
  wide string objects of class `std::basic_string<Elem, char_traits<Elem>,
61
  Wide_alloc>` and byte string objects of class `std::\\basic_string<char,
62
  char_traits<char>, Byte_alloc>`. The class template defines the types
63
  `wide_string` and `byte_string` as synonyms for these two types.
64
+ Conversion between a sequence of `Elem` values (stored in a
65
+ `wide_string` object) and multibyte sequences (stored in a `byte_string`
66
+ object) is performed by an object of class `Codecvt`, which meets the
67
+ requirements of the standard code-conversion facet `std::codecvt<Elem,
 
68
  char, std::mbstate_t>`.
69
 
70
  An object of this class template stores:
71
 
72
  - `byte_err_string` — a byte string to display on errors
 
75
  freed when the `wstring_convert` object is destroyed)
76
  - `cvtstate` — a conversion state object
77
  - `cvtcount` — a conversion count
78
 
79
  ``` cpp
80
+ typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
81
  ```
82
 
83
+ The type shall be a synonym for
84
+ `std::basic_string<char, char_traits<char>, Byte_alloc>`
85
 
86
  ``` cpp
87
+ size_t converted() const noexcept;
88
  ```
89
 
90
  *Returns:* `cvtcount`.
91
 
92
  ``` cpp
 
162
  constructed with a byte-error string, the member function shall return
163
  the byte-error string. Otherwise, the member function shall throw an
164
  object of class `std::range_error`.
165
 
166
  ``` cpp
167
+ typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
168
  ```
169
 
170
+ The type shall be a synonym for
171
+ `std::basic_string<Elem, char_traits<Elem>, Wide_alloc>`.
172
 
173
  ``` cpp
174
+ explicit wstring_convert(Codecvt* pcvt = new Codecvt);
175
  wstring_convert(Codecvt* pcvt, state_type state);
176
+ explicit wstring_convert(const byte_string& byte_err,
177
  const wide_string& wide_err = wide_string());
178
  ```
179
 
180
+ *Requires:* For the first and second constructors, `pcvt != nullptr`.
181
+
182
  *Effects:* The first constructor shall store `pcvt` in `cvtptr` and
183
  default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
184
  The second constructor shall store `pcvt` in `cvtptr`, `state` in
185
  `cvtstate`, and default values in `byte_err_string` and
186
  `wide_err_string`; moreover the stored state shall be retained between