1 24 25 package com.mckoi.database.regexbridge; 26 27 import com.mckoi.database.*; 28 import com.mckoi.util.IntegerVector; 29 import gnu.regexp.*; 30 31 38 39 public class GNURegex implements com.mckoi.database.RegexLibrary { 40 41 public boolean regexMatch(String regular_expression, String expression_ops, 42 String value) { 43 try { 44 46 int c_flags = 0; 47 if (expression_ops != null) { 48 if (expression_ops.indexOf('i') != -1) { 49 c_flags += RE.REG_ICASE; 50 } 51 if (expression_ops.indexOf('s') != -1) { 52 c_flags += RE.REG_DOT_NEWLINE; 53 } 54 if (expression_ops.indexOf('m') != -1) { 55 c_flags += RE.REG_MULTILINE; 56 } 57 } 58 59 RE re = new RE(regular_expression, c_flags); 60 return re.isMatch(value); 61 } 62 catch (REException e) { 63 return false; 65 } 66 } 67 68 public IntegerVector regexSearch(Table table, int column, 69 String regular_expression, String expression_ops) { 70 IntegerVector row_list = table.selectAll(column); 72 IntegerVector result_list = new IntegerVector(); 74 75 RE re; 77 try { 78 80 int c_flags = 0; 81 if (expression_ops != null) { 82 if (expression_ops.indexOf('i') != -1) { 83 c_flags += RE.REG_ICASE; 84 } 85 if (expression_ops.indexOf('s') != -1) { 86 c_flags += RE.REG_DOT_NEWLINE; 87 } 88 if (expression_ops.indexOf('m') != -1) { 89 c_flags += RE.REG_MULTILINE; 90 } 91 } 92 93 re = new RE(regular_expression, c_flags); 94 } 95 catch (REException e) { 96 return result_list; 98 } 99 100 int size = row_list.size(); 102 for (int i = 0; i < size; ++i) { 103 int row_index = row_list.intAt(i); 104 TObject cell = table.getCellContents(column, row_index); 105 if (!cell.isNull()) { 107 Object ob = cell.getObject(); 108 String str = ob.toString(); 109 if (re.isMatch(str)) { 111 result_list.addInt(row_index); 112 } 113 } 114 } 115 116 return result_list; 117 } 118 119 } 120 | Popular Tags |