コード例 #1
0
		public TextExpression(string schema, string text, string format, TextExpressionArgument[] args)
		{
			_schema = string.IsNullOrWhiteSpace(schema) ? string.Empty : schema.Trim();
			_text = string.IsNullOrWhiteSpace(text) ? string.Empty : text.Trim();
			_format = string.IsNullOrWhiteSpace(format) ? string.Empty : format.Trim();
			_arguments = args ?? new TextExpressionArgument[0];
		}
コード例 #2
0
		public static TextExpressionNodeCollection Parse(string text)
		{
			if(string.IsNullOrEmpty(text))
				return TextExpressionNodeCollection.Empty;

			var index = 0;
			var nodes = new TextExpressionNodeCollection();

			//使用正则表达式解析指定的文本内容
			var matches = _regex.Matches(text);

			foreach(Match match in matches)
			{
				if(match.Index > index)
				{
					var length = match.Index - index;
					nodes.Add(new TextExpressionNode(index, length, text.Substring(index, length)));
				}

				TextExpressionArgument[] args = null;
				Group argsGroup = match.Groups["args"];

				if(argsGroup.Success)
				{
					if(argsGroup.Captures.Count == 0)
						args = new TextExpressionArgument[] { ParseArgument(argsGroup.Value) };
					else
					{
						args = new TextExpressionArgument[argsGroup.Captures.Count];

						for(int i = 0; i < argsGroup.Captures.Count; i++)
						{
							args[i] = ParseArgument(argsGroup.Captures[i].Value);
						}
					}
				}

				nodes.Add(new TextExpressionNode(match.Index,
												 match.Length,
												 match.Value,
												 new TextExpression(
													 match.Groups["name"].Value,
													 match.Groups["text"].Value,
													 match.Groups["format"].Value,
													 args)));

				index = match.Index + match.Length;
			}

			if(index < text.Length)
			{
				nodes.Add(new TextExpressionNode(index, text.Length - index, text.Substring(index, text.Length - index)));
			}

			return nodes;
		}
コード例 #3
0
		public TextExpression(string name, string text, string format, TextExpressionArgument[] args)
		{
			_name = string.IsNullOrWhiteSpace(name) ? string.Empty : name.Trim();
			_text = string.IsNullOrWhiteSpace(text) ? string.Empty : text.Trim();
			_format = string.IsNullOrWhiteSpace(format) ? string.Empty : format.Trim();
			_arguments = args ?? new TextExpressionArgument[0];
		}
コード例 #4
0
        public static TextExpressionNodeCollection Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(TextExpressionNodeCollection.Empty);
            }

            var index = 0;
            var nodes = new TextExpressionNodeCollection();

            //使用正则表达式解析指定的文本内容
            var matches = _regex.Matches(text);

            foreach (Match match in matches)
            {
                if (match.Index > index)
                {
                    var length = match.Index - index;
                    nodes.Add(new TextExpressionNode(index, length, text.Substring(index, length)));
                }

                TextExpressionArgument[] args = null;
                Group argsGroup = match.Groups["args"];

                if (argsGroup.Success)
                {
                    if (argsGroup.Captures.Count == 0)
                    {
                        args = new TextExpressionArgument[] { ParseArgument(argsGroup.Value) }
                    }
                    ;
                    else
                    {
                        args = new TextExpressionArgument[argsGroup.Captures.Count];

                        for (int i = 0; i < argsGroup.Captures.Count; i++)
                        {
                            args[i] = ParseArgument(argsGroup.Captures[i].Value);
                        }
                    }
                }

                nodes.Add(new TextExpressionNode(match.Index,
                                                 match.Length,
                                                 match.Value,
                                                 new TextExpression(
                                                     match.Groups["name"].Value,
                                                     match.Groups["text"].Value,
                                                     match.Groups["format"].Value,
                                                     args)));

                index = match.Index + match.Length;
            }

            if (index < text.Length)
            {
                nodes.Add(new TextExpressionNode(index, text.Length - index, text.Substring(index, text.Length - index)));
            }

            return(nodes);
        }