CPKeywordRecogniser Class Reference
Inherits from | NSObject |
Conforms to | CPTokenRecogniser |
Declared in | CPKeywordRecogniser.h CPKeywordRecogniser.m |
Overview
The CPKeywordRecogniser class attempts to recognise a specific keyword in a token stream.
A keyword recogniser attempts to recognise a specific word or set of symbols. Keyword recognisers can also check that the keyword is not followed by specific characters in order to stop it recognising the beginnings of words.
This recogniser produces CPKeywordTokens.
Tasks
Creating and Initialising a Keyword Recogniser
-
+ recogniserForKeyword:
Creates a Keyword Recogniser for a specific keyword.
-
+ recogniserForKeyword:invalidFollowingCharacters:
Creates a Keyword Recogniser for a specific keyword.
-
– initWithKeyword:
Initialises a Keyword Recogniser to recognise a specific keyword.
-
– initWithKeyword:invalidFollowingCharacters:
Initialises a Keyword Recogniser to recognise a specific keyword.
Configuring a Keyword Recogniser
-
keyword
The keyword that the recogniser should attempt to recognise.
property -
invalidFollowingCharacters
A set of characters that may not follow the keyword.
property
Other Methods
-
– recogniseTokenInString:currentTokenPosition:
Attempts to recognise a token at tokenPosition in tokenString.
Properties
Class Methods
recogniserForKeyword:
Creates a Keyword Recogniser for a specific keyword.
+ (id)recogniserForKeyword:(NSString *)keyword
Parameters
- keyword
The keyword to recognise.
Discussion
Creates a Keyword Recogniser for a specific keyword.
Declared In
CPKeywordRecogniser.h
recogniserForKeyword:invalidFollowingCharacters:
Creates a Keyword Recogniser for a specific keyword.
+ (id)recogniserForKeyword:(NSString *)keyword invalidFollowingCharacters:(NSCharacterSet *)invalidFollowingCharacters
Parameters
- keyword
The keyword to recognise.
- invalidFollowingCharacters
A set of characters that may not follow the keyword in the string being tokenised.
Discussion
Creates a Keyword Recogniser for a specific keyword.
Declared In
CPKeywordRecogniser.h
Instance Methods
initWithKeyword:
Initialises a Keyword Recogniser to recognise a specific keyword.
- (id)initWithKeyword:(NSString *)keyword
Parameters
- keyword
The keyword to recognise.
Discussion
Initialises a Keyword Recogniser to recognise a specific keyword.
Declared In
CPKeywordRecogniser.h
initWithKeyword:invalidFollowingCharacters:
Initialises a Keyword Recogniser to recognise a specific keyword.
- (id)initWithKeyword:(NSString *)keyword invalidFollowingCharacters:(NSCharacterSet *)invalidFollowingCharacters
Parameters
- keyword
The keyword to recognise.
- invalidFollowingCharacters
A set of characters that may not follow the keyword in the string being tokenised.
Discussion
Initialises a Keyword Recogniser to recognise a specific keyword.
Declared In
CPKeywordRecogniser.h
recogniseTokenInString:currentTokenPosition:
Attempts to recognise a token at tokenPosition in tokenString.
- (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition:(NSUInteger *)tokenPosition
Parameters
- tokenString
The string in which to recognise tokens.
- tokenPosition
The position at which to try to find the token. On output, the position after the recognised token.
Return Value
Returns the token recognised.
Discussion
Attempts to recognise a token at tokenPosition in tokenString.
If a token is successfully recognised, it should be returned, and tokenPosition advanced to after the consumed characters.
If no valid token is found nil
must be returned instead, and tokenPosition left unchanged.
Declared In
CPTokenRecogniser.h