home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v16n10 / string.exe / STRISRCH.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-30  |  765 b   |  35 lines

  1. #include <string.h>
  2. #include <ctype.h>
  3. #include <errno.h>
  4. #include <string.hpp>
  5.  
  6. int String::match(const String &a) const
  7. {
  8.     if (!rp || !a.rp) return 0;
  9.     int lim, rv = -1;
  10.     if (a.length() > length())
  11.         lim = rv = length();
  12.     else
  13.         lim = a.length();
  14.     const char *p = body(), *q = a.body();
  15.     for (int i = 0; i < lim; ++i)
  16.         if (*p++ != *q++)
  17.             return i;
  18.     return rv;
  19. }
  20.  
  21. int String::match(const char *s) const
  22. {
  23.     if (!rp || !*s) return 0;
  24.     int rv = -1, lim, sl = strlen(s);
  25.     if (sl > length())
  26.         lim = rv = length();
  27.     else
  28.         lim = sl;
  29.     const char *p = body();
  30.     for (int i = 0; i < lim; ++i)
  31.         if (*p++ != *s++)
  32.             return i;
  33.     return rv;
  34. }
  35.