public void getting_path_type(string path, string parsedPart, PathComponentType componentType, string[] prefixes) { var pathType = new PathManager().GetPathType(prefixes, path); pathType.Type.ShouldBe(componentType); pathType.ParsedValue.ShouldBe(parsedPart); }
public void getting_path_type(string path, string parsedPart, PathComponentType componentType, string[] prefixes) { var pathType = new PathManager().GetPathType(prefixes, path); pathType.Type.ShouldBe(componentType); pathType.ParsedValue.ShouldBe(parsedPart); }
public void reading_path_components(string value, string parsedPart, PathComponentType type, string parsedPartTwo,PathComponentType result2) { var components = new PathManager().ReadComponents(value).ToList(); var parseResult1 = components.Count > 0 ? components[0] : new PathComponent(); var parseResult2 = components.Count > 1 ? components[1] : new PathComponent(); parseResult1.ParsedValue.ShouldBe(parsedPart); parseResult1.Type.ShouldBe(type); parseResult2.ParsedValue.ShouldBe(parsedPartTwo); parseResult2.Type.ShouldBe(result2); }
public void reading_path_components(string value, string parsedPart, PathComponentType type, string parsedPartTwo, PathComponentType result2) { var components = new PathManager().ReadComponents(value).ToList(); var parseResult1 = components.Count > 0 ? components[0] : new PathComponent(); var parseResult2 = components.Count > 1 ? components[1] : new PathComponent(); parseResult1.ParsedValue.ShouldBe(parsedPart); parseResult1.Type.ShouldBe(type); parseResult2.ParsedValue.ShouldBe(parsedPartTwo); parseResult2.Type.ShouldBe(result2); }
private static bool MatchPathComponent(string component, string path, ref int indexInPath, PathComponentType componentType, int startIndexInComponent = 0) { Debug.Assert(component != null, "Component string is null"); Debug.Assert(path != null, "Path is null"); var componentLength = component.Length; var pathLength = path.Length; var startIndex = indexInPath; // Try to walk the name as far as we can. var indexInComponent = startIndexInComponent; while (indexInPath < pathLength) { // Check if we've reached a terminator in the path. var nextCharInPath = path[indexInPath]; if (nextCharInPath == '\\' && indexInPath + 1 < pathLength) { // Escaped character. Bypass treatment of special characters below. ++indexInPath; nextCharInPath = path[indexInPath]; } else { if (nextCharInPath == '/') { break; } if ((nextCharInPath == '>' && componentType == PathComponentType.Layout) || (nextCharInPath == '}' && componentType == PathComponentType.Usage) || (nextCharInPath == ')' && componentType == PathComponentType.DisplayName)) { ++indexInPath; break; } ////TODO: allow only single '*' and recognize '**' // If we've reached a '*' in the path, skip character in name. if (nextCharInPath == '*') { // But first let's see if we have something after the wildcard that matches the rest of the component. // This could be when, for example, we hit "T" on matching "leftTrigger" against "*Trigger". We have to stop // gobbling up characters for the wildcard when reaching "Trigger" in the component name. // // NOTE: Just looking at the very next character only is *NOT* enough. We need to match the entire rest of // the path. Otherwise, in the example above, we would stop on seeing the lowercase 't' and then be left // trying to match "tTrigger" against "Trigger". var indexAfterWildcard = indexInPath + 1; if (indexInPath < (pathLength - 1) && indexInComponent < componentLength && MatchPathComponent(component, path, ref indexAfterWildcard, componentType, indexInComponent)) { indexInPath = indexAfterWildcard; return(true); } if (indexInComponent < componentLength) { ++indexInComponent; } else { return(true); } continue; } } // If we've reached the end of the component name, we did so before // we've reached a terminator if (indexInComponent == componentLength) { indexInPath = startIndex; return(false); } if (char.ToLower(component[indexInComponent]) == char.ToLower(nextCharInPath)) { ++indexInComponent; ++indexInPath; } else { // Name isn't a match. indexInPath = startIndex; return(false); } } if (indexInComponent == componentLength) { return(true); } indexInPath = startIndex; return(false); }
private static bool MatchPathComponent(string component, string path, ref int indexInPath, PathComponentType componentType) { Debug.Assert(!string.IsNullOrEmpty(component)); Debug.Assert(!string.IsNullOrEmpty(path)); var nameLength = component.Length; var pathLength = path.Length; var startIndex = indexInPath; // Try to walk the name as far as we can. var indexInName = 0; while (indexInPath < pathLength) { // Check if we've reached a terminator in the path. var nextCharInPath = path[indexInPath]; if (nextCharInPath == '/') { break; } if ((nextCharInPath == '>' && componentType == PathComponentType.Layout) || (nextCharInPath == '}' && componentType == PathComponentType.Usage)) { ++indexInPath; break; } ////TODO: allow only single '*' and recognize '**' // If we've reached a '*' in the path, skip character in name. if (nextCharInPath == '*') { // But first let's see if the following character is a match. if (indexInPath < (pathLength - 1) && indexInName < nameLength && char.ToLower(path[indexInPath + 1]) == char.ToLower(component[indexInName])) { ++indexInName; indexInPath += 2; // Match '*' and following character. } else if (indexInName < nameLength) { ++indexInName; } else { return(true); } continue; } // If we've reached the end of the component name, we did so before // we've reached a terminator if (indexInName == nameLength) { indexInPath = startIndex; return(false); } if (char.ToLower(component[indexInName]) == char.ToLower(nextCharInPath)) { ++indexInName; ++indexInPath; } else { // Name isn't a match. indexInPath = startIndex; return(false); } } if (indexInName == nameLength) { return(true); } indexInPath = startIndex; return(false); }