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

Added splitword() function and other dependent functions.

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.