Permalink
Browse files

quicksave: work on KeywordText.matchOneWord(..)

  • Loading branch information...
1 parent 3269f80 commit dd5533e39f4f368c16dcfb096021165d7279a611 @dnsmkl committed May 9, 2012
Showing with 22 additions and 4 deletions.
  1. +22 −4 src/types.d
View
@@ -63,11 +63,29 @@ struct KeywordText
auto matchOneWord(string sqlText)
{
import std.algorithm:map;
- import std.array:split;
- auto paterns = std.algorithm.map!(std.regex.regex)(std.array.split(this.vLong));
- paterns ~= std.algorithm.map!(std.regex.regex)(std.array.split(this.vShort));
+ import std.array:split,array;
+ alias std.array.array array;
+ alias std.algorithm.map map;
+ alias std.array.split split;
+ Regex!char createFrontWordRegex(string a){ return regex("^" ~ a ~ r"\b","i"); }
+
+ auto paterns = map!createFrontWordRegex(split(this.vLong) ~ split(this.vShort));
+
+ auto tryPatern(Regex!char patern){ return std.regex.match(sqlText, patern); }
+ auto matches = map!tryPatern(paterns);
+ foreach(m ; matches)
+ {
+ if(m) return true;
+ }
+ return false;
+ }
+ unittest
+ {
+ auto a = KeywordText("LeFT JOiN");
+ assert( a.matchOneWord("LEFT WORD"));
+ assert( a.matchOneWord("JOIN WORD"));
+ assert(!a.matchOneWord("WORD LEFT"));
}
-
}
enum KeywordType { simple, composite };

0 comments on commit dd5533e

Please sign in to comment.