Commits

mpodonyi  committed 378d863

Refactored out Regex Generation to Template class

  • Participants
  • Parent commits 9920778

Comments (0)

Files changed (1)

File TemplateStrings/Template.cs

             }
         }
 
+        internal protected virtual string GetRegexString()
+        {
+            StringBuilder builder = new StringBuilder();
+
+            bool hasStartDelimiterEscape = !string.IsNullOrEmpty(StartDelimiterEscape);
+            bool hasStartDelimiter = !string.IsNullOrEmpty(StartDelimiter);
+
+            bool hasIdPattern = !string.IsNullOrEmpty(IdPattern);
+
+            bool hasEndDelimiterEscape = !string.IsNullOrEmpty(EndDelimiterEscape);
+            bool hasEndDelimiter = !string.IsNullOrEmpty(EndDelimiter);
+
+            if (hasStartDelimiterEscape && hasStartDelimiter)
+                builder.Append('(');
+
+            if (hasStartDelimiterEscape)
+            {
+                builder.AppendFormat("(?<escapedstart>{0})", Regex.Escape(StartDelimiterEscape));
+            }
+
+            if (hasStartDelimiter)
+            {
+                if (hasStartDelimiterEscape)
+                    builder.Append('|');
+
+                builder.AppendFormat("(?<start>{0})", Regex.Escape(StartDelimiter));
+            }
+
+            if (hasStartDelimiterEscape && hasStartDelimiter)
+                builder.Append(')');
+
+            if (hasIdPattern)
+                builder.AppendFormat("(?<named>{0})", IdPattern);
+
+            if (hasEndDelimiterEscape && hasEndDelimiter)
+                builder.Append('(');
+
+            if (hasEndDelimiterEscape)
+            {
+                builder.AppendFormat("(?<escapedend>{0})", Regex.Escape(EndDelimiterEscape));
+            }
+
+            if (hasEndDelimiter)
+            {
+                if (hasEndDelimiterEscape)
+                    builder.Append('|');
+
+                builder.AppendFormat("(?<end>{0})", Regex.Escape(EndDelimiter));
+            }
+
+            if (hasEndDelimiterEscape && hasEndDelimiter)
+                builder.Append(')');
+
+            return builder.ToString();
+        }
+
 
     }
 
 
                 builder.AppendFormat("(?<{0}>", i + 1);
 
-                bool hasStartDelimiterEscape=!string.IsNullOrEmpty(value.StartDelimiterEscape);
-                bool hasStartDelimiter=!string.IsNullOrEmpty(value.StartDelimiter);
-                
-                bool hasIdPattern= !string.IsNullOrEmpty(value.IdPattern);
-                
-                bool hasEndDelimiterEscape = !string.IsNullOrEmpty(value.EndDelimiterEscape);
-                bool hasEndDelimiter = !string.IsNullOrEmpty(value.EndDelimiter);
-
-                if (hasStartDelimiterEscape && hasStartDelimiter)
-                    builder.Append('(');
-
-                if (hasStartDelimiterEscape)
-                {
-                    builder.AppendFormat("(?<escapedstart>{0})", Regex.Escape(value.StartDelimiterEscape));
-                }
-
-                if (hasStartDelimiter)
-                {
-                    if (hasStartDelimiterEscape)
-                        builder.Append('|');
-
-                    builder.AppendFormat("(?<start>{0})", Regex.Escape(value.StartDelimiter));
-                }
-
-                if (hasStartDelimiterEscape && hasStartDelimiter)
-                    builder.Append(')');
-
-                if(hasIdPattern)
-                    builder.AppendFormat("(?<named>{0})", value.IdPattern);
-
-                if (hasEndDelimiterEscape && hasEndDelimiter)
-                    builder.Append('(');
-
-                if (hasEndDelimiterEscape)
-                {
-                    builder.AppendFormat("(?<escapedend>{0})", Regex.Escape(value.EndDelimiterEscape));
-                }
-
-                if (hasEndDelimiter)
-                {
-                    if (hasEndDelimiterEscape)
-                        builder.Append('|');
-
-                    builder.AppendFormat("(?<end>{0})", Regex.Escape(value.EndDelimiter));
-                }
-
-                if (hasEndDelimiterEscape && hasEndDelimiter)
-                    builder.Append(')');
+                builder.Append(value.GetRegexString());
 
                 builder.Append(")|");
             }