Skip to content

Commit f82f9c1

Browse files
committed
Added: .or() method
Added: .or() Modified: Can add VerbalExpression objects as value Fixed: Typographic fixes
1 parent 3aeac64 commit f82f9c1

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

VerbalExpressions.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ window.VerbalExpression = (function(){
6363
// Sanitation function for adding
6464
// anything safely to the expression
6565
sanitize : function( value ) {
66+
if(value.source) return value.source;
6667
return value.replace(/[^\w]/g, function(character) { return "\\" + character; });
6768
},
6869

@@ -97,7 +98,7 @@ window.VerbalExpression = (function(){
9798
// behaviour to split the "scentences"
9899
// naturally.
99100
then : function( value ) {
100-
value = this.sanitize(value);
101+
value = this.sanitize( value );
101102
this.add( "(" + value + ")" );
102103
return( this );
103104
},
@@ -125,7 +126,7 @@ window.VerbalExpression = (function(){
125126

126127
// Anything but these characters
127128
anythingBut : function( value ) {
128-
value = this.sanitize(value);
129+
value = this.sanitize( value );
129130
this.add( "([^" + value + "]*)" );
130131
return( this );
131132
},
@@ -178,7 +179,7 @@ window.VerbalExpression = (function(){
178179
return( this.anyOf( value ) );
179180
},
180181

181-
// Usage: .range( from, to [, from, to ...] )
182+
// Usage: .range( from, to [, from, to ... ] )
182183
range : function() {
183184

184185
var value = "[";
@@ -242,7 +243,7 @@ window.VerbalExpression = (function(){
242243
},
243244

244245
// Multiline, also reversed
245-
searhOneLine : function( enable ) {
246+
searchOneLine : function( enable ) {
246247

247248
if(enable != false) this.removeModifier( "m" );
248249
else this.addModifier( "m" );
@@ -267,6 +268,18 @@ window.VerbalExpression = (function(){
267268
value += "+";
268269
}
269270
this.add( value );
271+
return( this );
272+
},
273+
274+
// Adds alternative expressions
275+
or : function( value ) {
276+
277+
if(this._prefixes.indexOf("(") == -1) this._prefixes += "(";
278+
if(this._suffixes.indexOf(")") == -1) this._suffixes = ")" + this._suffixes;
279+
280+
this.add( ")|(" );
281+
if(value) this.then( value );
282+
270283
return( this );
271284
}
272285

0 commit comments

Comments
 (0)