mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Implement +[NSRegularExpression escapedPatternForString:]
This commit is contained in:
parent
567e957769
commit
7862434d85
2 changed files with 17 additions and 0 deletions
|
@ -149,6 +149,9 @@ GS_EXPORT_CLASS
|
|||
inString: (NSString*)string
|
||||
offset: (NSInteger)offset
|
||||
template: (NSString*)templat;
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
|
||||
+ (NSString *)escapedPatternForString:(NSString *)string;
|
||||
#endif
|
||||
#if GS_HAS_DECLARED_PROPERTIES
|
||||
@property (readonly) NSRegularExpressionOptions options;
|
||||
@property (readonly) NSUInteger numberOfCaptureGroups;
|
||||
|
|
|
@ -1064,6 +1064,20 @@ prepareResult(NSRegularExpression *regex,
|
|||
}
|
||||
#endif
|
||||
|
||||
+ (NSString *)escapedPatternForString:(NSString *)string {
|
||||
// https://unicode-org.github.io/icu/userguide/strings/regexp.html
|
||||
// Need to escape * ? + [ ( ) { } ^ $ | \ .
|
||||
return [[NSRegularExpression
|
||||
regularExpressionWithPattern: @"([*?+\\[(){}^$|\\\\.])"
|
||||
options: 0
|
||||
error: NULL]
|
||||
stringByReplacingMatchesInString: string
|
||||
options: 0
|
||||
range: NSMakeRange(0, [string length])
|
||||
withTemplate: @"\\\\$1"
|
||||
];
|
||||
}
|
||||
|
||||
- (NSRegularExpressionOptions) options
|
||||
{
|
||||
return options;
|
||||
|
|
Loading…
Reference in a new issue