Beispiel #1
0
        private static ChainSegment[] GetPathChain(Substring segmentString)
        {
            var insideEscapeBlock  = false;
            var pathChainParts     = Substring.Split(segmentString, '.', StringSplitOptions.RemoveEmptyEntries);
            var extendedEnumerator = ExtendedEnumerator <Substring> .Create(pathChainParts);

            if (!extendedEnumerator.Any && segmentString == ".")
            {
                return new[] { ChainSegment.This }
            }
            ;

            var chainSegments = new List <ChainSegment>();

            while (extendedEnumerator.MoveNext())
            {
                var next = extendedEnumerator.Current.Value;

                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.ToArray());
        }
Beispiel #2
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.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);
        }