private static String translateFormat ( String formatString , Map < String , String > mapping , String escapeStart , String escapeEnd , String targetEscapeStart , String targetEscapeEnd ) { int beginIndex = 0 ; int i = 0 ; char lastChar = 0 ; char currentChar = 0 ; String resultString = "" ; char esc1 = escapeStart . charAt ( 0 ) ; char esc2 = escapeEnd . charAt ( 0 ) ; for ( ; i < formatString . length ( ) ; i ++ ) { currentChar = formatString . charAt ( i ) ; if ( i > 0 && lastChar != currentChar ) { resultString += mapSubformat ( formatString , mapping , beginIndex , i , escapeStart , escapeEnd , targetEscapeStart , targetEscapeEnd ) ; beginIndex = i ; } lastChar = currentChar ; if ( currentChar == esc1 ) { i ++ ; while ( i < formatString . length ( ) && formatString . charAt ( i ) != esc2 ) { i ++ ; } resultString += targetEscapeStart ; resultString += formatString . substring ( beginIndex + 1 , i ) ; resultString += targetEscapeEnd ; i ++ ; if ( i < formatString . length ( ) ) { lastChar = formatString . charAt ( i ) ; } beginIndex = i ; } } if ( beginIndex < formatString . length ( ) && i <= formatString . length ( ) ) { return resultString + mapSubformat ( formatString , mapping , beginIndex , i , escapeStart , escapeEnd , targetEscapeStart , targetEscapeEnd ) ; } else { return resultString ; } }
Internal method to do translations