This struct implements the interface given with StringEscaper. Its purpose is to convert string data to external string representations and vice versa. Such conversion is needed when C++ strings contain non-readable characters like 'new line', 'carriage return' or 'tabulator' and such strings should be stored in ASCII or unicode files. The common way of conversion is to add "escape sequences", for example "\n"
for the 'new line' character.
Furthermore if a C++ string starts or ends with spaces, the string has to be quoted and in this case occurences of the quote character (")
inside the string have to be escaped. Quotation is also needed, if a series of strings, separated by possible delimiter characters needs to be escaped, and a string contains one of the delimiters itself. Likewise, when such string is imported back to C++ representation, delimiters must only be recognized when outside of quoted string tokens.
With this approach, this implementation should be compatible with INI-files, JSon files and such. If a different approach is needed, the virtual functions may be overridden by custom descendents.
This default implementation proceeds as follows:
'\'
. Those are \n
, \r
, \t
, \a
, \b
, \v
, \f
, \e
and also the double quotation marks \" and the backslash itself (\c \\\\).
- "Internalizing" a value:
- If (non-escaped) quote \c "
characters are found, those are removed and whitespaces within such quotes are kept.Definition at line 130 of file escaper.hpp.
#include <escaper.hpp>
Public Method Index: | |
virtual | ~StringEscaperStandard () override |
Virtual destructor. | |
virtual ALIB_API AString & | Escape (const String &src, AString &dest, const String &delimiters) const override |
virtual ALIB_API int | EscapeTokens (StringVectorMA &result, const String &src, const String &delimiters) const override |
virtual ALIB_API AString & | Unescape (const String &src, AString &dest) const override |
virtual ALIB_API int | UnescapeTokens (StringVectorMA &result, const String &src, const String &delimiters) const override |
Public Method Index: inherited from StringEscaper | |
virtual | ~StringEscaper () |
Virtual destructor. | |
|
inlineoverridevirtual |
Virtual destructor.
Definition at line 133 of file escaper.hpp.
|
overridevirtual |
Converts the given src string to an external representation. The escape symbol is backslash '\'
and the following characters are escaped: \n
, \r
, \t
, \a
, \b
, \v
, \f
, \e
. Furthermore the double quotation marks \" and the backslash itself (\c \\\\).<br>
Besides that, the value is surrounded by double quotes \c "
if it starts or ends with spaces or if it includes one of the delimiter characters. The rationale of the latter is understood when it comes to method UnescapeTokens: Here, delimiters are ignored if they reside in a quoted string. If neither trailing nor leading spaces nor a delimiter is found, the string is not quoted. In situations, a quoted string is always needed, the caller has to test if a string was quoted and add the quote after the invocation of this method.
src | The source string to convert to external representation. |
dest | The destination string buffer. |
delimiters | If one of these characters is found in the string, the value is quoted |
Reimplemented from StringEscaper.
Definition at line 81 of file escaper.cpp.
|
overridevirtual |
Parses a list of tokens separated by the given delimiter and calls method Escape for each of them. The results are copied to string list result.
result | The destination list of strings. |
src | The source string. |
delimiters | A set of characters defining the delimiters. |
Reimplemented from StringEscaper.
Definition at line 128 of file escaper.cpp.
Trims src, removes surrounding quotes and, un-escapes characters as defined with method Escape.
src | The source string. |
dest | The destination string. |
Reimplemented from StringEscaper.
Definition at line 35 of file escaper.cpp.
|
overridevirtual |
Parses a list of tokens separated by the given delimiter and calls method Unescape for each of them. The results are copied to string list result. Delimiters found within quoted strings are rightfully ignored.
result | The destination list of strings. |
src | The source string. |
delimiters | A set of characters accepted as delimiters. |
Reimplemented from StringEscaper.
Definition at line 142 of file escaper.cpp.