1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.metricshub.wbem.sblim.cimclient.internal.uri;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import org.metricshub.wbem.sblim.cimclient.internal.util.MOF;
43 import org.metricshub.wbem.sblim.cimclient.internal.util.Util;
44
45
46
47
48 public class StringValue extends Value implements QuotedValue {
49 private static final int NORMAL = 0;
50
51 private static final int ESCAPED = 1;
52
53 private static final int CLOSED = 2;
54
55
56
57
58
59
60
61
62
63 public static Value parse(URIString pUriStr) throws IllegalArgumentException {
64 URIString uriStr = pUriStr.deepCopy();
65 if (uriStr.charAt(0) != '\"') {
66 String msg = "Starting '\"' is missing!\n" + uriStr.markPosition();
67 throw new IllegalArgumentException(msg);
68 }
69 int rIdx = 1;
70 StringBuffer dstBuf = new StringBuffer();
71 int state = NORMAL;
72 while (rIdx < uriStr.length()) {
73 char ch = uriStr.charAt(rIdx++);
74 if (state == NORMAL) {
75 if (ch == '\\') {
76 state = ESCAPED;
77 continue;
78 }
79 if (ch == '"') {
80 state = CLOSED;
81 break;
82 }
83 } else {
84 state = NORMAL;
85 }
86 dstBuf.append(ch);
87 }
88 if (state != CLOSED) {
89 String msg = "Closing '\"' is missing!\n" + uriStr.markPosition(rIdx);
90 throw new IllegalArgumentException(msg);
91 }
92 uriStr.cutStarting(rIdx);
93
94 if (uriStr.length() != 0 && uriStr.charAt(0) != ',') {
95 String msg = "Next character should be ',' or end of string!\n" + uriStr.markPosition();
96 throw new IllegalArgumentException(msg);
97 }
98 pUriStr.set(uriStr);
99 return new StringValue(dstBuf.toString());
100 }
101
102 private String iStr;
103
104 private StringValue(String pStr) {
105 this.iStr = pStr;
106 }
107
108
109
110
111 @Override
112 public String toString() {
113 return this.iStr;
114 }
115
116
117
118
119 public String toQuotedString() {
120 return Util.quote(this.iStr);
121 }
122
123
124
125
126 @Override
127 public String getTypeInfo() {
128 return MOF.DT_STR;
129 }
130 }