@@ -17,8 +17,7 @@ internal static class EngineAlgorithim
1717
1818 private static readonly Regex IfConditionRegex = new Regex ( @"{{\s*#if\s*\(\s*(?<param>\w+)\s*(?<operator>==|!=|>=|<=|>|<)\s*(?<value>[^)]+)\s*\)\s*}}(?<code>[\s\S]*?)(?:{{\s*#else\s*}}(?<else>[\s\S]*?))?{{\s*#endif\s*}}" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
1919
20- private static readonly Regex LoopBlockRegex = new Regex ( @"{{\s*#foreach\s*\(\s*(\w+)\s*\)\s*\}\}([\s\S]*?)\{\{\s*#endforeach\s*}}" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
21-
20+ private static readonly Regex LoopBlockRegex = new Regex ( @"{{\s*#\s*foreach\s*\(\s*(\w+)\s*\)\s*\}\}([\s\S]*?)\{\{\s*#\s*endforeach\s*}}" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
2221 private static readonly Regex DirectParamRegex = new Regex ( @"{{(.+?)}}" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
2322
2423 public static string GenerateFromTemplate < T > ( T record , EngineRunnerTemplate template , Dictionary < string , object > parameterKeyValues = null , TemplateMapperOptions options = null ) where T : new ( )
@@ -33,7 +32,7 @@ internal static class EngineAlgorithim
3332 {
3433 if ( ! propMap . TryGetValue ( ifCondition . IfPropertyName , out ExtractedObjProperty property ) )
3534 {
36- result . Replace ( ifCondition . ReplaceRef , "[IF-CONDITION EXCEPTION]: unrecognized property: [" + ifCondition . IfPropertyName + "]" ) ;
35+ result . ReplaceFirstOccurrence ( ifCondition . ReplaceRef , "[IF-CONDITION EXCEPTION]: unrecognized property: [" + ifCondition . IfPropertyName + "]" ) ;
3736 continue ;
3837 }
3938
@@ -55,15 +54,15 @@ internal static class EngineAlgorithim
5554 replacement = string . Empty ;
5655 }
5756
58- result . Replace ( ifCondition . ReplaceRef , replacement ) ;
57+ result . ReplaceFirstOccurrence ( ifCondition . ReplaceRef , replacement ) ;
5958 }
6059
6160 // ---- Object Loops ----
6261 foreach ( ReplaceObjLoopCode objLoop in template . ReplaceObjLoopCodes )
6362 {
6463 if ( ! propMap . TryGetValue ( objLoop . TargetObjectName , out ExtractedObjProperty targetObj ) || ! ( targetObj . OriginalValue is IEnumerable enumerable ) )
6564 {
66- result . Replace ( objLoop . ReplaceRef , string . Empty ) ;
65+ result . ReplaceFirstOccurrence ( objLoop . ReplaceRef , string . Empty ) ;
6766 continue ;
6867 }
6968
@@ -87,30 +86,30 @@ internal static class EngineAlgorithim
8786 Type = row . GetType ( ) ,
8887 OriginalValue = row
8988 } ;
90- activeRow . Replace ( objLoopCode . ReplaceRef , tempProp . GetPropertyDisplayString ( objLoopCode . GetFormattingCommand ( ) , options ) ) ;
89+ activeRow . ReplaceFirstOccurrence ( objLoopCode . ReplaceRef , tempProp . GetPropertyDisplayString ( objLoopCode . GetFormattingCommand ( ) , options ) ) ;
9190 }
9291 else
9392 {
9493 if ( rowMap . TryGetValue ( propName , out ExtractedObjProperty p ) )
95- activeRow . Replace ( objLoopCode . ReplaceRef , p . GetPropertyDisplayString ( objLoopCode . GetFormattingCommand ( ) , options ) ) ;
94+ activeRow . ReplaceFirstOccurrence ( objLoopCode . ReplaceRef , p . GetPropertyDisplayString ( objLoopCode . GetFormattingCommand ( ) , options ) ) ;
9695 else
97- activeRow . Replace ( objLoopCode . ReplaceRef , objLoopCode . ReplaceCommand ) ;
96+ activeRow . ReplaceFirstOccurrence ( objLoopCode . ReplaceRef , objLoopCode . ReplaceCommand ) ;
9897 }
9998 }
10099
101100 loopResult . Append ( activeRow ) ;
102101 }
103102
104- result . Replace ( objLoop . ReplaceRef , loopResult . ToString ( ) ) ;
103+ result . ReplaceFirstOccurrence ( objLoop . ReplaceRef , loopResult . ToString ( ) ) ;
105104 }
106105
107106 // ---- Direct Replacements ----
108107 foreach ( ReplaceCode replaceCode in template . ReplaceCodes )
109108 {
110109 if ( propMap . TryGetValue ( replaceCode . GetTargetPropertyName ( ) , out ExtractedObjProperty property ) )
111- result . Replace ( replaceCode . ReplaceRef , property . GetPropertyDisplayString ( replaceCode . GetFormattingCommand ( ) , options ) ) ;
110+ result . ReplaceFirstOccurrence ( replaceCode . ReplaceRef , property . GetPropertyDisplayString ( replaceCode . GetFormattingCommand ( ) , options ) ) ;
112111 else
113- result . Replace ( replaceCode . ReplaceRef , "{{ " + replaceCode . ReplaceCommand + " }}" ) ;
112+ result . ReplaceFirstOccurrence ( replaceCode . ReplaceRef , "{{ " + replaceCode . ReplaceCommand + " }}" ) ;
114113 }
115114 return result . ToString ( ) ;
116115 }
0 commit comments