blob: 7030cb929cd3a69c1d32c8bee2032c3500c172b8 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
2 * Regex object for checking the context of the hint
3 */
Akronda5bd3a2020-10-16 17:37:49 +02004"use strict";
5
Nils Diewald0e6992a2015-04-14 20:13:52 +00006define({
Nils Diewald7148c6f2015-05-04 15:07:53 +00007
8 /**
9 * Create analyzer based on regular expression.
10 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000011 create : function (regex) {
12 return Object.create(this)._init(regex);
13 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000014
15 // Initialize analyzer
Nils Diewald0e6992a2015-04-14 20:13:52 +000016 _init : function (regex) {
17 try {
18 this._regex = new RegExp(regex);
19 }
20 catch (e) {
21 KorAP.log(0, e);
22 return;
23 };
24 return this;
25 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000026
27 /**
28 * Check a context based on the analyzer
29 * and return a valid context string.
30 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000031 test : function (text) {
32 if (!this._regex.exec(text))
33 return;
34 return RegExp.$1;
35 }
36});