mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Use Charmatcher to check for illegal characters in identifiers
This commit is contained in:
parent
635cb3691d
commit
04f833c25a
@ -13,12 +13,13 @@
|
||||
*/
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import static com.google.common.base.CharMatcher.inRange;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Types;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mysema.commons.lang.Pair;
|
||||
@ -42,6 +43,10 @@ public class SQLTemplates extends Templates {
|
||||
|
||||
public static final SQLTemplates DEFAULT = new SQLTemplates("\"",'\\',false);
|
||||
|
||||
private static final CharMatcher NON_UNDERSCORE_ALPHA_NUMERIC =
|
||||
CharMatcher.is('_').or(inRange('a', 'z').or(inRange('A', 'Z'))).or(inRange('0', '9'))
|
||||
.negate().precomputed();
|
||||
|
||||
public abstract static class Builder {
|
||||
|
||||
protected boolean printSchema, quote, newLineToSingleSpace;
|
||||
@ -727,14 +732,7 @@ public class SQLTemplates extends Templates {
|
||||
}
|
||||
|
||||
protected boolean requiresQuotes(final String identifier) {
|
||||
for (int i = 0; i < identifier.length(); i++) {
|
||||
final char ch = identifier.charAt(i);
|
||||
//0-9,a-z,A-Z_
|
||||
if (ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < '_') || ch > 'z') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return NON_UNDERSCORE_ALPHA_NUMERIC.matchesAnyOf(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user