@@ -15,7 +15,7 @@ class VerbalExpressions
15
15
public $ suffixes = "" ;
16
16
public $ modifiers = "m " ; // default to global multi line matching
17
17
public $ replaceLimit = 1 ; // the limit of preg_replace when g modifier is not set
18
- protected $ lastAdded = false ; // holds the last added regex
18
+ protected $ lastAdded = false ; // holds the last added regex
19
19
20
20
/**
21
21
* Sanitize
@@ -80,7 +80,7 @@ public function endOfLine($enable = true)
80
80
}
81
81
82
82
/**
83
- * Add
83
+ * Then
84
84
*
85
85
* Add a string to the expression
86
86
*
@@ -90,10 +90,12 @@ public function endOfLine($enable = true)
90
90
*/
91
91
public function then ($ value )
92
92
{
93
- return $ this ->add ("(?: " . self ::sanitize ($ value ). ") " );
93
+ return $ this ->add ("(?: " . self ::sanitize ($ value ) . ") " );
94
94
}
95
95
96
96
/**
97
+ * Find
98
+ *
97
99
* alias for then()
98
100
* @param string $value The string to be looked for
99
101
* @return VerbalExpressions
@@ -106,15 +108,15 @@ public function find($value)
106
108
/**
107
109
* Maybe
108
110
*
109
- * Add a string to the expression that might appear once (or not).
111
+ * Add a string to the expression that might appear once (or not).
110
112
*
111
113
* @access public
112
114
* @param string $value The string to be looked for
113
115
* @return VerbalExpressions
114
116
*/
115
117
public function maybe ($ value )
116
118
{
117
- return $ this ->add ("(?: " . self ::sanitize ($ value ). ")? " );
119
+ return $ this ->add ("(?: " . self ::sanitize ($ value ) . ")? " );
118
120
}
119
121
120
122
/**
@@ -141,7 +143,7 @@ public function anything()
141
143
*/
142
144
public function anythingBut ($ value )
143
145
{
144
- return $ this ->add ("(?:[^ " . self ::sanitize ($ value ) ."]*) " );
146
+ return $ this ->add ("(?:[^ " . self ::sanitize ($ value ) . "]*) " );
145
147
}
146
148
147
149
/**
@@ -168,7 +170,7 @@ public function something()
168
170
*/
169
171
public function somethingBut ($ value )
170
172
{
171
- return $ this ->add ("(?:[^ " . self ::sanitize ($ value ) ."]+) " );
173
+ return $ this ->add ("(?:[^ " . self ::sanitize ($ value ) . "]+) " );
172
174
}
173
175
174
176
/**
@@ -212,7 +214,7 @@ public function lineBreak()
212
214
* Shorthand for lineBreak
213
215
*
214
216
* @access public
215
- * return VerbalExpressions
217
+ * @ return VerbalExpressions
216
218
*/
217
219
public function br ()
218
220
{
@@ -256,7 +258,7 @@ public function word()
256
258
*/
257
259
public function anyOf ($ value )
258
260
{
259
- return $ this ->add ("[ " . $ value ."] " );
261
+ return $ this ->add ("[ " . $ value . "] " );
260
262
}
261
263
262
264
/**
@@ -396,7 +398,6 @@ public function multiple($value)
396
398
case '+ ' :
397
399
case '* ' :
398
400
break ;
399
-
400
401
default :
401
402
$ value .= '+ ' ;
402
403
break ;
@@ -409,18 +410,19 @@ public function multiple($value)
409
410
* OR
410
411
*
411
412
* Wraps the current expression in an `or` with $value
413
+ * Notice: OR is a reserved keyword in PHP, so this method is prefixed with "_"
412
414
*
413
415
* @access public
414
416
* @param string $value new expression
415
417
* @return VerbalExpressions
416
418
*/
417
419
public function _or ($ value )
418
420
{
419
- if (strpos ($ this ->prefixes ,"( " )===false ) {
421
+ if (strpos ($ this ->prefixes , "( " ) === false ) {
420
422
$ this ->prefixes .= "(?: " ;
421
423
}
422
424
423
- if (strpos ($ this ->suffixes , ") " )===false ) {
425
+ if (strpos ($ this ->suffixes , ") " ) === false ) {
424
426
$ this ->suffixes .= ") " ;
425
427
}
426
428
@@ -456,7 +458,7 @@ public function __toString()
456
458
*/
457
459
public function getRegex ()
458
460
{
459
- return "/ " . $ this ->prefixes . $ this ->source . $ this ->suffixes . "/ " . $ this ->modifiers ;
461
+ return "/ " . $ this ->prefixes . $ this ->source . $ this ->suffixes . "/ " . $ this ->modifiers ;
460
462
}
461
463
462
464
/**
@@ -489,9 +491,9 @@ public function test($value)
489
491
* @param array $options
490
492
* @return VerbalExpressions
491
493
*/
492
- public function clean ($ options = array ())
494
+ public function clean (array $ options = array ())
493
495
{
494
- $ options = array_merge (array ("prefixes " => "" , "source " =>"" , "suffixes " =>"" , "modifiers " =>"gm " ,"replaceLimit " =>"1 " ), $ options );
496
+ $ options = array_merge (array ("prefixes " => "" , "source " =>"" , "suffixes " =>"" , "modifiers " =>"gm " , "replaceLimit " =>"1 " ), $ options );
495
497
$ this ->prefixes = $ options ['prefixes ' ];
496
498
$ this ->source = $ options ['source ' ];
497
499
$ this ->suffixes = $ options ['suffixes ' ];
@@ -503,36 +505,35 @@ public function clean($options = array())
503
505
504
506
/**
505
507
* Limit
506
- *
507
- * Adds char limit to the last added expression.
508
+ *
509
+ * Adds char limit to the last added expression.
508
510
* If $max is less then $min the limit will be: At least $min chars {$min,}
509
511
* If $max is 0 the limit will be: exactly $min chars {$min}
510
512
* If $max bigger then $min the limit will be: at least $min but not more then $max {$min, $max}
511
- *
513
+ *
512
514
* @access public
513
515
* @param integer $min
514
516
* @param integer $max
515
517
* @return VerbalExpressions
516
518
*/
517
- public function limit ($ min , $ max = 0 ) {
518
- if ( $ max == 0 )
519
- $ value = " { " . $ min . " } " ;
520
-
521
- else if ($ max < $ min )
522
- $ value = "{ " . $ min. ",} " ;
523
-
524
- else
525
- $ value = " { " . $ min . " , " . $ max . " } " ;
519
+ public function limit ($ min , $ max = 0 )
520
+ {
521
+ if ( $ max == 0 ) {
522
+ $ value = " { " . $ min . " } " ;
523
+ } elseif ($ max < $ min ) {
524
+ $ value = "{ " . $ min . ",} " ;
525
+ } else {
526
+ $ value = " { " . $ min . " , " . $ max . " } " ;
527
+ }
526
528
527
529
// check if the expression has * or + for the last expression
528
- if (preg_match ("/\*|\+/ " , $ this ->lastAdded )) {
530
+ if (preg_match ("/\*|\+/ " , $ this ->lastAdded )) {
529
531
$ l = 1 ;
530
532
$ this ->source = strrev (str_replace (array ('+ ' ,'* ' ), strrev ($ value ), strrev ($ this ->source ), $ l ));
533
+
531
534
return $ this ;
532
535
}
533
536
534
537
return $ this ->add ($ value );
535
-
536
538
}
537
-
538
539
}
0 commit comments