File tree Expand file tree Collapse file tree
java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5083,55 +5083,27 @@ Pattern compileSqlLikePattern(String sqlLikePattern) {
50835083 boolean escaped = false ;
50845084 for (int i = 0 ; i < sqlLikePattern .length (); i ++) {
50855085 char c = sqlLikePattern .charAt (i );
5086- if (escaped ) {
5087- if (isRegexMetacharacter (c )) {
5088- regex .append ('\\' ).append (c );
5089- } else {
5090- regex .append (c );
5091- }
5092- escaped = false ;
5093- } else if (c == '\\' ) {
5086+ if (!escaped && c == '\\' ) {
50945087 escaped = true ;
5088+ continue ;
5089+ } else if (!escaped && c == '%' ) {
5090+ regex .append (".*" );
5091+ } else if (!escaped && c == '_' ) {
5092+ regex .append ('.' );
50955093 } else {
5096- switch (c ) {
5097- case '%' :
5098- regex .append (".*" );
5099- break ;
5100- case '_' :
5101- regex .append ('.' );
5102- break ;
5103- default :
5104- if (isRegexMetacharacter (c )) {
5105- regex .append ('\\' ).append (c );
5106- } else {
5107- regex .append (c );
5108- }
5109- break ;
5094+ if (isRegexMetacharacter (c )) {
5095+ regex .append ('\\' );
51105096 }
5097+ regex .append (c );
51115098 }
5112- }
5113- if (escaped ) {
5114- regex .append ('\\' ).append ('\\' );
5099+ escaped = false ;
51155100 }
51165101 regex .append ('$' );
51175102 return Pattern .compile (regex .toString (), Pattern .CASE_INSENSITIVE );
51185103 }
51195104
5120- private boolean isRegexMetacharacter (char c ) {
5121- return c == '\\'
5122- || c == '.'
5123- || c == '['
5124- || c == ']'
5125- || c == '('
5126- || c == ')'
5127- || c == '{'
5128- || c == '}'
5129- || c == '*'
5130- || c == '+'
5131- || c == '?'
5132- || c == '^'
5133- || c == '$'
5134- || c == '|' ;
5105+ private static boolean isRegexMetacharacter (char c ) {
5106+ return "\\ .[]{}()*+?^$|" .indexOf (c ) != -1 ;
51355107 }
51365108
51375109 boolean needsListing (String pattern ) {
You can’t perform that action at this time.
0 commit comments