Example #1
0
        private static IReadOnlyList <ChainSegment> GetPathChain(Substring segmentString)
        {
            var insideEscapeBlock = false;
            var pathChainParts    = Substring.Split(segmentString, '.', StringSplitOptions.RemoveEmptyEntries);

            if (pathChainParts.Count == 0 && segmentString == ".")
            {
                return new[] { ChainSegment.Create("this") }
            }
            ;

            var chainSegments = new List <ChainSegment>();

            var count = pathChainParts.Count;

            for (int index = 0; index < count; index++)
            {
                var next = pathChainParts[index];
                if (insideEscapeBlock)
                {
                    if (next.EndsWith(']'))
                    {
                        insideEscapeBlock = false;
                    }

                    chainSegments[chainSegments.Count - 1] = ChainSegment.Create($"{chainSegments[chainSegments.Count - 1]}.{next.ToString()}");
                    continue;
                }

                if (next.StartsWith('['))
                {
                    insideEscapeBlock = true;
                }

                if (next.EndsWith(']'))
                {
                    insideEscapeBlock = false;
                }

                chainSegments.Add(ChainSegment.Create(next.ToString()));
            }

            return(chainSegments);
        }
Example #2
0
        private static IEnumerable <ChainSegment> GetPathChain(string segmentString)
        {
            var insideEscapeBlock = false;
            var pathChainParts    = segmentString.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            if (pathChainParts.Length == 0 && segmentString == ".")
            {
                return new[] { ChainSegment.Create("this") }
            }
            ;

            var pathChain = pathChainParts.Aggregate(new List <ChainSegment>(), (list, next) =>
            {
                if (insideEscapeBlock)
                {
                    if (next.EndsWith("]"))
                    {
                        insideEscapeBlock = false;
                    }

                    list[list.Count - 1] = ChainSegment.Create($"{list[list.Count - 1]}.{next}");
                    return(list);
                }

                if (next.StartsWith("["))
                {
                    insideEscapeBlock = true;
                }

                if (next.EndsWith("]"))
                {
                    insideEscapeBlock = false;
                }

                list.Add(ChainSegment.Create(next));
                return(list);
            });

            return(pathChain);
        }