Changeset 14342


Ignore:
Timestamp:
08/08/07 15:42:44 (14 years ago)
Author:
mdewsnip
Message:

Added text_t replace() function, by John Rowe at DL Consulting Ltd.

Location:
gsdl/trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/lib/text_t.cpp

    r12504 r14342  
    298298
    299299
     300int text_t::replace(text_t toreplace, text_t replacement)
     301{
     302  // Get the beginning and end of the current text
     303  text_t::iterator text_begin = text.begin(), text_end = text.end();
     304  int count = 0;
     305  text_t new_text, temp_text;
     306
     307  // Loop through and grab the text off the end
     308  while (text_begin < text_end)
     309  {
     310    // Find where the next toreplace is
     311    text_t::iterator next_toreplace = findword(text_begin, text_end, toreplace);
     312
     313    // Grab the string up to it
     314    temp_text = substr(text_begin, next_toreplace);
     315
     316    // Add the new string onto the end
     317    if (new_text.empty())
     318    {
     319      new_text.append(temp_text);
     320    }
     321    else
     322    {
     323      new_text.append(replacement + temp_text);
     324    }
     325
     326    // Finally, we need to move the current pointer up to the new position
     327    text_begin = next_toreplace + 1;
     328    count++;
     329  }
     330
     331  text.clear();
     332  text = new_text.text_as_usvector();
     333  return count;
     334}
     335
     336
    300337// general functions which work on text_ts
    301338
  • gsdl/trunk/lib/text_t.h

    r12504 r14342  
    168168  char *getcstr() const;
    169169
     170  int replace(text_t toreplace, text_t replacement);
    170171};
    171172
Note: See TracChangeset for help on using the changeset viewer.