An object performs mappings between ASCII character set ranges. To use a CharSetTranslator, you construct it and then use either one of of the following members: More...
#include <charSetTranslator.h>
Classes | |
struct | LhsSubrange |
Information needed to describe character ranges in the left hand side of the mapping. More... | |
Public Member Functions | |
CharSetTranslator (std::string const &inset, std::string const &outset) | |
Create the mapping between the the characters defined in the inset and the outset and store it in the mapping_ member. | |
char const * | error () const |
bool | ok () const |
char | operator[] (unsigned char i) const |
map a character | |
std::string | translate (std::string const &s) const |
Copy and translate a string. If the construction of *this failed, then return empty string. | |
Static Public Member Functions | |
static std::string | unEscape (std::string const &in) |
Convert an input string to an output string by translating the standard C++ language escape character sequences into the characters they represent. For example: | |
Private Types | |
typedef std::list< LhsSubrange > | LhsRange |
Private Member Functions | |
void | populateLhs (char const *inset, LhsRange &lhs) |
Parse the left hand side of the character translation into a list of sub-ranges to be extracted from the right hand side. | |
void | populateMapping (LhsRange const &lhs, char const *rhs) |
Combine the list of character specified on the left hand side with the values defined on the right to produce the mappingSet_ member. | |
void | populateRhs (char const *set, char *rhs) |
Parse a sequence of characters into a buffer of up to 256 character positions. The final character in the sequence will be used to populate the empty slots. | |
Private Attributes | |
char const * | error_ |
error text associated with ok_ being false | |
char | mapping_ [256] |
A mapping between an input character set and an output character set. | |
bool | ok_ |
Flag indicating that all is good with this container. |
An object performs mappings between ASCII character set ranges. To use a CharSetTranslator, you construct it and then use either one of of the following members:
A translator is constructed using a pair of std::string which define characters to be translated. Sequences of characters may be specified to reduce typing. Here are some examples:
CharSetTranslator("z","z"); -- empty translation. It leaves all input characters untouched. CharSetTranslator("a-z", "A-Z"); -- performs the upper case operation. Only characters in the range a-z will be affected. CharSetTranslator("\o000-\o377", " "); -- converts all characters into space. When the output set is shorter than the input set, the final character of the outputset is used for any characters missed in the input set. CharSetTranslator("a-fA-F", "1-61-6"); -- converts all letters to numbers.
Definition at line 11 of file charSetTranslator.h.
typedef std::list< LhsSubrange > LhsRange [private] |
Definition at line 72 of file charSetTranslator.h.
CharSetTranslator | ( | std::string const & | inset, | |
std::string const & | outset | |||
) |
Create the mapping between the the characters defined in the inset and the outset and store it in the mapping_ member.
Both the inset and the outset are specified in the style of regular expression character sets:
set := {char | charRange} charRange := char "-" char
For example:
-+a-fA-F0-9
Which means all of the following:
Definition at line 79 of file charSetTranslator.h.
char const* error | ( | ) | const |
Definition at line 77 of file charSetTranslator.h.
bool ok | ( | ) | const |
Definition at line 76 of file charSetTranslator.h.
char operator[] | ( | unsigned char | i | ) | const |
map a character
Definition at line 124 of file charSetTranslator.h.
void populateLhs | ( | char const * | inset, | |
LhsRange & | lhs | |||
) | [private] |
Parse the left hand side of the character translation into a list of sub-ranges to be extracted from the right hand side.
Definition at line 23 of file charSetTranslator.cxx.
void populateMapping | ( | LhsRange const & | lhs, | |
char const * | rhs | |||
) | [private] |
Combine the list of character specified on the left hand side with the values defined on the right to produce the mappingSet_ member.
Definition at line 148 of file charSetTranslator.cxx.
void populateRhs | ( | char const * | set, | |
char * | rhs | |||
) | [private] |
Parse a sequence of characters into a buffer of up to 256 character positions. The final character in the sequence will be used to populate the empty slots.
Definition at line 79 of file charSetTranslator.cxx.
std::string translate | ( | std::string const & | s | ) | const |
Copy and translate a string. If the construction of *this failed, then return empty string.
Definition at line 5 of file charSetTranslator.cxx.
std::string unEscape | ( | std::string const & | in | ) | [static] |
Convert an input string to an output string by translating the standard C++ language escape character sequences into the characters they represent. For example:
\n - newline
\r - return characters
\t - tab
etc.
Definition at line 176 of file charSetTranslator.cxx.
char const* error_ [private] |
error text associated with ok_ being false
Definition at line 55 of file charSetTranslator.h.
char mapping_[256] [private] |
A mapping between an input character set and an output character set.
Definition at line 50 of file charSetTranslator.h.
bool ok_ [private] |
Flag indicating that all is good with this container.
Definition at line 53 of file charSetTranslator.h.