MBRegexCache Class Reference
| Inherits from | MBThreadsafeCache : NSObject |
|---|---|
| Conforms to | MBSingleton |
| Declared in | MBRegexCache.h |
Overview
Regular expressions can be expensive to instantiate, so we implement our
own thread-safe singleton MBRegexCache. The cache is automatically populated
as you call the methods for getting regular expressions, and it also empties
itself when memory warnings occur.
You can retrieve NSRegularExpression instances from the cache by calling
instance methods on the singleton. Or, as a convenience to avoid having
to acquire the singleton, you can also get NSRegularExpressions by calling
class-level methods as well. It is more efficient to get the singleton
instance and call instance-level methods when you expect to do many calls to
the MBRegexCache.
Warning: You must not create instances of this class yourself; this class
is a singleton. Call the instance class method (declared by the
MBSingleton protocol) to acquire the singleton instance.
Class-level methods, for convenience
+ regularExpressionWithPattern:options:error:
Returns an NSRegularExpression instance for the given regular
expression pattern and options.
+ (nullable NSRegularExpression *)regularExpressionWithPattern:(nonnull NSString *)pattern options:(NSRegularExpressionOptions)options error:(NSErrorPtrPtr)errPtrParameters
pattern |
The regular expression pattern |
|---|---|
options |
The |
errPtr |
If this method returns |
Return Value
A pointer to an NSRegularExpression instance, or
nil if the passed-in pattern could not be interpreted
as a valid regular expression.
Declared In
MBRegexCache.h
+ regularExpressionWithPattern:options:
Returns an NSRegularExpression instance for the given regular
expression pattern and options.
+ (nullable NSRegularExpression *)regularExpressionWithPattern:(nonnull NSString *)pattern options:(NSRegularExpressionOptions)optionsParameters
pattern |
The regular expression pattern |
|---|---|
options |
The |
Return Value
A pointer to an NSRegularExpression instance, or
nil if the passed-in pattern could not be interpreted
as a valid regular expression. If an error occurs causing
nil to be returned, a message will be logged to the
console.
Declared In
MBRegexCache.h
+ regularExpressionWithPattern:
Returns an NSRegularExpression instance for the given regular
expression pattern.
+ (nullable NSRegularExpression *)regularExpressionWithPattern:(nonnull NSString *)patternParameters
pattern |
The regular expression pattern |
|---|
Return Value
A pointer to an NSRegularExpression instance, or
nil if the passed-in pattern could not be interpreted
as a valid regular expression. If an error occurs causing
nil to be returned, a message will be logged to the
console.
Declared In
MBRegexCache.h
Instance-level methods, for efficiency
– regularExpressionWithPattern:options:error:
Returns an NSRegularExpression instance for the given regular
expression pattern and options.
- (nullable NSRegularExpression *)regularExpressionWithPattern:(nonnull NSString *)pattern options:(NSRegularExpressionOptions)options error:(NSErrorPtrPtr)errPtrParameters
pattern |
The regular expression pattern |
|---|---|
options |
The |
errPtr |
If this method returns |
Return Value
A pointer to an NSRegularExpression instance, or
nil if the passed-in pattern could not be interpreted
as a valid regular expression.
Declared In
MBRegexCache.h
– regularExpressionWithPattern:options:
Returns an NSRegularExpression instance for the given regular
expression pattern and options.
- (nullable NSRegularExpression *)regularExpressionWithPattern:(nonnull NSString *)pattern options:(NSRegularExpressionOptions)optionsParameters
pattern |
The regular expression pattern |
|---|---|
options |
The |
Return Value
A pointer to an NSRegularExpression instance, or
nil if the passed-in pattern could not be interpreted
as a valid regular expression. If an error occurs causing
nil to be returned, a message will be logged to the
console.
Declared In
MBRegexCache.h
– regularExpressionWithPattern:
Returns an NSRegularExpression instance for the given regular
expression pattern.
- (nullable NSRegularExpression *)regularExpressionWithPattern:(nonnull NSString *)patternParameters
pattern |
The regular expression pattern |
|---|
Return Value
A pointer to an NSRegularExpression instance, or
nil if the passed-in pattern could not be interpreted
as a valid regular expression. If an error occurs causing
nil to be returned, a message will be logged to the
console.
Declared In
MBRegexCache.h