public static PathInfo Parse(string path) { if (path == "null") { return(Empty); } var originalPath = path; var pathType = GetPathType(path); var pathSubstring = new Substring(path); var isValidHelperLiteral = true; var isVariable = pathType == PathType.Variable; var isInversion = pathType == PathType.Inversion; var isBlockHelper = pathType == PathType.BlockHelper; if (isVariable || isBlockHelper || isInversion) { isValidHelperLiteral = isBlockHelper || isInversion; pathSubstring = new Substring(pathSubstring, 1); } var segments = new List <PathSegment>(); var pathParts = Substring.Split(pathSubstring, '/'); var extendedEnumerator = ExtendedEnumerator <Substring> .Create(pathParts); using var container = StringBuilderPool.Shared.Use(); var buffer = container.Value; while (extendedEnumerator.MoveNext()) { var segment = extendedEnumerator.Current.Value; if (buffer.Length != 0) { buffer.Append('/'); buffer.Append(in segment); if (Substring.LastIndexOf(segment, ']', out var index) && !Substring.LastIndexOf(segment, '[', index, out _)) { var chainSegment = GetPathChain(buffer.ToString()); if (chainSegment.Length > 1) { isValidHelperLiteral = false; } segments.Add(new PathSegment(segment, chainSegment)); buffer.Length = 0; continue; } } if (Substring.LastIndexOf(segment, '[', out var startIndex) && !Substring.LastIndexOf(segment, ']', startIndex, out _)) { buffer.Append(in segment); continue; } switch (segment.Length) { case 2 when segment[0] == '.' && segment[1] == '.':
public void LastIndexOf(string input, char trimChar, int expected) { var actual = Substring.LastIndexOf(input, trimChar); Assert.Equal(expected, actual); }