Example #1
0
            private void BeginParseField(ref PatternFieldResolveContext ctx)
            {
                ctx.parameter = null;
                var vName = this.charValue;

                _fieldResolver = TryGetResolver(vName);
            }
Example #2
0
            private void EndParseField(ref PatternFieldResolveContext ctx)
            {
                var value = _fieldResolver(ctx);

                if (value != null)
                {
                    _messageBuilder.Append(value);
                }
                _fieldResolver = null;
            }
Example #3
0
            private bool ReadCharValueIfNotParsingField(ref PatternFieldResolveContext context)
            {
                var charValue = this.charValue;

                if (charValue == ESCAPE_CHAR)
                {
                    if (!MoveNext())
                    {
                        return(false);
                    }
                    this.BeginParseField(ref context);
                }
                else
                {
                    _messageBuilder.Append(charValue);
                }
                return(true);
            }
Example #4
0
            public string Format(string pattern, ULogger logger, LogType type, object message)
            {
                var messageStr = message == null? "":message.ToString();

                if (pattern == null)
                {
                    return(messageStr);
                }
                _index                 = -1;
                _pattern               = pattern;
                _messageBuilder        = new StringBuilder();
                _fieldParameterBuilder = null;
                _fieldResolver         = null;
                var context = new PatternFieldResolveContext()
                {
                    logger  = logger,
                    logType = type,
                    message = messageStr
                };

                while (true)
                {
                    if (!MoveNext())
                    {
                        break;
                    }
                    var charValue = this.charValue;
                    if (this.IsParsingField())
                    {
                        if (this.IsParsingFieldParameter())
                        {
                            if (charValue == PARAMETER_END_CHAR)
                            {
                                var p = this.EndParseFieldParameter();
                                context.parameter = p;
                            }
                            else
                            {
                                _fieldParameterBuilder.Append(charValue);
                            }
                        }
                        else
                        {
                            if (charValue == PARAMETER_BEGIN_CHAR)
                            {
                                BeginParseFieldParameter();
                            }
                            else
                            {
                                EndParseField(ref context);
                                if (!ReadCharValueIfNotParsingField(ref context))
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!ReadCharValueIfNotParsingField(ref context))
                        {
                            break;
                        }
                    }
                }
                if (IsParsingField())
                {
                    EndParseField(ref context);
                }
                return(_messageBuilder.ToString());
            }