88package org .seedstack .coffig .evaluator ;
99
1010import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
11- import java .util .Optional ;
12- import java .util .regex .Matcher ;
13- import java .util .regex .Pattern ;
1411import org .seedstack .coffig .TreeNode ;
1512import org .seedstack .coffig .node .ValueNode ;
1613import org .seedstack .coffig .spi .ConfigurationEvaluator ;
1714import org .slf4j .Logger ;
1815import org .slf4j .LoggerFactory ;
1916
17+ import java .util .Optional ;
18+ import java .util .regex .Matcher ;
19+ import java .util .regex .Pattern ;
20+
2021public class MacroEvaluator implements ConfigurationEvaluator {
2122 public static final String VALUE_QUOTE = "'" ;
2223 public static final String VALUE_SEPARATOR = ":" ;
@@ -34,8 +35,8 @@ public TreeNode evaluate(TreeNode rootNode, TreeNode valueNode) {
3435 try {
3536 return new ValueNode (processValue (rootNode , valueNode .value ()));
3637 } catch (Exception e ) {
37- LOGGER .error ("Error when evaluating configuration macro: {}" , valueNode .value (), e );
38- return new ValueNode ();
38+ LOGGER .debug ("Error when evaluating configuration macro: {}" , valueNode .value (), e );
39+ return new ValueNode (TreeNode . formatNodeError ( e ) );
3940 }
4041 } else {
4142 return valueNode ;
@@ -54,24 +55,24 @@ private String processValue(TreeNode rootNode, String value) {
5455 // Process all macros
5556 while ((matchingResult = findMatchingCurlyBraces (value , currentPos )) != null ) {
5657 // Add the beginning of the string (before the macro)
57- result .append (value . substring ( currentPos , matchingResult .startPos ) );
58+ result .append (value , currentPos , matchingResult .startPos );
5859
5960 if (matchingResult .escaped ) {
6061 // Add the macro as-is (without resolving it)
61- result .append (value . substring ( matchingResult .startPos + 1 , matchingResult .endPos + 1 ) );
62+ result .append (value , matchingResult .startPos + 1 , matchingResult .endPos + 1 );
6263 } else {
6364 // Process the macro
6465 boolean insideQuotes = false ;
6566 for (String part : value .substring (matchingResult .startPos + 2 , matchingResult .endPos )
6667 .split (VALUE_SEPARATOR )) {
6768 if (part .startsWith (VALUE_QUOTE ) && part .endsWith (VALUE_QUOTE )) {
68- result .append (part . substring ( 1 , part .length () - 1 ) );
69+ result .append (part , 1 , part .length () - 1 );
6970 break ;
7071 } else if (!insideQuotes && part .startsWith (VALUE_QUOTE )) {
7172 result .append (part .substring (1 ));
7273 insideQuotes = true ;
7374 } else if (insideQuotes && part .endsWith (VALUE_QUOTE )) {
74- result .append (VALUE_SEPARATOR ).append (part . substring ( 0 , part .length () - 1 ) );
75+ result .append (VALUE_SEPARATOR ).append (part , 0 , part .length () - 1 );
7576 insideQuotes = false ;
7677 } else if (insideQuotes ) {
7778 result .append (VALUE_SEPARATOR ).append (part );
0 commit comments