分析模板的一段简单快速的算法片段

char[] templateText = txt.ToCharArray();
            
//ITemplate it = new CleanTemplate();

            List
<Tag> tags = new List<Tag>();
            
char[] temp = new char[100];

            
for (int i = 0; i < templateText.Length; i++)
            {
                
if (templateText[i] == '{')
                {
                    
if (i > 0 && templateText[i - 1== '\\')
                        
continue;

                    Tag tag 
= new Tag();
                    tag.StartIndex 
= i;
                    context.Response.Write(templateText[i]);

                    
while (++< templateText.Length && templateText[i] != '}')
                    {
                        
if (templateText[i] == ' ')
                        {
                            
if (isFirstSpace)
                            {
                                isFirstSpace 
= false;
                                context.Response.Write(
" ");
                            }
                            
continue;
                        }
                        context.Response.Write(templateText[i]);
                    }
                    tag.EndIndex 
= i;
                    context.Response.Write(templateText[i]);
                    context.Response.Write(
"<br />");
                }

                isFirstSpace 
= true;
            }

原文地址:https://www.cnblogs.com/afxcn/p/763225.html