Changeset 10140


Ignore:
Timestamp:
2005-06-17T10:49:44+12:00 (19 years ago)
Author:
kjdon
Message:

added starts_with and ends_with functions

Location:
trunk/gsdl/lib
Files:
2 edited

Legend:

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

    r9593 r10140  
    2828/*
    2929   $Log$
     30   Revision 1.25  2005/06/16 22:49:44  kjdon
     31   added starts_with and ends_with functions
     32
    3033   Revision 1.24  2005/04/07 04:27:18  kjdon
    3134   added some x++ -> ++x changes submitted by Emanuel Dejanu
     
    660663}
    661664
     665// checks to see if a text_t starts with the specified prefix
     666bool starts_with(const text_t& text, const text_t& prefix) {
     667  if (prefix.empty()) return true;
     668  if (text.empty() || text.size()<prefix.size()) return false;
     669  text_t substring = substr(text.begin(), text.begin()+prefix.size());
     670  return substring == prefix;
     671}
     672// checks to see if a text_t ends with the specified suffix
     673bool ends_with(const text_t& text, const text_t& suffix) {
     674  if (suffix.empty()) return true;
     675  if (text.empty() || text.size() < suffix.size()) return false;
     676  text_t substring = substr(text.end()-suffix.size(),text.end());
     677  return substring == suffix;
     678
     679}
    662680
    663681
  • trunk/gsdl/lib/text_t.h

    r8727 r10140  
    272272bool has_unicode_letdig (const text_t &text);
    273273
     274// checks to see if a text_t starts with the specified prefix
     275bool starts_with(const text_t& text, const text_t& prefix);
     276// checks to see if a text_t ends with the specified suffix
     277bool ends_with(const text_t& text, const text_t& suffix);
    274278
    275279// conversion classes used for getting information in to and out of
Note: See TracChangeset for help on using the changeset viewer.