@@ -410,28 +410,22 @@ public func matchesText(key: String, text: String) -> QueryConstraint {
410
410
- warning: This may be slow for large datasets.
411
411
- parameter key: The key that the string to match is stored in.
412
412
- parameter regex: The regular expression pattern to match.
413
- - returns: The same instance of `Query` as the receiver.
414
- */
415
- public func matchesRegex( key: String , regex: String ) -> QueryConstraint {
416
- . init( key: key, value: regex, comparator: . regex)
417
- }
418
-
419
- /**
420
- Add a regular expression constraint for finding string values that match the provided regular expression.
421
- - warning: This may be slow for large datasets.
422
- - parameter key: The key that the string to match is stored in.
423
- - parameter regex: The regular expression pattern to match.
424
- - parameter modifiers: Any of the following supported PCRE modifiers:
413
+ - parameter modifiers: Any of the following supported PCRE modifiers (defaults to nil):
425
414
- `i` - Case insensitive search
426
415
- `m` - Search across multiple lines of input
427
416
- returns: The same instance of `Query` as the receiver.
428
417
*/
429
- public func matchesRegex( key: String , regex: String , modifiers: String ) -> QueryConstraint {
430
- let dictionary = [
431
- QueryConstraint . Comparator. regex. rawValue: regex,
432
- QueryConstraint . Comparator. regexOptions. rawValue: modifiers
433
- ]
434
- return . init( key: key, value: dictionary)
418
+ public func matchesRegex( key: String , regex: String , modifiers: String ? = nil ) -> QueryConstraint {
419
+
420
+ if let modifiers = modifiers {
421
+ let dictionary = [
422
+ QueryConstraint . Comparator. regex. rawValue: regex,
423
+ QueryConstraint . Comparator. regexOptions. rawValue: modifiers
424
+ ]
425
+ return . init( key: key, value: dictionary)
426
+ } else {
427
+ return . init( key: key, value: regex, comparator: . regex)
428
+ }
435
429
}
436
430
437
431
private func regexStringForString( _ inputString: String ) -> String {
@@ -444,35 +438,44 @@ private func regexStringForString(_ inputString: String) -> String {
444
438
- warning: This will be slow for large datasets.
445
439
- parameter key: The key that the string to match is stored in.
446
440
- parameter substring: The substring that the value must contain.
441
+ - parameter modifiers: Any of the following supported PCRE modifiers (defaults to nil):
442
+ - `i` - Case insensitive search
443
+ - `m` - Search across multiple lines of input
447
444
- returns: The same instance of `Query` as the receiver.
448
445
*/
449
- public func containsString( key: String , substring: String ) -> QueryConstraint {
446
+ public func containsString( key: String , substring: String , modifiers : String ? = nil ) -> QueryConstraint {
450
447
let regex = regexStringForString ( substring)
451
- return matchesRegex ( key: key, regex: regex)
448
+ return matchesRegex ( key: key, regex: regex, modifiers : modifiers )
452
449
}
453
450
454
451
/**
455
452
Add a constraint for finding string values that start with a provided prefix.
456
453
This will use smart indexing, so it will be fast for large datasets.
457
454
- parameter key: The key that the string to match is stored in.
458
455
- parameter prefix: The substring that the value must start with.
456
+ - parameter modifiers: Any of the following supported PCRE modifiers (defaults to nil):
457
+ - `i` - Case insensitive search
458
+ - `m` - Search across multiple lines of input
459
459
- returns: The same instance of `Query` as the receiver.
460
460
*/
461
- public func hasPrefix( key: String , prefix: String ) -> QueryConstraint {
461
+ public func hasPrefix( key: String , prefix: String , modifiers : String ? = nil ) -> QueryConstraint {
462
462
let regex = " ^ \( regexStringForString ( prefix) ) "
463
- return matchesRegex ( key: key, regex: regex)
463
+ return matchesRegex ( key: key, regex: regex, modifiers : modifiers )
464
464
}
465
465
466
466
/**
467
467
Add a constraint for finding string values that end with a provided suffix.
468
468
- warning: This will be slow for large datasets.
469
469
- parameter key: The key that the string to match is stored in.
470
470
- parameter suffix: The substring that the value must end with.
471
+ - parameter modifiers: Any of the following supported PCRE modifiers (defaults to nil):
472
+ - `i` - Case insensitive search
473
+ - `m` - Search across multiple lines of input
471
474
- returns: The same instance of `Query` as the receiver.
472
475
*/
473
- public func hasSuffix( key: String , suffix: String ) -> QueryConstraint {
476
+ public func hasSuffix( key: String , suffix: String , modifiers : String ? = nil ) -> QueryConstraint {
474
477
let regex = " \( regexStringForString ( suffix) ) $ "
475
- return matchesRegex ( key: key, regex: regex)
478
+ return matchesRegex ( key: key, regex: regex, modifiers : modifiers )
476
479
}
477
480
478
481
/**
0 commit comments