Changeset 16066


Ignore:
Timestamp:
2008-06-19T13:09:56+12:00 (16 years ago)
Author:
mdewsnip
Message:

Added splitword() function and other dependent functions.

Location:
gsdl/trunk/src/lib
Files:
2 edited

Legend:

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

    r15077 r16066  
    374374}
    375375
     376text_t::const_iterator findword (text_t::const_iterator first,
     377                 text_t::const_iterator last,
     378                 const text_t& word)
     379{
     380  text_t::const_iterator word_begin = word.begin();
     381  text_t::const_iterator word_end = word.end();
     382
     383  while (first != last)
     384    {
     385      text_t::const_iterator char_match = first;
     386      text_t::const_iterator word_here = word_begin;
     387      while (word_here!=word_end)
     388    {
     389      if (*char_match != *word_here)
     390        {
     391          break;
     392        }
     393      ++char_match;
     394      ++word_here;
     395    }
     396      if (word_here==word_end)
     397    {
     398      return first;
     399    }
     400      ++first;
     401    }
     402  return last; // get to here only if there is no match
     403}
     404
    376405text_t::iterator findword (text_t::iterator first,
    377406               text_t::iterator last,
     
    427456}
    428457
     458text_t::const_iterator getdelimitstr (text_t::const_iterator first, text_t::const_iterator last,
     459                      text_t w, text_t &outstr)
     460{
     461  text_t::const_iterator here = first;
     462  here = findword (first, last, w);
     463  outstr.clear();
     464  outstr.appendrange (first, here);
     465  if (here != last) here += w.size(); // skip w
     466  return here;
     467}
     468
    429469// split a string with a character
    430470void splitchar (text_t::const_iterator first, text_t::const_iterator last,
     
    466506    {
    467507      first = getdelimitstr (first, last, c, t);
     508      outlist.push_back (t);
     509    }
     510}
     511
     512void splitword (text_t::const_iterator first, text_t::const_iterator last,
     513        text_t w, text_tlist &outlist)
     514{
     515  outlist.erase(outlist.begin(), outlist.end());
     516
     517  text_t t;
     518
     519  while (first != last)
     520    {
     521      first = getdelimitstr (first, last, w, t);
    468522      outlist.push_back (t);
    469523    }
  • gsdl/trunk/src/lib/text_t.h

    r14342 r16066  
    229229text_t::iterator findword (text_t::iterator first, text_t::iterator last,
    230230               const text_t &word);
     231text_t::const_iterator findword (text_t::const_iterator first, text_t::const_iterator last,
     232                 const text_t& word);
    231233
    232234// get a string up to the next delimiter (which is skipped)
     
    236238text_t::iterator getdelimitstr (text_t::iterator first, text_t::iterator last,
    237239                unsigned short c, text_t &outstr);
     240
     241text_t::const_iterator getdelimitstr (text_t::const_iterator first, text_t::const_iterator last,
     242                      text_t w, text_t &outstr);
    238243
    239244// split a string with a character
     
    244249void splitchar (text_t::const_iterator first, text_t::const_iterator last,
    245250        unsigned short c, text_tarray &outlist);
     251
     252void splitword (text_t::const_iterator first, text_t::const_iterator last,
     253        text_t w, text_tlist &outlist);
    246254
    247255// join a string using a character
Note: See TracChangeset for help on using the changeset viewer.