Anonymous avatar Anonymous committed b3e9af6

further optimizations and fixes

Comments (0)

Files changed (2)

TemplateStrings/TemplateString.cs

 		
 		private Regex GeneratedRegex=null;
 		
-		private bool CompileRegex=false;
+		private readonly bool CompileRegex=false;
 
         protected abstract IList<TemplateValue> TemplateValues { get; }
 
+        private IList<TemplateValue> __TemplateValues;
+        private IList<TemplateValue> _TemplateValues
+        {
+            get
+            {
+                if (__TemplateValues == null)
+                    __TemplateValues = TemplateValues;
+                return __TemplateValues;
+            }
+        }
+
         public string Template { get; private set; }
 
         private void Validate()
         {
-            foreach (TemplateValue val in TemplateValues)
+            foreach (TemplateValue val in _TemplateValues)
             {
                 if (!string.IsNullOrEmpty(val.StartDelimiterEscape) && string.IsNullOrEmpty(val.StartDelimiter))
                     throw new ArgumentException(
 				
             var builder = new StringBuilder(200);
 
-            for (int i = 0; i < TemplateValues.Count; i++)
+            for (int i = 0; i < _TemplateValues.Count; i++)
             {
-                TemplateValue value = TemplateValues[i];
-
                 builder.AppendFormat("(?<{0}>", i + 1);
 
-                builder.Append(value.GetRegexString());
+                builder.Append(_TemplateValues[i].GetRegexString());
 
                 builder.Append(")|");
             }
 			RegexOptions regexOptions = RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant;
 			
 			if(CompileRegex)
-				regexOptions | =RegexOptions.Compiled ;
+				regexOptions |=RegexOptions.Compiled ;
 
             return GeneratedRegex = new Regex(builder.ToString(),regexOptions);
         }
                                                {
                                                    TemplateValue templateValue = null;
 
-                                                   for (int i = 0; i < TemplateValues.Count; i++)
+                                                   for (int i = 0; i < _TemplateValues.Count; i++)
                                                    {
                                                        if (match.Groups[(i + 1).ToString()].Success)
                                                        {
-                                                           templateValue = TemplateValues[i];
+                                                           templateValue = _TemplateValues[i];
                                                            break;
                                                        }
                                                    }
     public class PythonsTemplateString : TemplateString
     {
         public PythonsTemplateString(string template)
-            : base(template)
+            : this(template,false)
         {
         }
 
+        public PythonsTemplateString(string template, bool compileRegex):base(template,compileRegex)
+        {}
+
         protected override IList<TemplateValue> TemplateValues
         {
             get
     public class MvcTemplateString : TemplateString
     {
         public MvcTemplateString(string template)
-            : base(template)
+            : this(template,false)
         {
         }
 
+        public MvcTemplateString(string template, bool compileRegex):base(template,compileRegex)
+        {}
+
         protected override IList<TemplateValue> TemplateValues
         {
             get

TemplateStringsTest/TemplateTest.cs

                                    {
                                        EndDelimiter = "$",
                                        IdPattern = "[_a-z][_a-z0-9]*",
-                                       EndDelimiterEscape = "$$"
+                                       EndDelimiterEscape = "$"
                                    },
                                new TemplateValue
                                    {
                                        EndDelimiter = "}$",
                                        IdPattern = "[_a-z][_a-z0-9]*",
-                                       EndDelimiterEscape = "}$$",
+                                       EndDelimiterEscape = "$",
                                        StartDelimiter = "{"
                                    }
                            };
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.