@@ -300,8 +300,7 @@ public <V> StrSubstitutor(final Map<String, V> valueMap, final String prefix, fi
300300 * @param escape the escape character
301301 * @throws IllegalArgumentException if the prefix or suffix is null
302302 */
303- public <V > StrSubstitutor (final Map <String , V > valueMap , final String prefix , final String suffix ,
304- final char escape ) {
303+ public <V > StrSubstitutor (final Map <String , V > valueMap , final String prefix , final String suffix , final char escape ) {
305304 this (StrLookup .mapLookup (valueMap ), prefix , suffix , escape );
306305 }
307306
@@ -317,8 +316,7 @@ public <V> StrSubstitutor(final Map<String, V> valueMap, final String prefix, fi
317316 * @throws IllegalArgumentException if the prefix or suffix is null
318317 * @since 3.2
319318 */
320- public <V > StrSubstitutor (final Map <String , V > valueMap , final String prefix , final String suffix ,
321- final char escape , final String valueDelimiter ) {
319+ public <V > StrSubstitutor (final Map <String , V > valueMap , final String prefix , final String suffix , final char escape , final String valueDelimiter ) {
322320 this (StrLookup .mapLookup (valueMap ), prefix , suffix , escape , valueDelimiter );
323321 }
324322
@@ -340,13 +338,12 @@ public StrSubstitutor(final StrLookup<?> variableResolver) {
340338 * @param escape the escape character
341339 * @throws IllegalArgumentException if the prefix or suffix is null
342340 */
343- public StrSubstitutor (final StrLookup <?> variableResolver , final String prefix , final String suffix ,
344- final char escape ) {
345- this .setVariableResolver (variableResolver );
346- this .setVariablePrefix (prefix );
347- this .setVariableSuffix (suffix );
348- this .setEscapeChar (escape );
349- this .setValueDelimiterMatcher (DEFAULT_VALUE_DELIMITER );
341+ public StrSubstitutor (final StrLookup <?> variableResolver , final String prefix , final String suffix , final char escape ) {
342+ setVariableResolver (variableResolver );
343+ setVariablePrefix (prefix );
344+ setVariableSuffix (suffix );
345+ setEscapeChar (escape );
346+ setValueDelimiterMatcher (DEFAULT_VALUE_DELIMITER );
350347 }
351348
352349 /**
@@ -360,13 +357,12 @@ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix,
360357 * @throws IllegalArgumentException if the prefix or suffix is null
361358 * @since 3.2
362359 */
363- public StrSubstitutor (final StrLookup <?> variableResolver , final String prefix , final String suffix ,
364- final char escape , final String valueDelimiter ) {
365- this .setVariableResolver (variableResolver );
366- this .setVariablePrefix (prefix );
367- this .setVariableSuffix (suffix );
368- this .setEscapeChar (escape );
369- this .setValueDelimiter (valueDelimiter );
360+ public StrSubstitutor (final StrLookup <?> variableResolver , final String prefix , final String suffix , final char escape , final String valueDelimiter ) {
361+ setVariableResolver (variableResolver );
362+ setVariablePrefix (prefix );
363+ setVariableSuffix (suffix );
364+ setEscapeChar (escape );
365+ setValueDelimiter (valueDelimiter );
370366 }
371367
372368 /**
@@ -378,9 +374,7 @@ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix,
378374 * @param escape the escape character
379375 * @throws IllegalArgumentException if the prefix or suffix is null
380376 */
381- public StrSubstitutor (
382- final StrLookup <?> variableResolver , final StrMatcher prefixMatcher , final StrMatcher suffixMatcher ,
383- final char escape ) {
377+ public StrSubstitutor (final StrLookup <?> variableResolver , final StrMatcher prefixMatcher , final StrMatcher suffixMatcher , final char escape ) {
384378 this (variableResolver , prefixMatcher , suffixMatcher , escape , DEFAULT_VALUE_DELIMITER );
385379 }
386380
@@ -395,14 +389,13 @@ public StrSubstitutor(
395389 * @throws IllegalArgumentException if the prefix or suffix is null
396390 * @since 3.2
397391 */
398- public StrSubstitutor (
399- final StrLookup <?> variableResolver , final StrMatcher prefixMatcher , final StrMatcher suffixMatcher ,
400- final char escape , final StrMatcher valueDelimiterMatcher ) {
401- this .setVariableResolver (variableResolver );
402- this .setVariablePrefixMatcher (prefixMatcher );
403- this .setVariableSuffixMatcher (suffixMatcher );
404- this .setEscapeChar (escape );
405- this .setValueDelimiterMatcher (valueDelimiterMatcher );
392+ public StrSubstitutor (final StrLookup <?> variableResolver , final StrMatcher prefixMatcher , final StrMatcher suffixMatcher , final char escape ,
393+ final StrMatcher valueDelimiterMatcher ) {
394+ setVariableResolver (variableResolver );
395+ setVariablePrefixMatcher (prefixMatcher );
396+ setVariableSuffixMatcher (suffixMatcher );
397+ setEscapeChar (escape );
398+ setValueDelimiterMatcher (valueDelimiterMatcher );
406399 }
407400
408401 /**
@@ -1115,16 +1108,14 @@ private int substitute(final StrBuilder buf, final int offset, final int length,
11151108 final char escape = getEscapeChar ();
11161109 final StrMatcher valueDelimMatcher = getValueDelimiterMatcher ();
11171110 final boolean substitutionInVariablesEnabled = isEnableSubstitutionInVariables ();
1118-
11191111 final boolean top = priorVariables == null ;
11201112 boolean altered = false ;
11211113 int lengthChange = 0 ;
11221114 char [] chars = buf .buffer ;
11231115 int bufEnd = offset + length ;
11241116 int pos = offset ;
11251117 while (pos < bufEnd ) {
1126- final int startMatchLen = pfxMatcher .isMatch (chars , pos , offset ,
1127- bufEnd );
1118+ final int startMatchLen = pfxMatcher .isMatch (chars , pos , offset , bufEnd );
11281119 if (startMatchLen == 0 ) {
11291120 pos ++;
11301121 } else // found variable start marker
@@ -1146,43 +1137,34 @@ private int substitute(final StrBuilder buf, final int offset, final int length,
11461137 int endMatchLen ;
11471138 int nestedVarCount = 0 ;
11481139 while (pos < bufEnd ) {
1149- if (substitutionInVariablesEnabled
1150- && (endMatchLen = pfxMatcher .isMatch (chars ,
1151- pos , offset , bufEnd )) != 0 ) {
1140+ if (substitutionInVariablesEnabled && (endMatchLen = pfxMatcher .isMatch (chars , pos , offset , bufEnd )) != 0 ) {
11521141 // found a nested variable start
11531142 nestedVarCount ++;
11541143 pos += endMatchLen ;
11551144 continue ;
11561145 }
1157-
1158- endMatchLen = suffMatcher .isMatch (chars , pos , offset ,
1159- bufEnd );
1146+ endMatchLen = suffMatcher .isMatch (chars , pos , offset , bufEnd );
11601147 if (endMatchLen == 0 ) {
11611148 pos ++;
11621149 } else {
11631150 // found variable end marker
11641151 if (nestedVarCount == 0 ) {
1165- String varNameExpr = new String (chars , startPos
1166- + startMatchLen , pos - startPos
1167- - startMatchLen );
1152+ String varNameExpr = new String (chars , startPos + startMatchLen , pos - startPos - startMatchLen );
11681153 if (substitutionInVariablesEnabled ) {
11691154 final StrBuilder bufName = new StrBuilder (varNameExpr );
11701155 substitute (bufName , 0 , bufName .length ());
11711156 varNameExpr = bufName .toString ();
11721157 }
11731158 pos += endMatchLen ;
11741159 final int endPos = pos ;
1175-
11761160 String varName = varNameExpr ;
11771161 String varDefaultValue = null ;
1178-
11791162 if (valueDelimMatcher != null ) {
1180- final char [] varNameExprChars = varNameExpr .toCharArray ();
1163+ final char [] varNameExprChars = varNameExpr .toCharArray ();
11811164 int valueDelimiterMatchLen ;
11821165 for (int i = 0 ; i < varNameExprChars .length ; i ++) {
11831166 // if there's any nested variable when nested variable substitution disabled, then stop resolving name and default value.
1184- if (!substitutionInVariablesEnabled
1185- && pfxMatcher .isMatch (varNameExprChars , i , i , varNameExprChars .length ) != 0 ) {
1167+ if (!substitutionInVariablesEnabled && pfxMatcher .isMatch (varNameExprChars , i , i , varNameExprChars .length ) != 0 ) {
11861168 break ;
11871169 }
11881170 if ((valueDelimiterMatchLen = valueDelimMatcher .isMatch (varNameExprChars , i )) != 0 ) {
@@ -1192,21 +1174,16 @@ private int substitute(final StrBuilder buf, final int offset, final int length,
11921174 }
11931175 }
11941176 }
1195-
11961177 // on the first call initialize priorVariables
11971178 if (priorVariables == null ) {
11981179 priorVariables = new ArrayList <>();
1199- priorVariables .add (new String (chars ,
1200- offset , length ));
1180+ priorVariables .add (new String (chars , offset , length ));
12011181 }
1202-
12031182 // handle cyclic substitution
12041183 checkCyclicSubstitution (varName , priorVariables );
12051184 priorVariables .add (varName );
1206-
12071185 // resolve the variable
1208- String varValue = resolveVariable (varName , buf ,
1209- startPos , endPos );
1186+ String varValue = resolveVariable (varName , buf , startPos , endPos );
12101187 if (varValue == null ) {
12111188 varValue = varDefaultValue ;
12121189 }
@@ -1215,20 +1192,15 @@ private int substitute(final StrBuilder buf, final int offset, final int length,
12151192 final int varLen = varValue .length ();
12161193 buf .replace (startPos , endPos , varValue );
12171194 altered = true ;
1218- int change = substitute (buf , startPos ,
1219- varLen , priorVariables );
1220- change = change
1221- + varLen - (endPos - startPos );
1195+ int change = substitute (buf , startPos , varLen , priorVariables );
1196+ change = change + varLen - (endPos - startPos );
12221197 pos += change ;
12231198 bufEnd += change ;
12241199 lengthChange += change ;
1225- chars = buf .buffer ; // in case buffer was
1226- // altered
1200+ chars = buf .buffer ; // in case buffer was altered
12271201 }
1228-
12291202 // remove variable from the cyclic stack
1230- priorVariables
1231- .remove (priorVariables .size () - 1 );
1203+ priorVariables .remove (priorVariables .size () - 1 );
12321204 break ;
12331205 }
12341206 nestedVarCount --;
0 commit comments