Example #1
0
 private void EndSyntaxInfo(CustomUploaderSyntaxInfo syntaxInfo, int position, string syntax)
 {
     if (syntaxInfo != null)
     {
         syntaxInfo.EndPosition = position;
         syntaxInfo.Text        = syntax;
         SyntaxInfoList.Add(syntaxInfo);
     }
 }
Example #2
0
        public string Parse(string text, bool isOutput)
        {
            if (string.IsNullOrEmpty(text))
            {
                return("");
            }

            StringBuilder sbResult      = new StringBuilder();
            StringBuilder sbSyntax      = new StringBuilder();
            bool          escapeNext    = false;
            bool          parsingSyntax = false;

            SyntaxInfoList = new List <CustomUploaderSyntaxInfo>();
            CustomUploaderSyntaxInfo syntaxInfo = null;

            for (int i = 0; i < text.Length; i++)
            {
                if (!escapeNext && text[i] == SyntaxChar)
                {
                    if (!parsingSyntax)
                    {
                        parsingSyntax = true;
                        sbSyntax.Clear();
                        syntaxInfo = new CustomUploaderSyntaxInfo()
                        {
                            StartPosition = i
                        };
                    }
                    else
                    {
                        parsingSyntax = false;
                        string syntax = sbSyntax.ToString();
                        EndSyntaxInfo(syntaxInfo, i, syntax);

                        if (!SkipSyntaxParse && !string.IsNullOrEmpty(syntax))
                        {
                            string syntaxResult = ParseSyntax(syntax, isOutput);

                            if (!string.IsNullOrEmpty(syntaxResult))
                            {
                                sbResult.Append(syntaxResult);
                            }
                        }
                    }
                }
                else if (!escapeNext && text[i] == SyntaxEscapeChar)
                {
                    escapeNext = true;
                }
                else
                {
                    escapeNext = false;

                    if (!parsingSyntax)
                    {
                        sbResult.Append(text[i]);
                    }
                    else
                    {
                        sbSyntax.Append(text[i]);
                    }
                }
            }

            if (parsingSyntax)
            {
                string syntax = sbSyntax.ToString();
                EndSyntaxInfo(syntaxInfo, text.Length - 1, syntax);
            }

            return(sbResult.ToString());
        }
Example #3
0
        private string Parse(string text, bool isOutput)
        {
            if (string.IsNullOrEmpty(text))
            {
                return("");
            }

            if (UseNameParser)
            {
                NameParser   nameParser   = new NameParser(NameParserType);
                EscapeHelper escapeHelper = new EscapeHelper();
                escapeHelper.KeepEscapeCharacter = true;
                text = escapeHelper.Parse(text, nameParser.Parse);
            }

            StringBuilder sbResult      = new StringBuilder();
            StringBuilder sbSyntax      = new StringBuilder();
            bool          escapeNext    = false;
            bool          parsingSyntax = false;

            SyntaxInfoList = new List <CustomUploaderSyntaxInfo>();
            CustomUploaderSyntaxInfo syntaxInfo = null;

            for (int i = 0; i < text.Length; i++)
            {
                if (!escapeNext && text[i] == SyntaxChar)
                {
                    if (!parsingSyntax)
                    {
                        parsingSyntax = true;
                        sbSyntax.Clear();
                        syntaxInfo = new CustomUploaderSyntaxInfo()
                        {
                            StartPosition = i
                        };
                    }
                    else
                    {
                        parsingSyntax = false;
                        string syntax = sbSyntax.ToString();
                        EndSyntaxInfo(syntaxInfo, i, syntax);

                        if (!SkipSyntaxParse && !string.IsNullOrEmpty(syntax))
                        {
                            string syntaxResult = ParseSyntax(syntax, isOutput);

                            if (!string.IsNullOrEmpty(syntaxResult))
                            {
                                if (JSONEncode)
                                {
                                    syntaxResult = URLHelpers.JSONEncode(syntaxResult);
                                }
                                else if (XMLEncode)
                                {
                                    syntaxResult = URLHelpers.XMLEncode(syntaxResult);
                                }

                                sbResult.Append(syntaxResult);
                            }
                        }
                    }
                }
                else if (!escapeNext && text[i] == SyntaxEscapeChar)
                {
                    escapeNext = true;
                }
                else
                {
                    escapeNext = false;

                    if (!parsingSyntax)
                    {
                        sbResult.Append(text[i]);
                    }
                    else
                    {
                        sbSyntax.Append(text[i]);
                    }
                }
            }

            if (parsingSyntax)
            {
                string syntax = sbSyntax.ToString();
                EndSyntaxInfo(syntaxInfo, text.Length - 1, syntax);
            }

            return(sbResult.ToString());
        }