home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Headers / misckit / MiscStringPatterns.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  3.0 KB  |  83 lines

  1. //
  2. //    MiscStringPatterns.h -- Pattern matching and replacement routines
  3. //        Written by Steve Hayman Copyright (c) 1994 by Steve Hayman.
  4. //                Version 1.0  All rights reserved.
  5. //        This notice may not be removed from this source code.
  6. //
  7. //    This object is included in the MiscKit by permission from the author
  8. //    and its use is governed by the MiscKit license, found in the file
  9. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  10. //    for a list of all applicable permissions and restrictions.
  11. //    
  12.  
  13. //#import <misckit/MiscString.h>
  14.  
  15. // Note from Don:  these are here "temporarily" until we can get the regexpr.c
  16. // routines wrapped up by a few methods.  That's being done by Carl Lindberg
  17. // as he gets the time to do it.
  18.  
  19. @interface MiscString(PatternMatching)
  20.  
  21. /*
  22.  * Pattern matching and replacement routines
  23.  * These methods match MiscStrings against regular expressions, and
  24.  * perform substitutions.
  25.  * Steve Hayman
  26.  * shayman@Objectario.com
  27.  */
  28.  
  29. /*
  30.  * See if the receiver matches a regular expression.
  31.  * Returns 1 if it matches, 0 if not, -1 if an invalid regular expression.
  32.  * caseSens says whether or not to do case-sensitive matching.
  33.  */
  34. #ifdef DONT_COMPILE    // obsoleted by Regex category
  35. - (int) grep:(const char *)pattern;
  36. #endif
  37. #ifdef DONT_COMPILE    // obsoleted by Regex category
  38. - (int) grep:(const char *)pattern caseSensitive:(BOOL)caseSens;
  39. #endif
  40.  
  41. /*
  42.  * Match a regular expression as above, and optionally split it
  43.  * into three substrings - the part before the match, the part
  44.  * that actually matched the pattern, and the part after the match.
  45.  * bstring, mstring and astring should be other allocated MiscString objects
  46.  * which will be filled in by this method.
  47.  */
  48. #ifdef DONT_COMPILE    // obsoleted by Regex category
  49. - (int) grep:(const char *)pattern caseSensitive:(BOOL)caseSens
  50.         before:bstring middle:mstring after:astring;
  51. #endif
  52.  
  53. /*
  54.  * The same pattern matching methods as above, only with MiscString
  55.  * patterns rather than (const char *) patterns.
  56.  */
  57.  
  58. - (int) grepString:pattern caseSensitive:(BOOL)caseSens before:bstring
  59.         middle:mstring after:astring;
  60. - (int) grepString:pattern;
  61. - (int) grepString:pattern caseSensitive:(BOOL)caseSens;
  62.  
  63. /*
  64.  * Search-and-replace, with patterns.
  65.  * Searches for occurrences of the regexp "pattern" in the destination string,
  66.  * replaces it with "replacement".
  67.  * If glob is YES, replace all pattern occurrences; if NO, only the first.
  68.  * Returns the number of replacements that were made.
  69.  * Returns -1 if an ill-formed pattern was supplied
  70.  *
  71.  */
  72. - (int)replacePattern:(const char *)pattern caseSensitive:(BOOL)caseSens
  73.         globally:(BOOL)glob with:(const char *)replacement;
  74. - (int)replacePattern:(const char *)pattern caseSensitive:(BOOL)caseSens
  75.         globally:(BOOL)glob withString:replacement;
  76.  
  77. - (int)replacePatternString:pattern caseSensitive:(BOOL)caseSens
  78.         globally:(BOOL)glob with:(const char *)replacement;
  79. - (int)replacePatternString:pattern caseSensitive:(BOOL)caseSens
  80.         globally:(BOOL)glob withString:replacement;
  81.  
  82. @end
  83.