CharSetTranslator Class Reference

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>

List of all members.

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< LhsSubrangeLhsRange

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.

Detailed Description

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.


Member Typedef Documentation

typedef std::list< LhsSubrange > LhsRange [private]

Definition at line 72 of file charSetTranslator.h.


Constructor & Destructor Documentation

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
Note:
to specify "-" as a single character, it must be first in the set. For example: "-abc", includes "-" as a character, but "a-z", specifies all characters in the range "a" thorugh "z".

For example:

           -+a-fA-F0-9

Which means all of the following:

  • the character -
  • the character +
  • the range of characters 'a' through, and including 'f'
  • the range of characters 'A' through, and including 'F'
  • the range of characters '0' thorugh, and including '9'

Definition at line 79 of file charSetTranslator.h.

Here is the call graph for this function:


Member Function Documentation

char const* error (  )  const
Returns:
error message if any

Definition at line 77 of file charSetTranslator.h.

bool ok (  )  const
Returns:
true to indicate a successful construction

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.

Here is the caller graph for this function:

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.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Here is the caller graph for this function:

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.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Here is the caller graph for this function:


Member Data Documentation

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.


The documentation for this class was generated from the following files:
Generated on Wed Feb 29 22:52:41 2012 for CXXUtilities by  doxygen 1.6.3