Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7319 in orxonox.OLD


Ignore:
Timestamp:
Apr 17, 2006, 1:00:09 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: MUCH more comprehensive SubString

Location:
trunk/src/lib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/graphics_engine.cc

    r7256 r7319  
    317317  PRINT(4)("Running on : vendor: %s,  renderer: %s,  version:%s\n", vendor, renderer, version);
    318318  PRINT(4)("Extensions:\n");
    319   for (unsigned int i = 0; i < this->hwExtensions.getCount(); i++)
    320     PRINT(4)("%d: %s\n", i, this->hwExtensions.getString(i).c_str());
     319  for (unsigned int i = 0; i < this->hwExtensions.size(); i++)
     320    PRINT(4)("%d: %s\n", i, this->hwExtensions[i].c_str());
    321321
    322322
     
    514514bool GraphicsEngine::hwSupportsEXT(const std::string& extension)
    515515{
    516   for (unsigned int i = 0; i < this->hwExtensions.getCount(); i++)
     516  for (unsigned int i = 0; i < this->hwExtensions.size(); i++)
    517517    if ( this->hwExtensions.getString(i) == extension)
    518518      return true;
  • trunk/src/lib/parser/cmdline_parser/cmdline_parser.cc

    r7260 r7319  
    1111   ### File Specific:
    1212   main-programmer: Christoph Renner
    13    co-programmer: 
     13   co-programmer:
    1414*/
    1515
     
    4040{
    4141  ArgTableEntry entry;
    42  
     42
    4343  entry.id = id;
    4444  entry.longOption = longOption;
     
    4747  entry.argNames = argNames;
    4848  entry.help = help;
    49  
     49
    5050  if ( back )
    5151    argTable.push_back( entry );
     
    5858{
    5959  this->exeName = argv[0];
    60  
     60
    6161  //put all args in vector
    6262  std::vector<std::string> args;
    63  
     63
    6464  for ( int i = 1; i<argc; i++ )
    6565  {
    6666    std::string s = argv[i];
    67    
     67
    6868    if ( s.find( "=" ) == std::string::npos )
    6969    {
     
    8888      op.erase( op.find("=") );
    8989      ar.erase( 0, ar.find("=")+1);
    90      
     90
    9191      //PRINTF(0)("'%s' '%s'\n", op.c_str(), ar.c_str());
    9292      args.push_back( op );
     
    9494    }
    9595  }
    96  
     96
    9797  int i = 0;
    98  
     98
    9999  ArgTable::iterator it;
    100100  bool finish;
    101101  bool found;
    102  
     102
    103103  while ( i < args.size() )
    104104  {
     
    109109      {
    110110        found = true;
    111        
     111
    112112        int posArgs = 1;
    113        
     113
    114114        while ( i + posArgs < args.size() )
    115115        {
     
    119119            posArgs++;
    120120        }
    121        
     121
    122122        posArgs--;
    123        
     123
    124124        if ( it->numArgs > posArgs )
    125125        {
     
    127127          return false;
    128128        }
    129        
     129
    130130        std::vector<MultiType> argArgs;
    131        
     131
    132132        for ( int j = 1; j <= it->numArgs; j++ )
    133133          argArgs.push_back( args[i+j] );
    134        
     134
    135135        if ( !cb( *it, data, args[i], argArgs ) )
    136136          return false;
    137        
     137
    138138        i += it->numArgs;
    139        
     139
    140140        if ( finish )
    141141        {
     
    143143          break;
    144144        }
    145         else 
    146         { 
     145        else
     146        {
    147147          assert( it->numArgs == 0 );
    148148        }
    149149      }
    150150    }
    151    
     151
    152152    if ( !found )
    153153    {
     
    156156    }
    157157  }
    158  
     158
    159159  return true;
    160160}
     
    163163{
    164164  finish = true;
    165  
     165
    166166  if ( arg.length() < 2 )
    167167    return false;
    168  
     168
    169169  if ( arg[0] == '-' )
    170170  {
     
    172172    {
    173173      arg.erase( 0, 2 );
    174      
     174
    175175      if ( entry.longOption.find('%') != std::string::npos )
    176176      {
     
    208208  printf("Usage: %s [options]\n", exeName.c_str());
    209209  printf("\n");
    210  
     210
    211211  std::list<std::vector<std::string> > output;
    212  
     212
    213213  for ( ArgTable::iterator it = argTable.begin(); it != argTable.end(); it++ )
    214214  {
    215215    output.push_back( std::vector<std::string>() );
    216    
     216
    217217    SubString substr( it->argNames );
    218218    std::string args;
    219     assert( it->numArgs == substr.getCount() );
    220      
     219    assert( it->numArgs == substr.size() );
     220
    221221    for ( int i = 0; i<it->numArgs; i++ )
    222222    {
    223223      args += " [" + substr[i] + "]";
    224224    }
    225    
     225
    226226    if ( it->shortOption != '\0' )
    227227    {
     
    231231    else
    232232      output.back().push_back( "" );
    233    
     233
    234234    if ( it->longOption != "" )
    235235    {
    236236      output.back().push_back( "--" + it->longOption );
    237      
     237
    238238      output.back().back() += args;
    239239    }
    240240    else
    241241      output.back().push_back( "" );
    242    
     242
    243243    output.back().push_back( it->help );
    244244  }
    245  
     245
    246246  output.push_back( std::vector<std::string>() );
    247247  output.back().push_back( "Option" );
    248248  output.back().push_back( "Long option" );
    249249  output.back().push_back( "Description" );
    250  
     250
    251251  output.reverse();
    252  
     252
    253253  int maxShort = 0;
    254254  int maxLong = 0;
    255  
     255
    256256  std::list<std::vector<std::string> >::const_iterator it;
    257  
     257
    258258  for ( it = output.begin(); it != output.end(); it++ )
    259259  {
    260260    if ( (*it)[0].length() > maxShort )
    261261      maxShort = (*it)[0].length();
    262    
     262
    263263    if ( (*it)[1].length() > maxLong )
    264264      maxLong = (*it)[1].length();
    265265  }
    266  
     266
    267267  for ( it = output.begin(); it != output.end(); it++ )
    268268  {
    269269    printf("%s ", (*it)[0].c_str());
    270    
     270
    271271    for ( int i = 0; i<maxShort-(*it)[0].length(); i++ )
    272272      printf(" ");
    273    
     273
    274274    printf("%s ", (*it)[1].c_str());
    275    
     275
    276276    for ( int i = 0; i<maxLong-(*it)[1].length(); i++ )
    277277      printf(" ");
    278    
     278
    279279    printf("%s\n", (*it)[2].c_str());
    280280  }
    281  
     281
    282282  exit(0);
    283283}
  • trunk/src/lib/shell/shell_command.cc

    r7225 r7319  
    165165  SubString inputSplits(executionString, " \t\n,");
    166166
    167   if (inputSplits.getCount() == 0)
     167  if (inputSplits.size() == 0)
    168168    return false;
    169   if (inputSplits.getCount() >= 1)
     169  if (inputSplits.size() >= 1)
    170170  {
    171171    // CHECK FOR ALIAS
     
    181181          if (objectList != NULL)
    182182          {
    183             if (inputSplits.getCount() > 1)
     183            if (inputSplits.size() > 1)
    184184            {
    185185
     
    210210    }
    211211
    212     if (commandClass != NULL && inputSplits.getCount() >= 2)
     212    if (commandClass != NULL && inputSplits.size() >= 2)
    213213    {
    214214      if (objectList != NULL)
     
    231231      }
    232232      // match a function.
    233       if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))
     233      if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.size() >= 3)))
    234234      {
    235235        list<ShellCommand*>::iterator cmdIT;
     
    240240            if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective)
    241241              return false;
    242             if (inputSplits.getCount() > fktPos+1)
     242            if (inputSplits.size() > fktPos+1)
    243243              (*cmdIT)->executor->execute(objectPointer, executionString.substr(inputSplits.getOffset(fktPos +1))); /// TODO CHECK IF OK
    244244            else
  • trunk/src/lib/shell/shell_completion.cc

    r7225 r7319  
    8888    completeString = "";
    8989  else
    90     completeString = inputSplits.getString(inputSplits.getCount()-1).c_str();
     90    completeString = inputSplits.getString(inputSplits.size()-1).c_str();
    9191
    9292  // CLASS COMPLETION
    93   if (inputSplits.getCount() == 0)
     93  if (inputSplits.size() == 0)
    9494  {
    9595    completeType |= SHELLC_CLASS;
    9696    completeType |= SHELLC_ALIAS;
    9797  }
    98   else if (inputSplits.getCount() == 1 && emptyComplete == false)
     98  else if (inputSplits.size() == 1 && emptyComplete == false)
    9999  {
    100100    completeType |= SHELLC_CLASS;
     
    103103
    104104  // OBJECT/FUNCTION COMPLETIONS
    105   else if ((inputSplits.getCount() == 1 && emptyComplete == true) ||
    106             (inputSplits.getCount() == 2 && emptyComplete == false))
     105  else if ((inputSplits.size() == 1 && emptyComplete == true) ||
     106            (inputSplits.size() == 2 && emptyComplete == false))
    107107  {
    108108    classID = ClassList::StringToID(inputSplits.getString(0).c_str()); //FIXME
     
    113113      completeType |= SHELLC_FUNCTION;
    114114  }
    115   else if ((inputSplits.getCount() == 2 && emptyComplete == true) ||
    116             (inputSplits.getCount() == 3 && emptyComplete == false))
     115  else if ((inputSplits.size() == 2 && emptyComplete == true) ||
     116            (inputSplits.size() == 3 && emptyComplete == false))
    117117  {
    118118    classID = ClassList::StringToID(inputSplits.getString(0) .c_str()); // FIXME
  • trunk/src/lib/util/substring.cc

    r7221 r7319  
    2626*/
    2727
    28 
    29 /**
    30  *  breaks a string into parts that were initially seperated by comma
    31  * @param string the string to break into substrings
    32 */
    33 
    3428#include "substring.h"
    3529
     
    3731#include <cassert>
    3832
     33/**
     34 * @brief create a SubString from
     35 * @param string the String to Spilit
     36 * @param splitter the Character at which to split string (delimiter)
     37 */
    3938SubString::SubString(const std::string& string, char splitter)
    4039{
     
    4746
    4847/**
    49  * Splits a String into a Substring removing all whiteSpaces
     48 * @brief Splits a String into a SubString removing all whiteSpaces
    5049 * @param string the String to Split
    51  * @param whiteSpaces MUST BE __TRUE__
    52  *
     50 * @param whiteSpaces MUST BE __TRUE__ or __FALSE__ (will be ignored)
    5351 */
    5452SubString::SubString(const std::string& string, bool whiteSpaces)
    5553{
    5654  SubString::splitLine(this->strings, this->offsets,
    57                       string);
    58 }
     55                       string);
     56}
     57
     58/**
     59 * @brief Splits a String into multiple splitters.
     60 * @param string the String to split
     61 * @param splitters multiple set of characters at what to split. (delimiters)
     62 * @param escapeChar The Escape Character that overrides splitters commends and so on...
     63 * @param safemode_char within these characters splitting won't happen
     64 * @param comment_char the Comment character.
     65 */
    5966SubString::SubString(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char)
    6067{
    6168  SubString::splitLine(this->strings, this->offsets,
    62                        string, splitters, escapeChar, safemode_char);
    63 }
    64 
    65 /**
    66  * An empty String
     69                       string, splitters, escapeChar, safemode_char, comment_char);
     70}
     71
     72/**
     73 * @brief creates a SubSet of a SubString.
     74 * @param subString the SubString to take a set from.
     75 * @param subSetBegin the beginning to the end
     76 */
     77SubString::SubString(const SubString& subString, unsigned int subSetBegin)
     78{
     79  for (unsigned int i = subSetBegin; i < subString.size(); i++)
     80    this->strings.push_back(subString[i]);
     81}
     82
     83
     84/**
     85 * @brief creates a SubSet of a SubString.
     86 * @param subString the SubString to take a Set from
     87 * @param subSetBegin the beginning to the end
     88 * @param subSetEnd the end of the SubSet (max subString.size() will be checked internaly)
     89 */
     90SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd)
     91{
     92  for (unsigned int i = subSetBegin; i < subString.size() || i < subSetEnd; i++)
     93    this->strings.push_back(subString[i]);
     94}
     95
     96
     97/**
     98 * @brief removes the object from memory
     99 */
     100SubString::~SubString()
     101{ }
     102
     103/**
     104 * @brief An empty String
    67105 */
    68106const std::string SubString::emptyString = "";
    69107
    70 
    71 
     108/**
     109 * @brief stores the Value of subString in this SubString
     110 * @param subString will be copied into this String.
     111 * @returns this SubString.
     112 */
     113SubString& SubString::operator=(const SubString& subString)
     114{
     115  this->offsets = subString.offsets;
     116  this->strings = subString.strings;
     117  return *this;
     118}
     119
     120
     121/**
     122 * @brief comparator.
     123 * @param subString the SubString to compare against this one.
     124 * @returns true if the Stored Strings match
     125 */
     126bool SubString::operator==(const SubString& subString)
     127{
     128  return (this->strings == subString.strings);
     129}
     130
     131
     132/**
     133 * @brief append operator
     134 * @param subString the String to append.
     135 * @returns a SubString where this and subString are appended.
     136 */
     137SubString SubString::operator+(const SubString& subString) const
     138{
     139  return SubString(subString) += subString;
     140}
     141
     142
     143/**
     144 * @brief append operator.
     145 * @param subString append subString to this SubString.
     146 * @returns this substring appended with subString
     147 */
     148SubString& SubString::operator+=(const SubString& subString)
     149{
     150  for (unsigned int i = 0; i < subString.size(); i++)
     151    this->strings.push_back(subString[i]);
     152}
     153
     154
     155/**
     156 * @brief Split the String at
     157 * @param string where to split
     158 * @param splitter delimiter.
     159 */
    72160unsigned int SubString::split(const std::string& string, char splitter)
    73161{
     
    83171
    84172/**
    85  * Splits a String into a Substring removing all whiteSpaces
     173 * @brief Splits a String into a Substring removing all whiteSpaces
    86174 * @param string the String to Split
    87175 * @param whiteSpaces MUST BE __TRUE__
     
    96184}
    97185
     186
     187/**
     188 * @brief Splits a String into multiple splitters.
     189 * @param string the String to split
     190 * @param splitters multiple set of characters at what to split. (delimiters)
     191 * @param escapeChar The Escape Character that overrides splitters commends and so on...
     192 * @param safemode_char within these characters splitting won't happen
     193 * @param comment_char the Comment character.
     194 */
    98195unsigned int SubString::split(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char)
    99196{
     
    103200                       string, splitters, escapeChar, safemode_char);
    104201  return strings.size();
     202}
     203
     204
     205/**
     206 * @brief joins together all Strings of this Substring.
     207 * @param delimiter the String between the subStrings.
     208 * @returns the joined String.
     209 */
     210std::string SubString::join(const std::string& delimiter) const
     211{
     212  if (!this->strings.empty())
     213  {
     214    std::string retVal = this->strings[0];
     215    for (unsigned int i = 0; i < this->strings.size(); i++)
     216      retVal += delimiter + this->strings[i];
     217    return retVal;
     218  }
     219  else
     220    return SubString::emptyString;
     221}
     222
     223
     224/**
     225 * @brief creates a SubSet of a SubString.
     226 * @param subSetBegin the beginning to the end
     227 * @returns the SubSet
     228 *
     229 * This function is added for your convenience, and does the same as
     230 * SubString::SubString(const SubString& subString, unsigned int subSetBegin)
     231 */
     232SubString SubString::getSubSet(unsigned int subSetBegin) const
     233{
     234  return SubString(*this, subSetBegin);
     235}
     236
     237
     238/**
     239 * @brief creates a SubSet of a SubString.
     240 * @param subSetBegin the beginning to
     241 * @param subSetEnd the end of the SubSet to select (if bigger than subString.size() it will be downset.)
     242 * @returns the SubSet
     243 *
     244 * This function is added for your convenience, and does the same as
     245 * SubString::SubString(const SubString& subString, unsigned int subSetBegin)
     246 */
     247SubString SubString::getSubSet(unsigned int subSetBegin, unsigned int subSetEnd) const
     248{
     249  return SubString(*this, subSetBegin, subSetEnd);
     250}
     251
     252
     253/**
     254 * @brief get a particular substring's offset
     255 * @param i the ID of the substring to get the offset from
     256 * @returns the offset or NULL if an invalid ID was given
     257 */
     258unsigned int SubString::getOffset(unsigned int i) const
     259{
     260  if( i < this->offsets.size() && i >= 0)
     261    return this->offsets[i];
     262  else
     263    return 0;
    105264}
    106265
     
    119278 * @returns SPLIT_LINE_STATE the parser was in when returning
    120279 *
     280 * This is the Actual Splitting Algorithm from Clemens Wacha
    121281 * Supports delimiters, escape characters,
    122282 * ignores special  characters between safemode_char and between comment_char and linend '\n'.
     
    142302    switch(state)
    143303    {
    144     case SL_NORMAL:
    145       if(line[i] == escape_char)
    146       {
    147         state = SL_ESCAPE;
    148       }
    149       else if(line[i] == safemode_char)
    150       {
     304      case SL_NORMAL:
     305        if(line[i] == escape_char)
     306        {
     307          state = SL_ESCAPE;
     308        }
     309        else if(line[i] == safemode_char)
     310        {
     311          state = SL_SAFEMODE;
     312        }
     313        else if(line[i] == comment_char)
     314        {
     315          /// FINISH
     316          if(token.size() > 0)
     317          {
     318            ret.push_back(token);
     319            offsets.push_back(i);
     320            token.clear();
     321          }
     322          token += line[i];       // EAT
     323          state = SL_COMMENT;
     324        }
     325        else if(delimiters.find(line[i]) != std::string::npos)
     326        {
     327          // line[i] is a delimiter
     328          /// FINISH
     329          if(token.size() > 0)
     330          {
     331            ret.push_back(token);
     332            offsets.push_back(i);
     333            token.clear();
     334          }
     335        }
     336        else
     337        {
     338          token += line[i];       // EAT
     339        }
     340        break;
     341      case SL_ESCAPE:
     342        if(line[i] == 'n') token += '\n';
     343        else if(line[i] == 't') token += '\t';
     344        else if(line[i] == 'v') token += '\v';
     345        else if(line[i] == 'b') token += '\b';
     346        else if(line[i] == 'r') token += '\r';
     347        else if(line[i] == 'f') token += '\f';
     348        else if(line[i] == 'a') token += '\a';
     349        else if(line[i] == '?') token += '\?';
     350        else token += line[i];  // EAT
     351        state = SL_NORMAL;
     352        break;
     353      case SL_SAFEMODE:
     354        if(line[i] == safemode_char)
     355        {
     356          state = SL_NORMAL;
     357        }
     358        else if(line[i] == escape_char)
     359        {
     360          state = SL_SAFEESCAPE;
     361        }
     362        else
     363        {
     364          token += line[i];       // EAT
     365        }
     366        break;
     367      case SL_SAFEESCAPE:
     368        if(line[i] == 'n') token += '\n';
     369        else if(line[i] == 't') token += '\t';
     370        else if(line[i] == 'v') token += '\v';
     371        else if(line[i] == 'b') token += '\b';
     372        else if(line[i] == 'r') token += '\r';
     373        else if(line[i] == 'f') token += '\f';
     374        else if(line[i] == 'a') token += '\a';
     375        else if(line[i] == '?') token += '\?';
     376        else token += line[i];  // EAT
    151377        state = SL_SAFEMODE;
    152       }
    153       else if(line[i] == comment_char)
    154       {
    155         /// FINISH
    156         if(token.size() > 0)
    157         {
    158           ret.push_back(token);
    159           offsets.push_back(i);
    160           token.clear();
    161         }
    162         token += line[i];       // EAT
    163         state = SL_COMMENT;
    164       }
    165       else if(delimiters.find(line[i]) != std::string::npos)
    166       {
    167         // line[i] is a delimiter
    168         /// FINISH
    169         if(token.size() > 0)
    170         {
    171           ret.push_back(token);
    172           offsets.push_back(i);
    173           token.clear();
    174         }
    175       }
    176       else
    177       {
    178         token += line[i];       // EAT
    179       }
    180       break;
    181     case SL_ESCAPE:
    182       if(line[i] == 'n') token += '\n';
    183       else if(line[i] == 't') token += '\t';
    184       else if(line[i] == 'v') token += '\v';
    185       else if(line[i] == 'b') token += '\b';
    186       else if(line[i] == 'r') token += '\r';
    187       else if(line[i] == 'f') token += '\f';
    188       else if(line[i] == 'a') token += '\a';
    189       else if(line[i] == '?') token += '\?';
    190       else token += line[i];  // EAT
    191       state = SL_NORMAL;
    192       break;
    193     case SL_SAFEMODE:
    194       if(line[i] == safemode_char)
    195       {
    196         state = SL_NORMAL;
    197       }
    198       else if(line[i] == escape_char)
    199       {
    200         state = SL_SAFEESCAPE;
    201       }
    202       else
    203       {
    204         token += line[i];       // EAT
    205       }
    206       break;
    207     case SL_SAFEESCAPE:
    208       if(line[i] == 'n') token += '\n';
    209       else if(line[i] == 't') token += '\t';
    210       else if(line[i] == 'v') token += '\v';
    211       else if(line[i] == 'b') token += '\b';
    212       else if(line[i] == 'r') token += '\r';
    213       else if(line[i] == 'f') token += '\f';
    214       else if(line[i] == 'a') token += '\a';
    215       else if(line[i] == '?') token += '\?';
    216       else token += line[i];  // EAT
    217       state = SL_SAFEMODE;
    218       break;
    219     case SL_COMMENT:
    220       if(line[i] == '\n')
    221       {
    222         /// FINISH
    223         if(token.size() > 0)
    224         {
    225           ret.push_back(token);
    226           offsets.push_back(i);
    227           token.clear();
    228         }
    229         state = SL_NORMAL;
    230       }
    231       else
    232       {
    233         token += line[i];       // EAT
    234       }
    235       break;
    236     default:
    237       // nothing
    238       break;
     378        break;
     379      case SL_COMMENT:
     380        if(line[i] == '\n')
     381        {
     382          /// FINISH
     383          if(token.size() > 0)
     384          {
     385            ret.push_back(token);
     386            offsets.push_back(i);
     387            token.clear();
     388          }
     389          state = SL_NORMAL;
     390        }
     391        else
     392        {
     393          token += line[i];       // EAT
     394        }
     395        break;
     396      default:
     397        // nothing
     398        break;
    239399    }
    240400    i++;
     
    251411}
    252412
    253 /**
    254  *  removes the object from memory
    255 */
    256 SubString::~SubString()
    257 { }
    258 
    259 /**
    260  * get a particular substring's offset
    261  * @param i the ID of the substring to get the offset from
    262  * @returns the offset or NULL if an invalid ID was given
    263  */
    264 unsigned int SubString::getOffset(unsigned int i)
    265 {
    266   if( i < this->offsets.size() && i >= 0)
    267     return this->offsets[i];
    268   else
    269     return 0;
    270 }
    271 
    272 /**
    273  * Some nice debug information about this SubString
     413
     414/**
     415 * @brief Some nice debug information about this SubString
    274416 */
    275417void SubString::debug() const
  • trunk/src/lib/util/substring.h

    r7300 r7319  
    1010#include <string>
    1111
    12   typedef enum {
    13     SL_NORMAL,
    14     SL_ESCAPE,
    15     SL_SAFEMODE,
    16     SL_SAFEESCAPE,
    17     SL_COMMENT,
    18   } SPLIT_LINE_STATE;
     12typedef enum {
     13  SL_NORMAL,
     14  SL_ESCAPE,
     15  SL_SAFEMODE,
     16  SL_SAFEESCAPE,
     17  SL_COMMENT,
     18} SPLIT_LINE_STATE;
    1919
    2020//! A class that can load one string and split it in multipe ones
     21/**
     22 * SubString is a very Powerfull way to create a SubSet from a String
     23 * It can be used, to Split strings append them and join them again.
     24 */
    2125class SubString
    2226{
    23  public:
     27public:
    2428  SubString(const std::string& string = "", char splitter = ',');
    2529  SubString(const std::string& string, bool whiteSpaces);
    2630  SubString(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0');
     31  /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */
     32  SubString(const SubString& subString) { *this = subString; };
     33  SubString(const SubString& subString, unsigned int subSetBegin);
     34  SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd);
    2735  ~SubString();
    2836
     37  // operate on the SubString
     38  SubString& operator=(const SubString& subString);
     39  bool operator==(const SubString& subString);
     40  SubString operator+(const SubString& subString) const;
     41  SubString& operator+=(const SubString& subString);
     42  /** @param subString the String to append @returns appended String. @brief added for convenience */
     43  SubString& append(const SubString subString) { return (*this += subString); };
     44
     45  /////////////////////////////////////////
     46  // Split and Join the any String. ///////
    2947  unsigned int split(const std::string& string = "", char splitter = ',');
    3048  unsigned int split(const std::string& string, bool whiteSpaces);
    3149  unsigned int split(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0');
     50  std::string join(const std::string& delimiter) const;
     51  ////////////////////////////////////////
    3252
    33   inline unsigned int getCount() { return this->strings.size(); };
    34   const std::string& getString(unsigned int i) { return (i < this->strings.size()) ? this->strings[i] : emptyString; }; // safety-precaution
    35   const std::string& operator[](unsigned int i) { return this->getString(i); };
    36   unsigned int getOffset(unsigned int i);
     53  // retrieve a SubSet from the String
     54  SubString getSubSet(unsigned int subSetBegin) const;
     55  SubString getSubSet(unsigned int subSetBegin, unsigned int subSetEnd) const;
    3756
     57  // retrieve Information from within
     58  inline unsigned int size() const { return this->strings.size(); };
     59const std::string& getString(unsigned int i) const { return (i < this->strings.size()) ? this->strings[i] : emptyString; }
     60  ; // safety-precaution
     61  const std::string& operator[](unsigned int i) const { return this->getString(i); };
     62  unsigned int getOffset(unsigned int i) const;
     63
     64  // the almighty algorithm.
    3865  static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,std::vector<unsigned int>& offsets,
    3966                                    const std::string& line, const std::string& delimiters = " \t\r\n",
    4067                                    char escape_char = '\\', char safemode_char = '"', char comment_char = '\0',
    4168                                    SPLIT_LINE_STATE start_state = SL_NORMAL);
    42 
     69  // debugging.
    4370  void debug() const;
    4471
    45  private:
    46    std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
    47    std::vector<unsigned int> offsets;                      //!< offsets of the beginning of the input-string to the beginning of each substring.
     72private:
     73  std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
     74  std::vector<unsigned int> offsets;                      //!< offsets of the beginning of the input-string to the beginning of each substring.
    4875
    49    static const std::string emptyString;
     76  static const std::string emptyString;
    5077};
    5178
Note: See TracChangeset for help on using the changeset viewer.