osgEarth 2.1.1
Public Member Functions | Private Types | Private Attributes

osgEarth::StringTokenizer Class Reference

List of all members.

Public Member Functions

 StringTokenizer (const std::string &delims=" \t\r\n", const std::string &quotes="'\"")
 StringTokenizer (const std::string &input, StringVector &output, const std::string &delims=" \t\r\n", const std::string &quotes="'\"", bool keepEmpties=true, bool trimTokens=true)
void tokenize (const std::string &input, StringVector &output) const
bool & keepEmpties ()
bool & trimTokens ()
void addDelim (char delim, bool keepAsToken=false)
void addDelims (const std::string &delims, bool keepAsTokens=false)
void addQuote (char delim, bool keepInToken=false)
void addQuotes (const std::string &delims, bool keepInTokens=false)

Private Types

typedef std::map< char, bool > TokenMap

Private Attributes

TokenMap _delims
TokenMap _quotes
bool _allowEmpties
bool _trimTokens

Detailed Description

Splits a string up into a vector of strings based on a set of delimiters, quotes, and rules.

Definition at line 94 of file StringUtils.


Member Typedef Documentation

typedef std::map<char,bool> osgEarth::StringTokenizer::TokenMap [private]

Definition at line 119 of file StringUtils.


Constructor & Destructor Documentation

StringTokenizer::StringTokenizer ( const std::string &  delims = " \t\r\n",
const std::string &  quotes = "'\"" 
)

Definition at line 24 of file StringUtils.cpp.

                                                                                   :
_allowEmpties( true ),
_trimTokens  ( true )
{
    addDelims( delims );
    addQuotes( quotes );
}

Here is the call graph for this function:

StringTokenizer::StringTokenizer ( const std::string &  input,
StringVector output,
const std::string &  delims = " \t\r\n",
const std::string &  quotes = "'\"",
bool  keepEmpties = true,
bool  trimTokens = true 
)

Definition at line 32 of file StringUtils.cpp.

                                                                 :
_allowEmpties( allowEmpties ),
_trimTokens  ( trimTokens )
{
    addDelims( delims );
    addQuotes( quotes );
    tokenize( input, output );
}

Here is the call graph for this function:


Member Function Documentation

void StringTokenizer::addDelim ( char  delim,
bool  keepAsToken = false 
)

Definition at line 47 of file StringUtils.cpp.

{
    _delims[delim] = keep;
}

Here is the caller graph for this function:

void StringTokenizer::addDelims ( const std::string &  delims,
bool  keepAsTokens = false 
)

Definition at line 53 of file StringUtils.cpp.

{
    for( unsigned i=0; i<delims.size(); ++i )
        addDelim( delims.at(i), keep );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StringTokenizer::addQuote ( char  delim,
bool  keepInToken = false 
)

Definition at line 60 of file StringUtils.cpp.

{
    _quotes[quote] = keep;
}

Here is the caller graph for this function:

void StringTokenizer::addQuotes ( const std::string &  delims,
bool  keepInTokens = false 
)

Definition at line 66 of file StringUtils.cpp.

{
    for( unsigned i=0; i<quotes.size(); ++i )
        addQuote( quotes.at(i), keep );
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool& osgEarth::StringTokenizer::keepEmpties ( ) [inline]

Definition at line 106 of file StringUtils.

{ return _allowEmpties; }

Here is the caller graph for this function:

void StringTokenizer::tokenize ( const std::string &  input,
StringVector output 
) const

Definition at line 73 of file StringUtils.cpp.

{
    output.clear();

    std::stringstream buf;
    bool quoted = false;
    for( std::string::const_iterator i = input.begin(); i != input.end(); ++i )
    {
        char c = *i;    

        TokenMap::const_iterator q = _quotes.find( c );

        if ( quoted )
        {
            if ( q != _quotes.end() )
            {
                quoted = false;
                if ( q->second )
                    buf << c;
            }
            else
            {
                buf << c;
            }
        }
        else
        {
            if ( q != _quotes.end() )
            {
                quoted = true;
                if ( q->second )
                    buf << c;
            }
            else
            {
                TokenMap::const_iterator d = _delims.find( c );
                if ( d == _delims.end() )
                {
                    buf << c;
                }
                else
                {
                    std::string token = _trimTokens ? trim(buf.str()) : buf.str();

                    if ( _allowEmpties || !token.empty() )
                        output.push_back( token );

                    if ( d->second == true )
                    {
                        output.push_back( std::string(1, c) );
                    }

                    buf.str("");
                }
            }
        }       
    }

    std::string last = _trimTokens ? trim(buf.str()) : buf.str();
    if ( !last.empty() )
        output.push_back( last );
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool& osgEarth::StringTokenizer::trimTokens ( ) [inline]

Definition at line 108 of file StringUtils.

{ return _trimTokens; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 122 of file StringUtils.

Definition at line 120 of file StringUtils.

Definition at line 121 of file StringUtils.

Definition at line 123 of file StringUtils.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines