The class for writing text to streams.
More...
#include "nn/nlib/TextWriter.h"
The class for writing text to streams.
- Description
- Outputs UTF-8 text strings to streams. A BOM is not attached.
- Newline characters are processed as follows.
-
LF is output unmodified.
-
CR is output as LF.
-
CRLF is output as LF.
- With surrogate pairs, if a high surrogate and a low surrogate are not paired, an
EILSEQ
error is generated, const wchar_t str[] = L"wide \r\nstring";
MemoryOutputStream ostr(....);
-
- Examples:
- exi/serializer/serializer.cpp, exi/simple1/simple1.cpp, exi/simple2/simple2.cpp, exi/textparser/textparser.cpp, misc/writefile/writefile.cpp, msgpack/jsonrpc/jsonrpc.cpp, and msgpack/jsonrpc/server.cpp.
Definition at line 33 of file TextWriter.h.
◆ Close()
nn::nlib::TextWriter::Close |
( |
| ) |
|
|
noexcept |
Closes the text writer.
- Returns
- Returns
true
when successful.
- Description
- Clears the reference to the base stream, closes the text writer, and detaches the base stream. The base stream is not closed by this operation.
◆ Flush()
nn::nlib::TextWriter::Flush |
( |
| ) |
|
|
noexcept |
Flushes the text writer and the base stream.
- Returns
- Returns
true
when successful.
- Description
- If this function has been called in the state where data has been written only for a high surrogate, writing of that high surrogate is put on hold.
◆ GetErrorValue()
nn::nlib::TextWriter::GetErrorValue |
( |
| ) |
const |
|
inlinenoexcept |
This function can get the cause of the error when writing has failed.
- Return values
-
0 | No error occurred. |
EINVAL | Invalid argument. |
EEXIST | Initialized redundantly. |
EBADF | No stream to write to. |
EIO | Writing to the stream has failed for some reason. |
EILSEQ | Tried to write an invalid character. |
ENOMEM | Failed to dynamically allocate memory. |
Definition at line 49 of file TextWriter.h.
◆ GetStream()
nn::nlib::TextWriter::GetStream |
( |
| ) |
|
|
inlinenoexcept |
Gets the stream for the text writer to write to.
- Returns
- The pointer to the stream.
Definition at line 50 of file TextWriter.h.
◆ Init()
nn::nlib::TextWriter::Init |
( |
| ) |
|
|
noexcept |
◆ Open()
◆ SetError()
nn::nlib::TextWriter::SetError |
( |
errno_t |
e | ) |
const |
|
inlinenoexcept |
Sets an error value.
- Parameters
-
- Description
- If an error value has not been set, the one specified by e is set.
Definition at line 53 of file TextWriter.h.
◆ Write() [1/8]
nn::nlib::TextWriter::Write |
( |
wchar_t |
c | ) |
|
|
noexcept |
Writes one character to a stream.
- Parameters
-
[in] | c | A wide character (UTF-16 or UTF-32). |
- Returns
- Returns
true
when successful.
◆ Write() [2/8]
nn::nlib::TextWriter::Write |
( |
const wchar_t * |
str | ) |
|
|
noexcept |
Writes a text string to a stream.
- Parameters
-
[in] | str | A wide text string. |
- Returns
- Returns
true
when successful.
◆ Write() [3/8]
nn::nlib::TextWriter::Write |
( |
char |
c | ) |
|
|
noexcept |
Writes one character to a stream.
- Parameters
-
- Returns
- Returns
true
when successful.
- Description
- To write a multibyte string, write the data as a string and not one character at a time. An error is generated (
EILSEQ
).
◆ Write() [4/8]
Writes a text string to a stream.
- Parameters
-
[in] | str | A UTF-8 text string. |
- Returns
- Returns
true
when successful.
◆ Write() [5/8]
Writes one character to a stream.
- Parameters
-
- Returns
- Returns
true
when successful.
- Description
- If a high surrogate has been written, an error occurs if this is not followed by writing a low surrogate.
◆ Write() [6/8]
Writes a text string to a stream.
- Parameters
-
- Returns
- Returns
true
when successful.
◆ Write() [7/8]
Writes one character to a stream.
- Parameters
-
- Returns
- Returns
true
when successful.
◆ Write() [8/8]
Writes a text string to a stream.
- Parameters
-
- Returns
- Returns
true
when successful.
◆ WriteFormat() [1/2]
nn::nlib::TextWriter::WriteFormat |
( |
const wchar_t * |
fmt, |
|
|
|
... |
|
) |
| |
|
noexcept |
Writes a formatted text string to a stream.
- Parameters
-
[in] | fmt | A formatted text string. |
- Returns
- Returns
true
if it succeeds, and false
if it fails.
- Description
- If the function returns
false
, you can use the GetErrorValue
member function to get the cause of the error.
- Examples:
- msgpack/jsonrpc/jsonrpc.cpp, and msgpack/jsonrpc/server.cpp.
◆ WriteFormat() [2/2]
nn::nlib::TextWriter::WriteFormat |
( |
const nlib_utf8_t * |
fmt, |
|
|
|
... |
|
) |
| |
|
noexcept |
Writes a formatted text string to a stream.
- Parameters
-
[in] | fmt | A formatted text string. |
- Returns
- Returns
true
if it succeeds, and false
if it fails.
- Description
- If the function returns
false
, you can use the GetErrorValue
member function to get the cause of the error.
The documentation for this class was generated from the following files: