@@ -70,39 +70,26 @@ public String perform() {
70
70
while ( tokens .hasMoreTokens () ) {
71
71
token = tokens .nextToken ();
72
72
73
- if ( "-" .equals (token ) && result .toString ().endsWith ("-" ) ) {
73
+ if ( "-" .equals ( token ) && result .toString ().endsWith ( "-" ) ) {
74
74
do {
75
75
result .append ( token );
76
76
token = tokens .nextToken ();
77
77
}
78
78
while ( !"\n " .equals ( token ) && tokens .hasMoreTokens () );
79
79
}
80
80
81
- lcToken = token .toLowerCase (Locale .ROOT );
82
- switch (lcToken ) {
83
-
81
+ lcToken = token .toLowerCase ( Locale .ROOT );
82
+ switch ( lcToken ) {
84
83
case "'" :
85
84
case "`" :
86
85
case "\" " :
87
- String t ;
88
- do {
89
- t = tokens .nextToken ();
90
- token += t ;
91
- }
92
- while ( !lcToken .equals ( t ) && tokens .hasMoreTokens () );
93
- lcToken = token ;
86
+ appendUntilToken (lcToken );
94
87
misc ();
95
88
break ;
96
89
// SQL Server uses "[" and "]" to escape reserved words
97
90
// see SQLServerDialect.openQuote and SQLServerDialect.closeQuote
98
91
case "[" :
99
- String tt ;
100
- do {
101
- tt = tokens .nextToken ();
102
- token += tt ;
103
- }
104
- while ( !"]" .equals ( tt ) && tokens .hasMoreTokens () );
105
- lcToken = token ;
92
+ appendUntilToken ("]" );
106
93
misc ();
107
94
break ;
108
95
@@ -238,7 +225,7 @@ private void from() {
238
225
}
239
226
240
227
private void comma () {
241
- if ( afterByOrSetOrFromOrSelect && inFunction == 0 ) {
228
+ if ( afterByOrSetOrFromOrSelect && inFunction == 0 ) {
242
229
commaAfterByOrFromOrSelect ();
243
230
}
244
231
// else if ( afterOn && inFunction==0 ) {
@@ -313,7 +300,7 @@ private void beginCase() {
313
300
314
301
private void misc () {
315
302
out ();
316
- if ( afterInsert && inFunction == 0 ) {
303
+ if ( afterInsert && inFunction == 0 ) {
317
304
newline ();
318
305
afterInsert = false ;
319
306
}
@@ -329,7 +316,7 @@ private void white() {
329
316
}
330
317
331
318
private void updateOrInsertOrDelete () {
332
- if ( indent > 1 ) {
319
+ if ( indent > 1 ) {
333
320
//probably just the insert SQL function
334
321
out ();
335
322
}
@@ -367,7 +354,7 @@ private void select() {
367
354
368
355
private void out () {
369
356
if ( result .charAt ( result .length () - 1 ) == ',' ) {
370
- result .append (" " );
357
+ result .append ( " " );
371
358
}
372
359
result .append ( token );
373
360
}
@@ -390,8 +377,8 @@ private void endNewClause() {
390
377
newline ();
391
378
afterBeginBeforeEnd = false ;
392
379
afterByOrSetOrFromOrSelect = "by" .equals ( lcToken )
393
- || "set" .equals ( lcToken )
394
- || "from" .equals ( lcToken );
380
+ || "set" .equals ( lcToken )
381
+ || "from" .equals ( lcToken );
395
382
}
396
383
397
384
private void beginNewClause () {
@@ -507,9 +494,21 @@ private static boolean isWhitespace(String token) {
507
494
508
495
private void newline () {
509
496
result .append ( System .lineSeparator () )
510
- .append ( INDENT_STRING .repeat (indent ) );
497
+ .append ( INDENT_STRING .repeat ( indent ) );
511
498
beginLine = true ;
512
499
}
500
+
501
+ private void appendUntilToken (String stopToken ) {
502
+ final StringBuilder sb = new StringBuilder ( this .token );
503
+ String t ;
504
+ do {
505
+ t = tokens .nextToken ();
506
+ sb .append ( t );
507
+ }
508
+ while ( !stopToken .equals ( t ) && tokens .hasMoreTokens () );
509
+ this .token = sb .toString ();
510
+ lcToken = token ;
511
+ }
513
512
}
514
513
515
514
}
0 commit comments