示例#1
0
        static protected bool ContainsPotentialTags(StringSlice inSlice, IDelimiterRules inDelimiters)
        {
            if (inDelimiters.RichText)
            {
                bool bIdenticalDelims = inDelimiters.TagStartDelimiter == "<" && inDelimiters.TagEndDelimiter == ">";
                if (inSlice.Contains("<") || inSlice.Contains(">"))
                {
                    return(true);
                }

                if (bIdenticalDelims)
                {
                    return(false);
                }
            }

            return(inSlice.Contains(inDelimiters.TagStartDelimiter) && inSlice.Contains(inDelimiters.TagEndDelimiter));
        }
示例#2
0
        static private string GetLocationFromTrace(string inTrace)
        {
            foreach (var line in StringSlice.EnumeratedSplit(inTrace, StringUtils.DefaultNewLineChars, StringSplitOptions.RemoveEmptyEntries))
            {
                int atIndex = line.IndexOf(" (at ");
                if (atIndex > 0)
                {
                    StringSlice method   = line.Substring(0, atIndex).Trim();
                    StringSlice location = line.Substring(atIndex + 5);
                    location = location.Substring(0, location.Length - 1).Trim();

                    // ignore locations with < or >, these are internal and not helpfuls
                    if (location.Contains('<') || location.Contains('>'))
                    {
                        continue;
                    }

                    int param = method.IndexOf('(');
                    if (param > 0)
                    {
                        method = method.Substring(0, param).Trim();
                    }

                    int lineNum = 0;
                    int colon   = location.IndexOf(':');
                    if (colon > 0)
                    {
                        StringSlice lineNumStr = location.Substring(colon + 1);
                        lineNum  = StringParser.ParseInt(lineNumStr);
                        location = location.Substring(0, colon).Trim();
                    }

                    int lastSlash = location.LastIndexOf('/');
                    if (lastSlash >= 0)
                    {
                        location = location.Substring(lastSlash + 1);
                    }
                    return(string.Format("{0} @{1}:{2}", method, lastSlash, lineNum));
                }
            }
            return(StackTraceDisabledMessage);
        }
示例#3
0
        // Attempts to add content to the current block
        static private bool TryAddContent(ref ParseState ioState, StringSlice inContent)
        {
            switch (ioState.CurrentState)
            {
            case BlockState.NotStarted:
            case BlockState.BlockDone:
            {
                BlockParser.LogError(ioState.Position, "Cannot add content '{0}', not currently in block", inContent);
                return(false);
            }

            case BlockState.BlockStarted:
            {
                ioState.Generator.CompleteHeader(ioState, ioState.Package, ioState.CurrentBlock, TagData.Empty);
                ioState.CurrentState = BlockState.InData;
                break;
            }

            case BlockState.InHeader:
            {
                if (ioState.Rules.RequireExplicitBlockHeaderEnd)
                {
                    BlockParser.LogError(ioState.Position, "Cannot add content '{0}', block header is not exited", inContent);
                    return(false);
                }

                ioState.Generator.CompleteHeader(ioState, ioState.Package, ioState.CurrentBlock, TagData.Empty);
                ioState.CurrentState = BlockState.InData;
                break;
            }

            case BlockState.InData:
                break;
            }

            bool bHandled = ioState.Generator.TryAddContent(ioState, ioState.Package, ioState.CurrentBlock, inContent);

            if (!bHandled)
            {
                BlockMetaCache.ContentInfo contentSetter;
                if (ioState.Cache.TryGetContent(ioState.CurrentBlock, out contentSetter))
                {
                    if (contentSetter.Mode == BlockContentMode.LineByLine)
                    {
                        StringSlice contentString = inContent;
                        if (contentString.Contains('\\'))
                        {
                            contentString = inContent.Unescape();
                        }

                        bHandled = contentSetter.Invoke(ioState.CurrentBlock, contentString, ioState.Cache.SharedResources);
                    }
                    else
                    {
                        if (ioState.ContentBuilder.Length == 0)
                        {
                            inContent = inContent.TrimStart(BlockParser.TrimCharsWithSpace);
                        }
                        else if (ioState.ContentBuilder.Length > 0 && contentSetter.LineSeparator != 0)
                        {
                            ioState.ContentBuilder.Append(contentSetter.LineSeparator);
                        }
                        ioState.ContentBuilder.AppendSlice(inContent);
                        bHandled = true;
                    }
                }
            }

            if (!bHandled)
            {
                BlockParser.LogError(ioState.Position, "Unable to add content");
            }

            return(bHandled);
        }