CPQuotedRecogniser Class Reference
Inherits from | NSObject |
Conforms to | CPTokenRecogniser |
Declared in | CPQuotedRecogniser.h CPQuotedRecogniser.m |
Overview
The CPQuotedRecogniser class is used to recognise quoted literals in the input string. This can be used for quoted strings, characters, comments and many other things.
Quoted tokens are recognised via a start string and end string. You may optionally add an escape sequence string that stops the end quote being recognised at that point in the input. You may optionally provide a block used to replace escape sequences with their actual meaning. If you don’t provide an escape replcement block it is assumed that the character following the escape sequence replaces the whole sequence.
Finally, you may also provide a maximum length for the quoted sequence to recognise. If you want to recognise strings of any length, pass NSNotFound.
This recogniser produces CPQuotedTokens. The name of the produced tokens is determined by the name property.
Tasks
Creating and Initialising a Quoted Recogniser
-
+ quotedRecogniserWithStartQuote:endQuote:name:
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote.
-
+ quotedRecogniserWithStartQuote:endQuote:escapeSequence:name:
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string.
-
+ quotedRecogniserWithStartQuote:endQuote:escapeSequence:maximumLength:name:
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string. Quoted strings have a maximum length.
-
– initWithStartQuote:endQuote:escapeSequence:maximumLength:name:
Initialises a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string. Quoted strings have a maximum length.
Configuring a Quoted Recogniser
-
startQuote
Determines the string used to indicate the start of the quoted literal.
property -
endQuote
Determines the string used to indicate the end of the quoted literal.
property -
escapeSequence
Determines the string used to indicate an escaped character in the quoted literal.
property -
escapeReplacer
Determines how much of the input string to consume when an escaped literal is found, and what to replace it with.
property -
maximumLength
Determines the maximum length of the quoted literal not including quotes. To indicate the literal can be any length specify NSNotFound.
property -
name
Determines the name of the CPToken produced.
property
Other Methods
-
– recogniseTokenInString:currentTokenPosition:
Attempts to recognise a token at tokenPosition in tokenString.
Properties
endQuote
Determines the string used to indicate the end of the quoted literal.
@property (readwrite, copy) NSString *endQuote
Discussion
Determines the string used to indicate the end of the quoted literal.
See Also
Declared In
CPQuotedRecogniser.h
escapeReplacer
Determines how much of the input string to consume when an escaped literal is found, and what to replace it with.
@property (readwrite, copy) NSString *^ ) ( NSString *tokenStream , NSUInteger *quotePosition ) escapeReplacer
Discussion
Determines how much of the input string to consume when an escaped literal is found, and what to replace it with.
Declared In
CPQuotedRecogniser.h
escapeSequence
Determines the string used to indicate an escaped character in the quoted literal.
@property (readwrite, copy) NSString *escapeSequence
Discussion
Determines the string used to indicate an escaped character in the quoted literal.
Declared In
CPQuotedRecogniser.h
maximumLength
Determines the maximum length of the quoted literal not including quotes. To indicate the literal can be any length specify NSNotFound.
@property (readwrite, assign) NSUInteger maximumLength
Discussion
Determines the maximum length of the quoted literal not including quotes. To indicate the literal can be any length specify NSNotFound.
Declared In
CPQuotedRecogniser.h
name
Determines the name of the CPToken produced.
@property (readwrite, copy) NSString *name
Discussion
Determines the name of the CPToken produced.
Declared In
CPQuotedRecogniser.h
Class Methods
quotedRecogniserWithStartQuote:endQuote:escapeSequence:maximumLength:name:
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string. Quoted strings have a maximum length.
+ (id)quotedRecogniserWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote escapeSequence:(NSString *)escapeSequence maximumLength:(NSUInteger)maximumLength name:(NSString *)name
Parameters
- startQuote
A string that indicates the beginning of a quoted literal.
- endQuote
A string that indicates the end of the quoted literal.
- escapeSequence
A string that indicates an escaped character.
- maximumLength
The maximum length of the resulting string.
- name
The name to attach to recognised tokens.
Return Value
Returns a CPQuotedRecogniser that recognises C like identifiers.
Discussion
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string. Quoted strings have a maximum length.
See Also
Declared In
CPQuotedRecogniser.h
quotedRecogniserWithStartQuote:endQuote:escapeSequence:name:
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string.
+ (id)quotedRecogniserWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote escapeSequence:(NSString *)escapeSequence name:(NSString *)name
Parameters
- startQuote
A string that indicates the beginning of a quoted literal.
- endQuote
A string that indicates the end of the quoted literal.
- escapeSequence
A string that indicates an escaped character.
- name
The name to attach to recognised tokens.
Return Value
Returns a CPQuotedRecogniser that recognises C like identifiers.
Discussion
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string.
See Also
Declared In
CPQuotedRecogniser.h
quotedRecogniserWithStartQuote:endQuote:name:
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote.
+ (id)quotedRecogniserWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote name:(NSString *)name
Parameters
- startQuote
A string that indicates the beginning of a quoted literal.
- endQuote
A string that indicates the end of the quoted literal.
- name
The name to attach to recognised tokens.
Return Value
Returns a CPQuotedRecogniser that recognises C like identifiers.
Discussion
Creates a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote.
See Also
Declared In
CPQuotedRecogniser.h
Instance Methods
initWithStartQuote:endQuote:escapeSequence:maximumLength:name:
Initialises a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string. Quoted strings have a maximum length.
- (id)initWithStartQuote:(NSString *)startQuote endQuote:(NSString *)endQuote escapeSequence:(NSString *)escapeSequence maximumLength:(NSUInteger)maximumLength name:(NSString *)name
Parameters
- startQuote
A string that indicates the beginning of a quoted literal.
- endQuote
A string that indicates the end of the quoted literal.
- escapeSequence
A string that indicates an escaped character.
- maximumLength
The maximum length of the resulting string.
- name
The name to attach to recognised tokens.
Return Value
Returns a CPQuotedRecogniser that recognises C like identifiers.
Discussion
Initialises a quoted recogniser that recognises quoted litterals starting with startQuote and ending with endQuote. Escaped sequences are recognised by the escapeSequence string. Quoted strings have a maximum length.
Declared In
CPQuotedRecogniser.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