@@ -70,39 +70,26 @@ public String perform() {
7070 while ( tokens .hasMoreTokens () ) {
7171 token = tokens .nextToken ();
7272
73- if ( "-" .equals (token ) && result .toString ().endsWith ("-" ) ) {
73+ if ( "-" .equals ( token ) && result .toString ().endsWith ( "-" ) ) {
7474 do {
7575 result .append ( token );
7676 token = tokens .nextToken ();
7777 }
7878 while ( !"\n " .equals ( token ) && tokens .hasMoreTokens () );
7979 }
8080
81- lcToken = token .toLowerCase (Locale .ROOT );
82- switch (lcToken ) {
83-
81+ lcToken = token .toLowerCase ( Locale .ROOT );
82+ switch ( lcToken ) {
8483 case "'" :
8584 case "`" :
8685 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 );
9487 misc ();
9588 break ;
9689 // SQL Server uses "[" and "]" to escape reserved words
9790 // see SQLServerDialect.openQuote and SQLServerDialect.closeQuote
9891 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 ("]" );
10693 misc ();
10794 break ;
10895
@@ -238,7 +225,7 @@ private void from() {
238225 }
239226
240227 private void comma () {
241- if ( afterByOrSetOrFromOrSelect && inFunction == 0 ) {
228+ if ( afterByOrSetOrFromOrSelect && inFunction == 0 ) {
242229 commaAfterByOrFromOrSelect ();
243230 }
244231// else if ( afterOn && inFunction==0 ) {
@@ -313,7 +300,7 @@ private void beginCase() {
313300
314301 private void misc () {
315302 out ();
316- if ( afterInsert && inFunction == 0 ) {
303+ if ( afterInsert && inFunction == 0 ) {
317304 newline ();
318305 afterInsert = false ;
319306 }
@@ -329,7 +316,7 @@ private void white() {
329316 }
330317
331318 private void updateOrInsertOrDelete () {
332- if ( indent > 1 ) {
319+ if ( indent > 1 ) {
333320 //probably just the insert SQL function
334321 out ();
335322 }
@@ -367,7 +354,7 @@ private void select() {
367354
368355 private void out () {
369356 if ( result .charAt ( result .length () - 1 ) == ',' ) {
370- result .append (" " );
357+ result .append ( " " );
371358 }
372359 result .append ( token );
373360 }
@@ -390,8 +377,8 @@ private void endNewClause() {
390377 newline ();
391378 afterBeginBeforeEnd = false ;
392379 afterByOrSetOrFromOrSelect = "by" .equals ( lcToken )
393- || "set" .equals ( lcToken )
394- || "from" .equals ( lcToken );
380+ || "set" .equals ( lcToken )
381+ || "from" .equals ( lcToken );
395382 }
396383
397384 private void beginNewClause () {
@@ -507,9 +494,21 @@ private static boolean isWhitespace(String token) {
507494
508495 private void newline () {
509496 result .append ( System .lineSeparator () )
510- .append ( INDENT_STRING .repeat (indent ) );
497+ .append ( INDENT_STRING .repeat ( indent ) );
511498 beginLine = true ;
512499 }
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+ }
513512 }
514513
515514}
0 commit comments