1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.sql.parser.sql.common.value.identifier;
19
20 import com.google.common.base.Strings;
21 import lombok.EqualsAndHashCode;
22 import lombok.Getter;
23 import lombok.RequiredArgsConstructor;
24 import lombok.ToString;
25 import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
26 import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
27 import org.apache.shardingsphere.sql.parser.sql.common.value.ValueASTNode;
28
29
30
31
32 @RequiredArgsConstructor
33 @Getter
34 @EqualsAndHashCode
35 @ToString
36 public final class IdentifierValue implements ValueASTNode<String> {
37
38 private final String value;
39
40 private final QuoteCharacter quoteCharacter;
41
42 public IdentifierValue(final String text) {
43 this(SQLUtils.getExactlyValue(text), QuoteCharacter.getQuoteCharacter(text));
44 }
45
46 public IdentifierValue(final String text, final String reservedCharacters) {
47 this(SQLUtils.getExactlyValue(text, reservedCharacters), QuoteCharacter.getQuoteCharacter(text));
48 }
49
50
51
52
53
54
55 public String getValueWithQuoteCharacters() {
56 return null == value ? "" : quoteCharacter.wrap(value);
57 }
58
59
60
61
62
63
64
65 public static String getQuotedContent(final String text) {
66 if (Strings.isNullOrEmpty(text)) {
67 return text;
68 }
69 QuoteCharacter quoteCharacter = QuoteCharacter.getQuoteCharacter(text);
70 if (QuoteCharacter.NONE == quoteCharacter) {
71 return text.trim();
72 }
73 return text.substring(1, text.length() - 1);
74 }
75 }