1 |
|
package org.codehaus.mojo.sql; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
import org.codehaus.plexus.util.StringUtils; |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
|
|
| 0% |
Uncovered Elements: 63 (63) |
Complexity: 20 |
Complexity Density: 0.57 |
|
27 |
|
public class SqlSplitter |
28 |
|
{ |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
public static final int NO_END = -1; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@param |
40 |
|
@param |
41 |
|
@return |
42 |
|
@value |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 60 (60) |
Complexity: 19 |
Complexity Density: 0.56 |
|
44 |
0
|
public static int containsSqlEnd( String line, String delimiter ) ... |
45 |
|
{ |
46 |
|
|
47 |
0
|
boolean isComment = false; |
48 |
|
|
49 |
0
|
boolean isAlphaDelimiter = StringUtils.isAlpha( delimiter ); |
50 |
|
|
51 |
0
|
if ( line == null || line.length() == 0 ) |
52 |
|
{ |
53 |
0
|
return NO_END; |
54 |
|
} |
55 |
|
|
56 |
0
|
int pos = 0; |
57 |
|
|
58 |
0
|
do |
59 |
|
{ |
60 |
0
|
if ( isComment ) |
61 |
|
{ |
62 |
0
|
if ( line.startsWith( "*/", pos ) ) |
63 |
|
{ |
64 |
0
|
isComment = false; |
65 |
|
} |
66 |
|
else |
67 |
|
{ |
68 |
0
|
pos++; |
69 |
0
|
continue; |
70 |
|
} |
71 |
|
} |
72 |
|
|
73 |
0
|
if ( line.startsWith( "/*", pos ) ) |
74 |
|
{ |
75 |
0
|
isComment = true; |
76 |
0
|
pos += 2; |
77 |
0
|
continue; |
78 |
|
} |
79 |
|
|
80 |
0
|
if ( line.startsWith( "--", pos ) ) |
81 |
|
{ |
82 |
0
|
return NO_END; |
83 |
|
} |
84 |
|
|
85 |
0
|
if ( line.startsWith( "'", pos ) || line.startsWith( "\"", pos ) ) |
86 |
|
{ |
87 |
0
|
String quoteChar = "" + line.charAt( pos ); |
88 |
0
|
String quoteEscape = "\\" + quoteChar; |
89 |
0
|
pos++; |
90 |
|
|
91 |
0
|
if ( line.length() <= pos ) |
92 |
|
{ |
93 |
0
|
return NO_END; |
94 |
|
} |
95 |
|
|
96 |
0
|
do |
97 |
|
{ |
98 |
0
|
if ( line.startsWith( quoteEscape, pos ) ) |
99 |
|
{ |
100 |
0
|
pos += 2; |
101 |
|
} |
102 |
0
|
} while ( !line.startsWith( quoteChar, pos++ ) ); |
103 |
|
|
104 |
0
|
continue; |
105 |
|
} |
106 |
|
|
107 |
0
|
if ( line.startsWith( delimiter, pos ) ) |
108 |
|
{ |
109 |
0
|
if ( isAlphaDelimiter ) |
110 |
|
{ |
111 |
|
|
112 |
|
|
113 |
0
|
if ( ( pos == 0 || !isAlpha( line.charAt( pos - 1 ) ) ) |
114 |
|
&& ( line.length() == pos + delimiter.length() |
115 |
|
|| !isAlpha( line.charAt( pos + delimiter.length() ) ) ) ) |
116 |
|
{ |
117 |
0
|
return pos + delimiter.length(); |
118 |
|
} |
119 |
|
} |
120 |
|
else |
121 |
|
{ |
122 |
0
|
return pos + delimiter.length(); |
123 |
|
} |
124 |
|
} |
125 |
|
|
126 |
0
|
pos++; |
127 |
|
|
128 |
0
|
} while ( line.length() >= pos ); |
129 |
|
|
130 |
0
|
return NO_END; |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
@param |
135 |
|
@return |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0
|
private static boolean isAlpha( char c )... |
138 |
|
{ |
139 |
0
|
return Character.isUpperCase( c ) || Character.isLowerCase( c ); |
140 |
|
} |
141 |
|
|
142 |
|
} |