DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | List of all members
Deveel.Data.Text.SystemRegexLibrary Class Reference

The default implementation of the system regular expression library. More...

Inheritance diagram for Deveel.Data.Text.SystemRegexLibrary:
Deveel.Data.Text.IRegexLibrary

Public Member Functions

bool RegexMatch (string regularExpression, string expressionOps, string value)
 Matches a regular expression against a string value. More...
 
IList< int > RegexSearch (Table table, int column, string regularExpression, string expressionOps)
 Performs a regular expression search on the given column of the table. More...
 

Detailed Description

The default implementation of the system regular expression library.

Definition at line 26 of file SystemRegexLibrary.cs.

Member Function Documentation

bool Deveel.Data.Text.SystemRegexLibrary.RegexMatch ( string  regularExpression,
string  expressionOps,
string  value 
)
inline

Matches a regular expression against a string value.

Parameters
regularExpressionThe regular expression to match.
expressionOpsThe expression options string that specifies various flags.
valueThe string to test.
Returns
If the value is a match against the expression then it returns true, otherwise it returns false.

Implements Deveel.Data.Text.IRegexLibrary.

Definition at line 28 of file SystemRegexLibrary.cs.

28  {
29  RegexOptions options = RegexOptions.None;
30 
31  if (expressionOps != null) {
32  if (expressionOps.IndexOf('i') != -1) {
33  options |= RegexOptions.IgnoreCase;
34  }
35  if (expressionOps.IndexOf('s') != -1) {
36  options |= RegexOptions.Singleline;
37  }
38  if (expressionOps.IndexOf('m') != -1) {
39  options |= RegexOptions.Multiline;
40  }
41  }
42 
43  Regex regex = new Regex(regularExpression, options);
44  return regex.IsMatch(value);
45  }
IList<int> Deveel.Data.Text.SystemRegexLibrary.RegexSearch ( Table  table,
int  column,
string  regularExpression,
string  expressionOps 
)
inline

Performs a regular expression search on the given column of the table.

Parameters
tableThe table to search for matching values.
columnThe column of the table to search for matching values.
regularExpressionThe expression to match (eg. "[0-9]+").
expressionOpsExpression operator string that specifies various flags.
Returns
Returns an IntegerVector that contains the list of rows in the table that matched the expression, or an empty list if the expression matched no rows in the column.

Implements Deveel.Data.Text.IRegexLibrary.

Definition at line 47 of file SystemRegexLibrary.cs.

47  {
48  // Get the ordered column,
49  IList<int> row_list = table.SelectAll(column);
50  // The result matched rows,
51  List<int> result_list = new List<int>();
52 
53  // Make into a new list that matches the pattern,
54  Regex regex;
55 
56  try {
57  RegexOptions options = RegexOptions.None;
58  if (expressionOps != null) {
59  if (expressionOps.IndexOf('i') != -1) {
60  options |= RegexOptions.IgnoreCase;
61  }
62  if (expressionOps.IndexOf('s') != -1) {
63  options |= RegexOptions.Singleline;
64  }
65  if (expressionOps.IndexOf('m') != -1) {
66  options |= RegexOptions.Multiline;
67  }
68  }
69 
70  regex = new Regex(regularExpression, options);
71  } catch (Exception) {
72  // Incorrect syntax means we always match to an empty list,
73  return result_list;
74  }
75 
76  // For each row in the column, test it against the regular expression.
77  int size = row_list.Count;
78  for (int i = 0; i < size; ++i) {
79  int row_index = row_list[i];
80  TObject cell = table.GetCell(column, row_index);
81  // Only try and match against non-null cells.
82  if (!cell.IsNull) {
83  Object ob = cell.Object;
84  String str = ob.ToString();
85  // If the column matches the regular expression then return it,
86  if (regex.IsMatch(str)) {
87  result_list.Add(row_index);
88  }
89  }
90  }
91 
92  return result_list;
93  }
A long string in the system.

The documentation for this class was generated from the following file: