mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Implement +[NSRegularExpression escapedPatternForString:]
This commit is contained in:
parent
567e957769
commit
7862434d85
2 changed files with 17 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue