public PathParser(string path) { Debug.Assert(path != null); this.path = path; length = path.Length; leftIndexInPath = 0; rightIndexInPath = 0; current = new ParsedPathComponent(); }
// Update parsing state and 'current' to next component in path. // Returns true if the was another component or false if the end of the path was reached. public bool MoveToNextComponent() { // See if we've the end of the path string. if (rightIndexInPath == length) { return(false); } // Make our current right index our new left index and find // a new right index from there. leftIndexInPath = rightIndexInPath; if (path[leftIndexInPath] == '/') { ++leftIndexInPath; rightIndexInPath = leftIndexInPath; if (leftIndexInPath == length) { return(false); } } // Parse <...> layout part, if present. var layout = new Substring(); if (rightIndexInPath < length && path[rightIndexInPath] == '<') { layout = ParseComponentPart('>'); } // Parse {...} usage part, if present. var usage = new Substring(); if (rightIndexInPath < length && path[rightIndexInPath] == '{') { usage = ParseComponentPart('}'); } // Parse name part, if present. var name = new Substring(); if (rightIndexInPath < length && path[rightIndexInPath] != '/') { name = ParseComponentPart('/'); } current = new ParsedPathComponent { layout = layout, usage = usage, name = name }; return(leftIndexInPath != rightIndexInPath); }
// Update parsing state and 'current' to next component in path. // Returns true if the was another component or false if the end of the path was reached. public bool MoveToNextComponent() { // See if we've the end of the path string. if (rightIndexInPath == length) { return(false); } // Make our current right index our new left index and find // a new right index from there. leftIndexInPath = rightIndexInPath; if (path[leftIndexInPath] == '/') { ++leftIndexInPath; rightIndexInPath = leftIndexInPath; if (leftIndexInPath == length) { return(false); } } // Parse <...> layout part, if present. var layout = new Substring(); if (rightIndexInPath < length && path[rightIndexInPath] == '<') { layout = ParseComponentPart('>'); } // Parse {...} usage part, if present. var usages = new List <Substring>(); while (rightIndexInPath < length && path[rightIndexInPath] == '{') { usages.Add(ParseComponentPart('}')); } // Parse display name part, if present. var displayName = new Substring(); if (rightIndexInPath < length - 1 && path[rightIndexInPath] == '#' && path[rightIndexInPath + 1] == '(') { ++rightIndexInPath; displayName = ParseComponentPart(')'); } // Parse name part, if present. var name = new Substring(); if (rightIndexInPath < length && path[rightIndexInPath] != '/') { name = ParseComponentPart('/'); } current = new ParsedPathComponent { layout = layout, usages = usages.ToArray(), name = name, displayName = displayName }; return(leftIndexInPath != rightIndexInPath); }