Skip to content

Commit 88f1a43

Browse files
committed
Rename
1 parent 86cd035 commit 88f1a43

2 files changed

Lines changed: 31 additions & 23 deletions

File tree

src/main/java/org/z3950/zing/cql/CQLTermNode.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ void toXCQLInternal(XCQLBuilder b, int level, List<CQLPrefix> prefixes,
7878

7979
@Override
8080
public String toCQL() {
81-
String quotedIndex = maybeQuote(index);
82-
String quotedTerm = maybeQuote(term);
81+
String quotedIndex = toCQLTerm(index);
82+
String quotedTerm = toCQLTerm(term);
8383
String res = quotedTerm;
8484

8585
if (index != null &&
@@ -192,7 +192,7 @@ public String toPQF(Properties config) throws PQFTranslationException {
192192
if (isResultSetIndex(index)) {
193193
// Special case: ignore relation, modifiers, wildcards, etc.
194194
// There's parallel code in toType1BER()
195-
return "@set " + maybeQuote(term);
195+
return "@set " + toCQLTerm(term);
196196
}
197197

198198
List<String> attrs = getAttrs(config);
@@ -219,10 +219,13 @@ public String toPQF(Properties config) throws PQFTranslationException {
219219
text = text.substring(0, len - 1);
220220
}
221221

222-
return s + maybeQuote(text);
222+
return s + toCQLTerm(text);
223223
}
224224

225-
static String maybeQuote(String str) {
225+
// ensure that a term is properly quoted for CQL output if necessary.
226+
// If the term has a bare double-quote (") it will be
227+
// escaped with a backslash.
228+
static String toCQLTerm(String str) {
226229
if (str == null) {
227230
return null;
228231
}

src/test/java/org/z3950/zing/cql/CQLTermNodeTest.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,53 @@
55

66
public class CQLTermNodeTest {
77
@Test
8-
public void TestMaybeQuoteNull() {
9-
assertNull(CQLTermNode.maybeQuote(null));
8+
public void TestTCQLTermQuoteNull() {
9+
assertNull(CQLTermNode.toCQLTerm(null));
1010
}
1111

1212
@Test
13-
public void TestMaybeQuoteEmpty() {
14-
assertEquals("\"\"", CQLTermNode.maybeQuote(""));
13+
public void TestTCQLTermQuoteEmpty() {
14+
assertEquals("\"\"", CQLTermNode.toCQLTerm(""));
1515
}
1616

1717
@Test
18-
public void TestMaybeQuoteRelation() {
19-
assertEquals("\"<\"", CQLTermNode.maybeQuote("<"));
18+
public void TestTCQLTermQuoteRelation() {
19+
assertEquals("\"<\"", CQLTermNode.toCQLTerm("<"));
2020
}
2121

2222
@Test
23-
public void TestMaybeQuoteSimple() {
24-
assertEquals("simple", CQLTermNode.maybeQuote("simple"));
23+
public void TestTCQLTermQuoteSimple() {
24+
assertEquals("simple", CQLTermNode.toCQLTerm("simple"));
2525
}
2626

2727
@Test
28-
public void TestMaybeQuoteBlank() {
29-
assertEquals("\"a b\"", CQLTermNode.maybeQuote("a b"));
28+
public void TestTCQLTermQuoteBlank() {
29+
assertEquals("\"a b\"", CQLTermNode.toCQLTerm("a b"));
3030
}
3131

3232
@Test
33-
public void TestMaybeQuoteQuote1() {
34-
assertEquals("a\\\"", CQLTermNode.maybeQuote("a\""));
33+
public void TestTCQLTermQuoteQuote1() {
34+
assertEquals("a\\\"", CQLTermNode.toCQLTerm("a\""));
3535
}
3636

3737
@Test
38-
public void TestMaybeQuoteQuote2() {
39-
assertEquals("a\\\"", CQLTermNode.maybeQuote("a\\\""));
38+
public void TestTCQLTermQuoteQuote2() {
39+
assertEquals("a\\\"", CQLTermNode.toCQLTerm("a\\\""));
4040
}
4141

4242
@Test
43-
public void TestMaybeQuoteQuote3() {
44-
assertEquals("a" + "\\\\" + "\\\"", CQLTermNode.maybeQuote("a" + "\\\\" + "\""));
43+
public void TestTCQLTermQuoteQuote3() {
44+
assertEquals("a" + "\\\\" + "\\\"", CQLTermNode.toCQLTerm("a" + "\\\\" + "\""));
4545
}
4646

4747
@Test
48-
public void TestMaybeQuoteQuote4() {
49-
assertEquals("a" + "\\\\" + "\\\"", CQLTermNode.maybeQuote("a" + "\\\\" + "\\\""));
48+
public void TestTCQLTermQuoteQuote4() {
49+
assertEquals("a" + "\\\\" + "\\\"", CQLTermNode.toCQLTerm("a" + "\\\\" + "\\\""));
50+
}
51+
52+
@Test
53+
public void TestTCQLTermQuoteBackSlashTrail() {
54+
assertEquals("a\\", CQLTermNode.toCQLTerm("a\\"));
5055
}
5156

5257
}

0 commit comments

Comments
 (0)