-
Notifications
You must be signed in to change notification settings - Fork 4
/
xt_regexp.jsp
148 lines (134 loc) · 4.57 KB
/
xt_regexp.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
create or replace and compile java source named xt_regexp as
package com.xt_r;
/* Imports */
import java.sql.*;
import java.util.*;
import java.util.regex.*;
import oracle.sql.*;
import oracle.jdbc.driver.OracleDriver;
/* Main class */
public class XT_REGEXP
{
/**
* Simple regexp split with count - java.lang.String.split
*/
public static oracle.sql.ARRAY split(
java.lang.String pStr,
java.lang.String pDelim,
int pMaxCount)
throws SQLException
{
java.lang.String[] retArray = new java.lang.String[0];
if (pDelim==null) pDelim="";
if (pStr!=null)
retArray = pStr.split(pDelim,pMaxCount);
Connection conn = new OracleDriver().defaultConnection();
ArrayDescriptor descriptor =
ArrayDescriptor.createDescriptor("VARCHAR2_TABLE", conn );
oracle.sql.ARRAY outArray = new oracle.sql.ARRAY(descriptor,conn,retArray);
return outArray;
}
/**
* Function matches regexp
*/
public static boolean matches(java.lang.String pStr,java.lang.String pPattern,int pFlags)
throws SQLException
{
if(pPattern==null) pPattern="";
if(pStr==null) pStr="";
Pattern p = Pattern.compile(pPattern,pFlags);
Matcher m = p.matcher(pStr);
boolean b=m.find();
return b;
}
/**
* Function count matches regexp
*/
public static int matches_count(java.lang.String pStr,java.lang.String pPattern,int pFlags)
throws SQLException
{
if(pPattern==null) pPattern="";
if(pStr==null) pStr="";
Pattern p = Pattern.compile(pPattern,pFlags);
Matcher m = p.matcher(pStr);
int i = 0;
while(m.find())
i++;
return i;
}
/**
* Function returns regexp matches with limit
*/
public static oracle.sql.ARRAY getMatches(java.lang.String pStr,java.lang.String pPattern, int pGroup, int pFlags,int pMaxCount)
throws SQLException
{
List list = new ArrayList();
if(pPattern==null) pPattern="";
if(pStr==null) pStr="";
Pattern p = Pattern.compile(pPattern,pFlags);
Matcher m = p.matcher(pStr);
StringBuffer sb = new StringBuffer();
int i=0;
while(m.find() && (pMaxCount==0 || i++<pMaxCount)){
list.add(m.group(pGroup));
}
Connection conn = new OracleDriver().defaultConnection();
ArrayDescriptor descriptor =
ArrayDescriptor.createDescriptor("VARCHAR2_TABLE", conn );
oracle.sql.ARRAY outArray = new oracle.sql.ARRAY(descriptor,conn,list.toArray());
return outArray;
}
/**
* Function returns joined regexp matches
*/
public static java.lang.String joinMatches(java.lang.String pStr,java.lang.String pPattern, int pGroup, int pFlags, java.lang.String pDelim)
throws SQLException
{
if(pPattern==null) pPattern="";
if(pStr==null) pStr="";
Pattern p = Pattern.compile(pPattern,pFlags);
Matcher m = p.matcher(pStr);
StringBuffer sb = new StringBuffer();
boolean b=m.find();
while(b){
sb.append(m.group(pGroup));
b=m.find();
if (b) sb.append(pDelim);
}
return sb.toString();
}
/**
* ReplaceFirst occurence by regexp
*/
public static java.lang.String replaceFirst(java.lang.String pStr,java.lang.String pPattern,java.lang.String pReplacement)
throws SQLException
{
if(pPattern==null) pPattern="";
if(pStr==null) pStr="";
if(pReplacement==null) pReplacement="";
return pStr.replaceFirst(pPattern,pReplacement);
}
/**
* ReplaceAll by regexp
*/
public static java.lang.String replaceAll(java.lang.String pStr,java.lang.String pPattern,java.lang.String pReplacement)
throws SQLException
{
if(pPattern==null) pPattern="";
if(pStr==null) pStr="";
if(pReplacement==null) pReplacement="";
return pStr.replaceAll(pPattern,pReplacement);
}
/**
* ReplaceChar by regexp
*/
public static java.lang.String replaceChar(java.lang.String pStr,java.lang.String pOldChar,java.lang.String pReplaceChar)
throws SQLException
{
if(pOldChar==null) pOldChar="";
if(pStr==null) pStr="";
if(pReplaceChar==null) pReplaceChar="";
return pStr.replace(pOldChar.charAt(0),pReplaceChar.charAt(0));
}
}
/