From Jason Turner

[conversions]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpcoiflxb6/{from.md → to.md} +0 -294
tmp/tmpcoiflxb6/{from.md → to.md} RENAMED
@@ -12,299 +12,5 @@ template <class charT> charT toupper(charT c, const locale& loc);
12
  template <class charT> charT tolower(charT c, const locale& loc);
13
  ```
14
 
15
  *Returns:* `use_facet<ctype<charT>>(loc).tolower(c)`.
16
 
17
- ##### `string` conversions <a id="conversions.string">[[conversions.string]]</a>
18
-
19
- Class template `wstring_convert` performs conversions between a wide
20
- string and a byte string. It lets you specify a code conversion facet
21
- (like class template `codecvt`) to perform the conversions, without
22
- affecting any streams or locales. If you want to use the code conversion
23
- facet `codecvt_utf8` to output to `cout` a UTF-8 multibyte sequence
24
- corresponding to a wide string, but you don’t want to alter the locale
25
- for `cout`, you can write something like:
26
-
27
- ``` cpp
28
- wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
29
- std::string mbstring = myconv.to_bytes(L"Hello\n");
30
- std::cout << mbstring;
31
- ```
32
-
33
- ``` cpp
34
- namespace std {
35
- template<class Codecvt, class Elem = wchar_t,
36
- class Wide_alloc = std::allocator<Elem>,
37
- class Byte_alloc = std::allocator<char> > class wstring_convert {
38
- public:
39
- typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
40
- typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
41
- typedef typename Codecvt::state_type state_type;
42
- typedef typename wide_string::traits_type::int_type int_type;
43
-
44
- explicit wstring_convert(Codecvt* pcvt = new Codecvt);
45
- wstring_convert(Codecvt* pcvt, state_type state);
46
- explicit wstring_convert(const byte_string& byte_err,
47
- const wide_string& wide_err = wide_string());
48
- ~wstring_convert();
49
-
50
- wstring_convert(const wstring_convert&) = delete;
51
- wstring_convert& operator=(const wstring_convert&) = delete;
52
-
53
- wide_string from_bytes(char byte);
54
- wide_string from_bytes(const char* ptr);
55
- wide_string from_bytes(const byte_string& str);
56
- wide_string from_bytes(const char* first, const char* last);
57
-
58
- byte_string to_bytes(Elem wchar);
59
- byte_string to_bytes(const Elem* wptr);
60
- byte_string to_bytes(const wide_string& wstr);
61
- byte_string to_bytes(const Elem* first, const Elem* last);
62
-
63
- size_t converted() const noexcept;
64
- state_type state() const;
65
- private:
66
- byte_string byte_err_string; // exposition only
67
- wide_string wide_err_string; // exposition only
68
- Codecvt* cvtptr; // exposition only
69
- state_type cvtstate; // exposition only
70
- size_t cvtcount; // exposition only
71
- };
72
- }
73
- ```
74
-
75
- The class template describes an object that controls conversions between
76
- wide string objects of class `std::basic_string<Elem, char_traits<Elem>,
77
- Wide_alloc>` and byte string objects of class `std::\\basic_string<char,
78
- char_traits<char>, Byte_alloc>`. The class template defines the types
79
- `wide_string` and `byte_string` as synonyms for these two types.
80
- Conversion between a sequence of `Elem` values (stored in a
81
- `wide_string` object) and multibyte sequences (stored in a `byte_string`
82
- object) is performed by an object of class `Codecvt`, which meets the
83
- requirements of the standard code-conversion facet `std::codecvt<Elem,
84
- char, std::mbstate_t>`.
85
-
86
- An object of this class template stores:
87
-
88
- - `byte_err_string` — a byte string to display on errors
89
- - `wide_err_string` — a wide string to display on errors
90
- - `cvtptr` — a pointer to the allocated conversion object (which is
91
- freed when the `wstring_convert` object is destroyed)
92
- - `cvtstate` — a conversion state object
93
- - `cvtcount` — a conversion count
94
-
95
- ``` cpp
96
- typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
97
- ```
98
-
99
- The type shall be a synonym for
100
- `std::basic_string<char, char_traits<char>, Byte_alloc>`
101
-
102
- ``` cpp
103
- size_t converted() const noexcept;
104
- ```
105
-
106
- *Returns:* `cvtcount`.
107
-
108
- ``` cpp
109
- wide_string from_bytes(char byte);
110
- wide_string from_bytes(const char* ptr);
111
- wide_string from_bytes(const byte_string& str);
112
- wide_string from_bytes(const char* first, const char* last);
113
- ```
114
-
115
- *Effects:* The first member function shall convert the single-element
116
- sequence `byte` to a wide string. The second member function shall
117
- convert the null-terminated sequence beginning at `ptr` to a wide
118
- string. The third member function shall convert the sequence stored in
119
- `str` to a wide string. The fourth member function shall convert the
120
- sequence defined by the range \[`first`, `last`) to a wide string.
121
-
122
- In all cases:
123
-
124
- - If the `cvtstate` object was not constructed with an explicit value,
125
- it shall be set to its default value (the initial conversion state)
126
- before the conversion begins. Otherwise it shall be left unchanged.
127
- - The number of input elements successfully converted shall be stored in
128
- `cvtcount`.
129
-
130
- *Returns:* If no conversion error occurs, the member function shall
131
- return the converted wide string. Otherwise, if the object was
132
- constructed with a wide-error string, the member function shall return
133
- the wide-error string. Otherwise, the member function throws an object
134
- of class `std::range_error`.
135
-
136
- ``` cpp
137
- typedef typename wide_string::traits_type::int_type int_type;
138
- ```
139
-
140
- The type shall be a synonym for `wide_string::traits_type::int_type`.
141
-
142
- ``` cpp
143
- state_type state() const;
144
- ```
145
-
146
- returns `cvtstate`.
147
-
148
- ``` cpp
149
- typedef typename Codecvt::state_type state_type;
150
- ```
151
-
152
- The type shall be a synonym for `Codecvt::state_type`.
153
-
154
- ``` cpp
155
- byte_string to_bytes(Elem wchar);
156
- byte_string to_bytes(const Elem* wptr);
157
- byte_string to_bytes(const wide_string& wstr);
158
- byte_string to_bytes(const Elem* first, const Elem* last);
159
- ```
160
-
161
- *Effects:* The first member function shall convert the single-element
162
- sequence `wchar` to a byte string. The second member function shall
163
- convert the null-terminated sequence beginning at `wptr` to a byte
164
- string. The third member function shall convert the sequence stored in
165
- `wstr` to a byte string. The fourth member function shall convert the
166
- sequence defined by the range \[`first`, `last`) to a byte string.
167
-
168
- In all cases:
169
-
170
- - If the `cvtstate` object was not constructed with an explicit value,
171
- it shall be set to its default value (the initial conversion state)
172
- before the conversion begins. Otherwise it shall be left unchanged.
173
- - The number of input elements successfully converted shall be stored in
174
- `cvtcount`.
175
-
176
- *Returns:* If no conversion error occurs, the member function shall
177
- return the converted byte string. Otherwise, if the object was
178
- constructed with a byte-error string, the member function shall return
179
- the byte-error string. Otherwise, the member function shall throw an
180
- object of class `std::range_error`.
181
-
182
- ``` cpp
183
- typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
184
- ```
185
-
186
- The type shall be a synonym for
187
- `std::basic_string<Elem, char_traits<Elem>, Wide_alloc>`.
188
-
189
- ``` cpp
190
- explicit wstring_convert(Codecvt* pcvt = new Codecvt);
191
- wstring_convert(Codecvt* pcvt, state_type state);
192
- explicit wstring_convert(const byte_string& byte_err,
193
- const wide_string& wide_err = wide_string());
194
- ```
195
-
196
- *Requires:* For the first and second constructors, `pcvt != nullptr`.
197
-
198
- *Effects:* The first constructor shall store `pcvt` in `cvtptr` and
199
- default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
200
- The second constructor shall store `pcvt` in `cvtptr`, `state` in
201
- `cvtstate`, and default values in `byte_err_string` and
202
- `wide_err_string`; moreover the stored state shall be retained between
203
- calls to `from_bytes` and `to_bytes`. The third constructor shall store
204
- `new Codecvt` in `cvtptr`, `state_type()` in `cvtstate`, `byte_err` in
205
- `byte_err_string`, and `wide_err` in `wide_err_string`.
206
-
207
- ``` cpp
208
- ~wstring_convert();
209
- ```
210
-
211
- *Effects:* The destructor shall delete `cvtptr`.
212
-
213
- ##### Buffer conversions <a id="conversions.buffer">[[conversions.buffer]]</a>
214
-
215
- Class template `wbuffer_convert` looks like a wide stream buffer, but
216
- performs all its I/O through an underlying byte stream buffer that you
217
- specify when you construct it. Like class template `wstring_convert`, it
218
- lets you specify a code conversion facet to perform the conversions,
219
- without affecting any streams or locales.
220
-
221
- ``` cpp
222
- namespace std {
223
- template<class Codecvt,
224
- class Elem = wchar_t,
225
- class Tr = std::char_traits<Elem> >
226
- class wbuffer_convert
227
- : public std::basic_streambuf<Elem, Tr> {
228
- public:
229
- typedef typename Codecvt::state_type state_type;
230
-
231
- explicit wbuffer_convert(std::streambuf* bytebuf = 0,
232
- Codecvt* pcvt = new Codecvt,
233
- state_type state = state_type());
234
-
235
- ~wbuffer_convert();
236
-
237
- wbuffer_convert(const wbuffer_convert&) = delete;
238
- wbuffer_convert& operator=(const wbuffer_convert&) = delete;
239
-
240
- std::streambuf* rdbuf() const;
241
- std::streambuf* rdbuf(std::streambuf* bytebuf);
242
-
243
- state_type state() const;
244
-
245
- private:
246
- std::streambuf* bufptr; // exposition only
247
- Codecvt* cvtptr; // exposition only
248
- state_type cvtstate; // exposition only
249
- };
250
- }
251
- ```
252
-
253
- The class template describes a stream buffer that controls the
254
- transmission of elements of type `Elem`, whose character traits are
255
- described by the class `Tr`, to and from a byte stream buffer of type
256
- `std::streambuf`. Conversion between a sequence of `Elem` values and
257
- multibyte sequences is performed by an object of class `Codecvt`, which
258
- shall meet the requirements of the standard code-conversion facet
259
- `std::codecvt<Elem, char, std::mbstate_t>`.
260
-
261
- An object of this class template stores:
262
-
263
- - `bufptr` — a pointer to its underlying byte stream buffer
264
- - `cvtptr` — a pointer to the allocated conversion object (which is
265
- freed when the `wbuffer_convert` object is destroyed)
266
- - `cvtstate` — a conversion state object
267
-
268
- ``` cpp
269
- state_type state() const;
270
- ```
271
-
272
- *Returns:* `cvtstate`.
273
-
274
- ``` cpp
275
- std::streambuf* rdbuf() const;
276
- ```
277
-
278
- *Returns:* `bufptr`.
279
-
280
- ``` cpp
281
- std::streambuf* rdbuf(std::streambuf* bytebuf);
282
- ```
283
-
284
- *Effects:* stores `bytebuf` in `bufptr`.
285
-
286
- *Returns:* The previous value of `bufptr`.
287
-
288
- ``` cpp
289
- typedef typename Codecvt::state_type state_type;
290
- ```
291
-
292
- The type shall be a synonym for `Codecvt::state_type`.
293
-
294
- ``` cpp
295
- explicit wbuffer_convert(std::streambuf* bytebuf = 0,
296
- Codecvt* pcvt = new Codecvt, state_type state = state_type());
297
- ```
298
-
299
- *Requires:* `pcvt != nullptr`.
300
-
301
- *Effects:* The constructor constructs a stream buffer object,
302
- initializes `bufptr` to `bytebuf`, initializes `cvtptr` to `pcvt`, and
303
- initializes `cvtstate` to `state`.
304
-
305
- ``` cpp
306
- ~wbuffer_convert();
307
- ```
308
-
309
- *Effects:* The destructor shall delete `cvtptr`.
310
-
 
12
  template <class charT> charT tolower(charT c, const locale& loc);
13
  ```
14
 
15
  *Returns:* `use_facet<ctype<charT>>(loc).tolower(c)`.
16