| 1 | /* |
| 2 | ** CWRegEx.h |
| 3 | ** |
| 4 | ** Copyright (c) 2001-2004 Ludovic Marcotte, Francis Lachapelle |
| 5 | ** |
| 6 | ** Author: Francis Lachapelle <[email protected]> |
| 7 | ** Ludovic Marcotte <[email protected]> |
| 8 | ** |
| 9 | ** This library is free software; you can redistribute it and/or |
| 10 | ** modify it under the terms of the GNU Lesser General Public |
| 11 | ** License as published by the Free Software Foundation; either |
| 12 | ** version 2.1 of the License, or (at your option) any later version. |
| 13 | ** |
| 14 | ** This library is distributed in the hope that it will be useful, |
| 15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | ** Lesser General Public License for more details. |
| 18 | ** |
| 19 | ** You should have received a copy of the GNU General Public License |
| 20 | ** along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _Pantomime_H_CWRegEx |
| 24 | #define _Pantomime_H_CWRegEx |
| 25 | |
| 26 | #include <sys/types.h> |
| 27 | #include <regex.h> |
| 28 | |
| 29 | #import <Foundation/NSObject.h> |
| 30 | #import <Foundation/NSString.h> |
| 31 | |
| 32 | /*! |
| 33 | @class CWRegEx |
| 34 | @abstract Provides a simple object-oriented wrapper around POSIX regex. |
| 35 | @discussion This class provides a simple and efficient interface around |
| 36 | POSIX regex, which are available on most UNIX (or like) systems. |
| 37 | */ |
| 38 | @interface CWRegEx : NSObject |
| 39 | { |
| 40 | @private |
| 41 | regex_t _re; |
| 42 | } |
| 43 | |
| 44 | /*! |
| 45 | @method initWithPattern: |
| 46 | @discussion This method invokes initWithPattern: flags: with |
| 47 | the default REG_EXTENDED flag. |
| 48 | @param thePattern The regular expression to use. |
| 49 | @result An instance of CWRegEx, nil in case of an error. |
| 50 | */ |
| 51 | - (id) initWithPattern: (NSString *) thePattern; |
| 52 | |
| 53 | /*! |
| 54 | @method initWithPattern: flags: |
| 55 | @discussion This method is used to initialize a CWRegEx instance |
| 56 | using the specified pattern and flags. |
| 57 | @param thePattern The regular expression to use. |
| 58 | @param theFlags The flags to use. See regcomp(3) for a description |
| 59 | of the available flags. |
| 60 | @result An instance of CWRegEx, nil in case of an error. |
| 61 | */ |
| 62 | - (id) initWithPattern: (NSString *) thePattern |
| 63 | flags: (int) theFlags; |
| 64 | |
| 65 | /*! |
| 66 | @method regexWithPattern: |
| 67 | @discussion Invokes initWithPattern: with <i>thePattern</i> and |
| 68 | autoreleases the returned instance. |
| 69 | */ |
| 70 | + (id) regexWithPattern: (NSString *) thePattern; |
| 71 | |
| 72 | /*! |
| 73 | @method regexWithPattern: flags: |
| 74 | @discussion Invokes initWithPattern: flags: with <i>thePattern</i> and |
| 75 | <i>theFlags</i>, then autoreleases the returned instance. |
| 76 | */ |
| 77 | + (id) regexWithPattern: (NSString *) thePattern |
| 78 | flags: (int) theFlags; |
| 79 | |
| 80 | /*! |
| 81 | @method matchString: |
| 82 | @discussion This method is used to try to match <i>theString</i> |
| 83 | using the instance's pattern. |
| 84 | @param theString The string to match. |
| 85 | @result An array of matches (NSString instances), which can be empty but not nil. |
| 86 | */ |
| 87 | - (NSArray *) matchString: (NSString *) theString; |
| 88 | |
| 89 | /*! |
| 90 | @method matchString: withPattern: isCaseSensitive: |
| 91 | @discussion This method provides an easy way to quickly |
| 92 | match a string with the specified pattern, in a |
| 93 | case-sensitive manner or not. |
| 94 | @param theString The string to match. |
| 95 | @param thePattern The regular expression to use. |
| 96 | @param theBOOL Case-sensitive, or not. |
| 97 | @result An array of matches (NSString instances), which can be empty but not nil. |
| 98 | */ |
| 99 | + (NSArray *) matchString: (NSString *) theString |
| 100 | withPattern: (NSString *) thePattern |
| 101 | isCaseSensitive: (BOOL) theBOOL; |
| 102 | |
| 103 | @end |
| 104 | |
| 105 | #endif // _Pantomime_H_CWRegEx |