Changeset 10

Show
Ignore:
Timestamp:
12/11/06 1:03:49 PM (2 years ago)
Author:
aaron
Message:

added documentation
made code style more consistent

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CocoaICU.xcodeproj/project.pbxproj

    r7 r10  
    2222                939322570B1E6AD000DD0AF0 /* ICUMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ICUMatcher.h; path = source/ICUMatcher.h; sourceTree = "<group>"; }; 
    2323                939322580B1E6AD000DD0AF0 /* ICUMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ICUMatcher.m; path = source/ICUMatcher.m; sourceTree = "<group>"; }; 
    24                 93E2BFE60B18BEC4001193AC /* CocoaICU Unit Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "CocoaICU Unit Tests-Info.plist"; path = "resources/CocoaICU Unit Tests-Info.plist"; sourceTree = SOURCE_ROOT; }; 
    2524                93E2C0CE0B18D142001193AC /* CocoaICU.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CocoaICU.m; path = source/CocoaICU.m; sourceTree = "<group>"; }; 
    2625                93E2C0CF0B18D142001193AC /* ICUPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ICUPattern.h; path = source/ICUPattern.h; sourceTree = "<group>"; }; 
     
    5150                                08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */, 
    5251                                1AB674ADFE9D54B511CA2CBB /* Products */, 
    53                                 93E2BFE60B18BEC4001193AC /* CocoaICU Unit Tests-Info.plist */, 
    5452                        ); 
    5553                        name = CocoaICU; 
  • trunk/source/ICUMatcher.h

    r6 r10  
    1010@class ICUPattern; 
    1111 
     12/*! 
     13    @class               ICUMatcher 
     14    @abstract    ICUMatcher provides matching functionality for regular expression matching. 
     15    @discussion  This class is based off of the <a href="http://icu.sourceforge.net/apiref/icu4c/classRegexMatcher.html">C++ ICU RegexMatcher class</a>.  For examples of how to use the matcher, see the NSString category included in this project. 
     16*/ 
    1217@interface ICUMatcher : NSObject { 
    1318        ICUPattern *pattern; 
    1419} 
    1520 
     21/*! 
     22    @method     matcherWithPattern:overString: 
     23    @abstract   Returns a matcher that can match the given pattern over the given string. 
     24    @discussion  
     25*/ 
    1626+(ICUMatcher *)matcherWithPattern:(ICUPattern *)p overString:(NSString *)stringToSearchOver; 
     27 
     28/*! 
     29    @method     initWithPattern:overString: 
     30    @abstract   Initializes a matcher that can match the given patter over the given string. 
     31    @discussion  
     32*/ 
    1733-(ICUMatcher *)initWithPattern:(ICUPattern *)p overString:(NSString *)stringToSearchOver; 
    1834 
     35/*! 
     36    @method     findNext 
     37    @abstract   Finds the next occurrence of the pattern in the input string. 
     38    @discussion Use <code>group</code> and <code>rangeOfMatch</code> to extract the match. 
     39*/ 
    1940-(BOOL)findNext; 
     41 
     42/*! 
     43    @method     findFromIndex: 
     44    @abstract   Resets the pattern and performs a match from the specified index. 
     45    @discussion Use <code>group</code> and <code>rangeOfMatch</code> to extract the match. 
     46*/ 
    2047-(BOOL)findFromIndex:(unsigned)index; 
     48 
     49/*! 
     50    @method     group 
     51    @abstract   Returns the current match. 
     52    @discussion Each match has one or more subexpressions associated with the match.  This returns the entire match. 
     53*/ 
    2154-(NSString *)group; 
     55 
     56/*! 
     57    @method     groupAtIndex: 
     58    @abstract   Returns the given subexpression for the current match. 
     59    @discussion <code>group</code> is equivalent to <code>groupAtIndex:0</code>.  The subexpressions for a match are indexed from 1. 
     60*/ 
    2261-(NSString *)groupAtIndex:(unsigned)groupIndex; 
     62 
     63/*! 
     64    @method     numberOfGroups 
     65    @abstract   Returns the number of groups for the current match. 
     66    @discussion Group 0 is the entire match and groups 1..n represent the groups for the subexpressions. 
     67*/ 
    2368-(unsigned)numberOfGroups; 
     69 
     70/*! 
     71    @method     lookingAt: 
     72    @abstract   Returns true if the pattern matches some prefix of the input string starting at the specified index. 
     73    @discussion This method returns YES when some prefix of the substring matches the input string. 
     74*/ 
    2475-(BOOL)lookingAt:(unsigned)index; 
     76 
     77/*! 
     78    @method     pattern 
     79    @abstract   Returns the pattern for this matcher. 
     80    @discussion  
     81*/ 
    2582-(ICUPattern *)pattern; 
     83-(void)setPattern:(ICUPattern *)p; 
     84 
     85/*! 
     86    @method     matches 
     87    @abstract   Returns YES if the patterns matches the <b>entire</b> input string. 
     88    @discussion  
     89*/ 
    2690-(BOOL)matches; 
    27 -(void)setPattern:(ICUPattern *)p; 
     91 
     92/*! 
     93    @method     replaceAllWithString: 
     94    @abstract   Replaces all occurrences of the pattern with the replacement string and returns the resulting string. 
     95    @discussion The replacement string can contain references to capture groups taking the form or $1, $2, etc. 
     96*/ 
    2897-(NSString *)replaceAllWithString:(NSString *)aReplacementString; 
     98 
     99/*! 
     100    @method     replaceFirstWithString: 
     101    @abstract   Replaces the first occurrence of the pattern with the given replacement string and returns the resulting string. 
     102    @discussion The replacement string can contain references to capture groups taking the form or $1, $2, etc. 
     103*/ 
    29104-(NSString *)replaceFirstWithString:(NSString *)aReplacementString; 
     105 
     106/*! 
     107    @method     reset 
     108    @abstract   Resets any state associated with the matcher and its pattern. 
     109    @discussion  
     110*/ 
    30111-(void)reset; 
     112 
     113/*! 
     114    @method     rangeOfMatch 
     115    @abstract   Returns the range of the input string that corresponds to the current match. 
     116    @discussion 
     117*/ 
    31118-(NSRange)rangeOfMatch; 
     119 
     120/*! 
     121    @method     rangeOfMatchGroup: 
     122    @abstract   Returns the range of the input string that corresponds to the specified capture group of the current match. 
     123    @discussion 
     124*/ 
    32125-(NSRange)rangeOfMatchGroup:(unsigned)groupNumber; 
    33126 
  • trunk/source/ICUMatcher.m

    r6 r10  
    4040} 
    4141 
    42 -(ICUMatcher *)initWithPattern:(ICUPattern *)p overString:(NSString *)aStringToSearch; 
    43 
     42-(ICUMatcher *)initWithPattern:(ICUPattern *)p overString:(NSString *)aStringToSearch; { 
    4443        if(![super init]) 
    4544                return nil; 
     
    5150} 
    5251 
    53 -(void)dealloc 
    54 
     52-(void)dealloc { 
    5553        [[self pattern] release]; 
    5654 
     
    9088} 
    9189 
    92 -(BOOL)findFromIndex:(unsigned)index 
    93 
     90-(BOOL)findFromIndex:(unsigned)index { 
    9491        URegularExpression *re = [[self pattern] re]; 
    9592        [self reset]; 
     
    10299} 
    103100 
    104 -(NSString *)group 
    105 
     101-(NSString *)group { 
    106102        NSString *stringToMatch = [[self pattern] stringToSearch]; 
    107103        return [stringToMatch substringWithRange:[self rangeOfMatch]]; 
    108104} 
    109105 
    110 -(NSString *)groupAtIndex:(unsigned)groupIndex 
    111 
     106-(NSString *)groupAtIndex:(unsigned)groupIndex { 
    112107        size_t groupSize = InitialGroupSize; 
    113108        URegularExpression *re = [[self pattern] re]; 
     
    133128} 
    134129 
    135 -(unsigned)numberOfGroups 
    136 
     130-(unsigned)numberOfGroups { 
    137131        URegularExpression *re = [[self pattern] re]; 
    138132        UErrorCode status = 0; 
     
    207201} 
    208202 
    209 -(NSRange)rangeOfMatch 
    210 
     203-(NSRange)rangeOfMatch { 
    211204        return [self rangeOfMatchGroup:0]; 
    212205} 
    213206 
    214 -(NSRange)rangeOfMatchGroup:(unsigned)groupNumber 
    215 
     207-(NSRange)rangeOfMatchGroup:(unsigned)groupNumber { 
    216208        UErrorCode status = 0; 
    217209        URegularExpression *re = [[self pattern] re]; 
  • trunk/source/ICUPattern.h

    r5 r10  
    2020extern unsigned UnicodeWordBoundaries; 
    2121 
     22/*! 
     23    @class               ICUPattern 
     24    @abstract    A compiled regular expression. 
     25    @discussion  <a href="http://icu.sourceforge.net/">ICU</a> provides a widely used Unicode 
     26 regular expression library.  This class can be roughly mapped to the <a href="http://icu.sourceforge.net/apiref/icu4c/classRegexPattern.html">ICU C++ Pattern class</a>.  Notes about ICU regular expressions can be found at the  
     27 <a href="http://icu.sourceforge.net/userguide/regexp.html">ICU User Guide</a>. 
     28*/ 
    2229@interface ICUPattern: NSObject <NSCopying> { 
    2330        void *re; 
    2431        void *textToSearch; 
    2532        unsigned flags; 
     33        NSString *stringToSearch; 
    2634} 
    2735 
    28 // XOR flags (defaults to 0 when no flags are given) 
     36/*! 
     37    @method     patternWithString:flags: 
     38    @abstract   Returns an autoreleased pattern with the specified flags set. 
     39    @discussion Flags are defined as the OR of the constants defined in the class. 
     40*/ 
    2941+(ICUPattern *)patternWithString:(NSString *)aPattern flags:(unsigned)flags; 
     42 
     43/*! 
     44        @method     patternWithString: 
     45        @abstract   Returns an autoreleased pattern with the default flags. 
     46        @discussion Flags are given by 0. 
     47*/ 
    3048+(ICUPattern *)patternWithString:(NSString *)aPattern; 
    31 -(id)initWithString:(NSString *)aPattern; 
     49 
     50/*! 
     51        @method     initWithString:flags: 
     52        @abstract   Returns a pattern with the specified flags set. 
     53        @discussion Flags are defined as the OR of the constants defined in the class. 
     54*/ 
    3255-(id)initWithString:(NSString *)aPattern flags:(unsigned)flags; 
    3356 
     57/*! 
     58    @method     initWithString: 
     59        @abstract   Returns a pattern with the specified flags set. 
     60        @discussion Flags are defined as 0. 
     61*/ 
     62-(id)initWithString:(NSString *)aPattern; 
     63 
     64/*! 
     65    @method             componentsSplitFromString: 
     66    @abstract   Splits the input string into fields delineated by the expression given by the pattern. 
     67    @discussion Returns an empty array if the pattern is not found. 
     68*/ 
    3469-(NSArray *)componentsSplitFromString:(NSString *)stringToSplit; 
     70 
     71/*! 
     72    @method     matchesString: 
     73    @abstract   Returns YES if the pattern matches the entire input string. 
     74    @discussion Returns YES if the pattern matches the entire input string. 
     75*/ 
    3576-(BOOL)matchesString:(NSString *)stringToMatchAgainst; 
     77 
     78/*! 
     79    @method     pattern 
     80    @abstract   Returns the string representing the regular expression of this pattern. 
     81    @discussion Returns the string representing the regular expression of this pattern. 
     82*/ 
    3683-(NSString *)pattern; 
     84 
     85/*! 
     86    @method     setStringToSearch: 
     87    @abstract   Sets the string that is being searched by this pattern. 
     88    @discussion This method also resets any internal state of the pattern. 
     89*/ 
    3790-(void)setStringToSearch:(NSString *)aStringToSearchOver; 
     91 
     92/*! 
     93    @method     stringToSearch 
     94    @abstract   Returns the string that is being searched over with the pattern. 
     95    @discussion This method creates an NSString from the underlying UTF16 character array used by ICU.  For large 
     96 strings, this may be memory-intensive/time-consuming.  Performance-critical applications may want to modify this  
     97 class to suite their needs to reduce the number of NSString objects that are created. 
     98*/ 
    3899-(NSString *)stringToSearch; 
     100 
     101/*! 
     102    @method     reset 
     103    @abstract   Resets the pattern. 
     104    @discussion Patterns maintain state about the current match and this method resets that state. 
     105*/ 
    39106-(void)reset; 
    40107 
     108/*! 
     109    @method     re 
     110    @abstract   Returns the compiled ICU URegularExpression for this pattern. 
     111    @discussion This method primarily exists to allow the ICUMatcher to access the pattern. 
     112*/ 
    41113-(void *)re; 
     114 
    42115@end 
  • trunk/source/ICUPattern.m

    r6 r10  
    8585                free(re); 
    8686 
     87        [stringToSearch release]; 
    8788        [super dealloc]; 
    8889} 
    8990 
    90 -(NSString *)stringToSearch 
    91 
     91-(NSString *)stringToSearch { 
    9292        return [NSString stringWithUTF16String:[self textToSearch]]; 
    9393} 
    9494 
    95 -(void)setStringToSearch:(NSString *)aStringToSearchOver 
    96 
     95-(void)setStringToSearch:(NSString *)aStringToSearchOver { 
     96        if(stringToSearch != nil) 
     97                [stringToSearch release]; 
     98 
     99        stringToSearch = [aStringToSearchOver retain]; 
     100 
    97101        [self setTextToSearch:[aStringToSearchOver UTF16String]]; 
    98102} 
     
    102106 
    103107        uregex_setText([self re], utf16String, -1, &status); 
    104          
    105         textToSearch = utf16String; 
     108 
     109        [self reset]; 
     110 
     111        textToSearch = utf16String; // retained by the NSString  
    106112         
    107113        if(U_FAILURE(status)) { 
     
    156162} 
    157163 
    158 -(void *)re 
    159 
     164-(void *)re { 
    160165        return re; 
    161166} 
     
    234239} 
    235240 
    236 -(BOOL)matchesString:(NSString *)stringToMatchAgainst 
    237 
     241-(BOOL)matchesString:(NSString *)stringToMatchAgainst { 
    238242        ICUMatcher *m = [ICUMatcher matcherWithPattern:self overString:stringToMatchAgainst]; 
    239243        return [m matches];