tmp/tmpwsa8e8fi/{from.md → to.md}
RENAMED
|
@@ -46,18 +46,17 @@ template <class charT> charT tolower(charT c, const locale& loc);
|
|
| 46 |
##### `string` conversions <a id="conversions.string">[[conversions.string]]</a>
|
| 47 |
|
| 48 |
Class template `wstring_convert` performs conversions between a wide
|
| 49 |
string and a byte string. It lets you specify a code conversion facet
|
| 50 |
(like class template `codecvt`) to perform the conversions, without
|
| 51 |
-
affecting any streams or locales.
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
like:
|
| 56 |
|
| 57 |
``` cpp
|
| 58 |
-
wstring_convert<codecvt_utf8<wchar_t>> myconv;
|
| 59 |
std::string mbstring = myconv.to_bytes(L"Hello\n");
|
| 60 |
std::cout << mbstring;
|
| 61 |
```
|
| 62 |
|
| 63 |
``` cpp
|
|
@@ -69,27 +68,30 @@ template<class Codecvt, class Elem = wchar_t,
|
|
| 69 |
typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
|
| 70 |
typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
|
| 71 |
typedef typename Codecvt::state_type state_type;
|
| 72 |
typedef typename wide_string::traits_type::int_type int_type;
|
| 73 |
|
| 74 |
-
wstring_convert(Codecvt
|
| 75 |
wstring_convert(Codecvt* pcvt, state_type state);
|
| 76 |
-
wstring_convert(const byte_string& byte_err,
|
| 77 |
const wide_string& wide_err = wide_string());
|
| 78 |
~wstring_convert();
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
wide_string from_bytes(char byte);
|
| 81 |
wide_string from_bytes(const char* ptr);
|
| 82 |
wide_string from_bytes(const byte_string& str);
|
| 83 |
wide_string from_bytes(const char* first, const char* last);
|
| 84 |
|
| 85 |
byte_string to_bytes(Elem wchar);
|
| 86 |
byte_string to_bytes(const Elem* wptr);
|
| 87 |
byte_string to_bytes(const wide_string& wstr);
|
| 88 |
byte_string to_bytes(const Elem* first, const Elem* last);
|
| 89 |
|
| 90 |
-
size_t converted() const;
|
| 91 |
state_type state() const;
|
| 92 |
private:
|
| 93 |
byte_string byte_err_string; // exposition only
|
| 94 |
wide_string wide_err_string; // exposition only
|
| 95 |
Codecvt* cvtptr; // exposition only
|
|
@@ -102,15 +104,14 @@ template<class Codecvt, class Elem = wchar_t,
|
|
| 102 |
The class template describes an object that controls conversions between
|
| 103 |
wide string objects of class `std::basic_string<Elem, char_traits<Elem>,
|
| 104 |
Wide_alloc>` and byte string objects of class `std::\\basic_string<char,
|
| 105 |
char_traits<char>, Byte_alloc>`. The class template defines the types
|
| 106 |
`wide_string` and `byte_string` as synonyms for these two types.
|
| 107 |
-
Conversion between a sequence of `Elem` values (stored in a
|
| 108 |
-
object) and multibyte sequences (stored in a byte_string
|
| 109 |
-
performed by an object of class `Codecvt
|
| 110 |
-
|
| 111 |
-
`std::codecvt<Elem,
|
| 112 |
char, std::mbstate_t>`.
|
| 113 |
|
| 114 |
An object of this class template stores:
|
| 115 |
|
| 116 |
- `byte_err_string` — a byte string to display on errors
|
|
@@ -119,17 +120,18 @@ An object of this class template stores:
|
|
| 119 |
freed when the `wstring_convert` object is destroyed)
|
| 120 |
- `cvtstate` — a conversion state object
|
| 121 |
- `cvtcount` — a conversion count
|
| 122 |
|
| 123 |
``` cpp
|
| 124 |
-
typedef std::basic_string<char> byte_string;
|
| 125 |
```
|
| 126 |
|
| 127 |
-
The type shall be a synonym for
|
|
|
|
| 128 |
|
| 129 |
``` cpp
|
| 130 |
-
size_t converted() const;
|
| 131 |
```
|
| 132 |
|
| 133 |
*Returns:* `cvtcount`.
|
| 134 |
|
| 135 |
``` cpp
|
|
@@ -205,22 +207,25 @@ return the converted byte string. Otherwise, if the object was
|
|
| 205 |
constructed with a byte-error string, the member function shall return
|
| 206 |
the byte-error string. Otherwise, the member function shall throw an
|
| 207 |
object of class `std::range_error`.
|
| 208 |
|
| 209 |
``` cpp
|
| 210 |
-
typedef std::basic_string<Elem> wide_string;
|
| 211 |
```
|
| 212 |
|
| 213 |
-
The type shall be a synonym for
|
|
|
|
| 214 |
|
| 215 |
``` cpp
|
| 216 |
-
wstring_convert(Codecvt
|
| 217 |
wstring_convert(Codecvt* pcvt, state_type state);
|
| 218 |
-
wstring_convert(const byte_string& byte_err,
|
| 219 |
const wide_string& wide_err = wide_string());
|
| 220 |
```
|
| 221 |
|
|
|
|
|
|
|
| 222 |
*Effects:* The first constructor shall store `pcvt` in `cvtptr` and
|
| 223 |
default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
|
| 224 |
The second constructor shall store `pcvt` in `cvtptr`, `state` in
|
| 225 |
`cvtstate`, and default values in `byte_err_string` and
|
| 226 |
`wide_err_string`; moreover the stored state shall be retained between
|
|
@@ -250,14 +255,19 @@ template<class Codecvt,
|
|
| 250 |
class wbuffer_convert
|
| 251 |
: public std::basic_streambuf<Elem, Tr> {
|
| 252 |
public:
|
| 253 |
typedef typename Codecvt::state_type state_type;
|
| 254 |
|
| 255 |
-
wbuffer_convert(std::streambuf
|
| 256 |
Codecvt* pcvt = new Codecvt,
|
| 257 |
state_type state = state_type());
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
std::streambuf* rdbuf() const;
|
| 260 |
std::streambuf* rdbuf(std::streambuf* bytebuf);
|
| 261 |
|
| 262 |
state_type state() const;
|
| 263 |
|
|
@@ -271,13 +281,12 @@ template<class Codecvt,
|
|
| 271 |
|
| 272 |
The class template describes a stream buffer that controls the
|
| 273 |
transmission of elements of type `Elem`, whose character traits are
|
| 274 |
described by the class `Tr`, to and from a byte stream buffer of type
|
| 275 |
`std::streambuf`. Conversion between a sequence of `Elem` values and
|
| 276 |
-
multibyte sequences is performed by an object of class
|
| 277 |
-
|
| 278 |
-
of the standard code-conversion facet
|
| 279 |
`std::codecvt<Elem, char, std::mbstate_t>`.
|
| 280 |
|
| 281 |
An object of this class template stores:
|
| 282 |
|
| 283 |
- `bufptr` — a pointer to its underlying byte stream buffer
|
|
@@ -310,14 +319,16 @@ typedef typename Codecvt::state_type state_type;
|
|
| 310 |
```
|
| 311 |
|
| 312 |
The type shall be a synonym for `Codecvt::state_type`.
|
| 313 |
|
| 314 |
``` cpp
|
| 315 |
-
wbuffer_convert(std::streambuf
|
| 316 |
Codecvt* pcvt = new Codecvt, state_type state = state_type());
|
| 317 |
```
|
| 318 |
|
|
|
|
|
|
|
| 319 |
*Effects:* The constructor constructs a stream buffer object,
|
| 320 |
initializes `bufptr` to `bytebuf`, initializes `cvtptr` to `pcvt`, and
|
| 321 |
initializes `cvtstate` to `state`.
|
| 322 |
|
| 323 |
``` cpp
|
|
|
|
| 46 |
##### `string` conversions <a id="conversions.string">[[conversions.string]]</a>
|
| 47 |
|
| 48 |
Class template `wstring_convert` performs conversions between a wide
|
| 49 |
string and a byte string. It lets you specify a code conversion facet
|
| 50 |
(like class template `codecvt`) to perform the conversions, without
|
| 51 |
+
affecting any streams or locales. If you want to use the code conversion
|
| 52 |
+
facet `codecvt_utf8` to output to `cout` a UTF-8 multibyte sequence
|
| 53 |
+
corresponding to a wide string, but you don’t want to alter the locale
|
| 54 |
+
for `cout`, you can write something like:
|
|
|
|
| 55 |
|
| 56 |
``` cpp
|
| 57 |
+
wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
|
| 58 |
std::string mbstring = myconv.to_bytes(L"Hello\n");
|
| 59 |
std::cout << mbstring;
|
| 60 |
```
|
| 61 |
|
| 62 |
``` cpp
|
|
|
|
| 68 |
typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
|
| 69 |
typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
|
| 70 |
typedef typename Codecvt::state_type state_type;
|
| 71 |
typedef typename wide_string::traits_type::int_type int_type;
|
| 72 |
|
| 73 |
+
explicit wstring_convert(Codecvt* pcvt = new Codecvt);
|
| 74 |
wstring_convert(Codecvt* pcvt, state_type state);
|
| 75 |
+
explicit wstring_convert(const byte_string& byte_err,
|
| 76 |
const wide_string& wide_err = wide_string());
|
| 77 |
~wstring_convert();
|
| 78 |
|
| 79 |
+
wstring_convert(const wstring_convert&) = delete;
|
| 80 |
+
wstring_convert& operator=(const wstring_convert&) = delete;
|
| 81 |
+
|
| 82 |
wide_string from_bytes(char byte);
|
| 83 |
wide_string from_bytes(const char* ptr);
|
| 84 |
wide_string from_bytes(const byte_string& str);
|
| 85 |
wide_string from_bytes(const char* first, const char* last);
|
| 86 |
|
| 87 |
byte_string to_bytes(Elem wchar);
|
| 88 |
byte_string to_bytes(const Elem* wptr);
|
| 89 |
byte_string to_bytes(const wide_string& wstr);
|
| 90 |
byte_string to_bytes(const Elem* first, const Elem* last);
|
| 91 |
|
| 92 |
+
size_t converted() const noexcept;
|
| 93 |
state_type state() const;
|
| 94 |
private:
|
| 95 |
byte_string byte_err_string; // exposition only
|
| 96 |
wide_string wide_err_string; // exposition only
|
| 97 |
Codecvt* cvtptr; // exposition only
|
|
|
|
| 104 |
The class template describes an object that controls conversions between
|
| 105 |
wide string objects of class `std::basic_string<Elem, char_traits<Elem>,
|
| 106 |
Wide_alloc>` and byte string objects of class `std::\\basic_string<char,
|
| 107 |
char_traits<char>, Byte_alloc>`. The class template defines the types
|
| 108 |
`wide_string` and `byte_string` as synonyms for these two types.
|
| 109 |
+
Conversion between a sequence of `Elem` values (stored in a
|
| 110 |
+
`wide_string` object) and multibyte sequences (stored in a `byte_string`
|
| 111 |
+
object) is performed by an object of class `Codecvt`, which meets the
|
| 112 |
+
requirements of the standard code-conversion facet `std::codecvt<Elem,
|
|
|
|
| 113 |
char, std::mbstate_t>`.
|
| 114 |
|
| 115 |
An object of this class template stores:
|
| 116 |
|
| 117 |
- `byte_err_string` — a byte string to display on errors
|
|
|
|
| 120 |
freed when the `wstring_convert` object is destroyed)
|
| 121 |
- `cvtstate` — a conversion state object
|
| 122 |
- `cvtcount` — a conversion count
|
| 123 |
|
| 124 |
``` cpp
|
| 125 |
+
typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
|
| 126 |
```
|
| 127 |
|
| 128 |
+
The type shall be a synonym for
|
| 129 |
+
`std::basic_string<char, char_traits<char>, Byte_alloc>`
|
| 130 |
|
| 131 |
``` cpp
|
| 132 |
+
size_t converted() const noexcept;
|
| 133 |
```
|
| 134 |
|
| 135 |
*Returns:* `cvtcount`.
|
| 136 |
|
| 137 |
``` cpp
|
|
|
|
| 207 |
constructed with a byte-error string, the member function shall return
|
| 208 |
the byte-error string. Otherwise, the member function shall throw an
|
| 209 |
object of class `std::range_error`.
|
| 210 |
|
| 211 |
``` cpp
|
| 212 |
+
typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
|
| 213 |
```
|
| 214 |
|
| 215 |
+
The type shall be a synonym for
|
| 216 |
+
`std::basic_string<Elem, char_traits<Elem>, Wide_alloc>`.
|
| 217 |
|
| 218 |
``` cpp
|
| 219 |
+
explicit wstring_convert(Codecvt* pcvt = new Codecvt);
|
| 220 |
wstring_convert(Codecvt* pcvt, state_type state);
|
| 221 |
+
explicit wstring_convert(const byte_string& byte_err,
|
| 222 |
const wide_string& wide_err = wide_string());
|
| 223 |
```
|
| 224 |
|
| 225 |
+
*Requires:* For the first and second constructors, `pcvt != nullptr`.
|
| 226 |
+
|
| 227 |
*Effects:* The first constructor shall store `pcvt` in `cvtptr` and
|
| 228 |
default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
|
| 229 |
The second constructor shall store `pcvt` in `cvtptr`, `state` in
|
| 230 |
`cvtstate`, and default values in `byte_err_string` and
|
| 231 |
`wide_err_string`; moreover the stored state shall be retained between
|
|
|
|
| 255 |
class wbuffer_convert
|
| 256 |
: public std::basic_streambuf<Elem, Tr> {
|
| 257 |
public:
|
| 258 |
typedef typename Codecvt::state_type state_type;
|
| 259 |
|
| 260 |
+
explicit wbuffer_convert(std::streambuf* bytebuf = 0,
|
| 261 |
Codecvt* pcvt = new Codecvt,
|
| 262 |
state_type state = state_type());
|
| 263 |
|
| 264 |
+
~wbuffer_convert();
|
| 265 |
+
|
| 266 |
+
wbuffer_convert(const wbuffer_convert&) = delete;
|
| 267 |
+
wbuffer_convert& operator=(const wbuffer_convert&) = delete;
|
| 268 |
+
|
| 269 |
std::streambuf* rdbuf() const;
|
| 270 |
std::streambuf* rdbuf(std::streambuf* bytebuf);
|
| 271 |
|
| 272 |
state_type state() const;
|
| 273 |
|
|
|
|
| 281 |
|
| 282 |
The class template describes a stream buffer that controls the
|
| 283 |
transmission of elements of type `Elem`, whose character traits are
|
| 284 |
described by the class `Tr`, to and from a byte stream buffer of type
|
| 285 |
`std::streambuf`. Conversion between a sequence of `Elem` values and
|
| 286 |
+
multibyte sequences is performed by an object of class `Codecvt`, which
|
| 287 |
+
shall meet the requirements of the standard code-conversion facet
|
|
|
|
| 288 |
`std::codecvt<Elem, char, std::mbstate_t>`.
|
| 289 |
|
| 290 |
An object of this class template stores:
|
| 291 |
|
| 292 |
- `bufptr` — a pointer to its underlying byte stream buffer
|
|
|
|
| 319 |
```
|
| 320 |
|
| 321 |
The type shall be a synonym for `Codecvt::state_type`.
|
| 322 |
|
| 323 |
``` cpp
|
| 324 |
+
explicit wbuffer_convert(std::streambuf* bytebuf = 0,
|
| 325 |
Codecvt* pcvt = new Codecvt, state_type state = state_type());
|
| 326 |
```
|
| 327 |
|
| 328 |
+
*Requires:* `pcvt != nullptr`.
|
| 329 |
+
|
| 330 |
*Effects:* The constructor constructs a stream buffer object,
|
| 331 |
initializes `bufptr` to `bytebuf`, initializes `cvtptr` to `pcvt`, and
|
| 332 |
initializes `cvtstate` to `state`.
|
| 333 |
|
| 334 |
``` cpp
|