public string GetFormatterName(TokenzierContext context, int index, out bool found, out Func <IMorestachioError> errProducer) { var last = CompileCurrent(context, index, out errProducer); if (last == null) { if (CurrentPart == string.Empty) { last = new KeyValuePair <string, PathType>(string.Empty, PathType.DataPath); } else { found = false; return(null); } } found = true; if (last.Value.Value != PathType.DataPath) { PathParts.Add(last.Value.Key, last.Value.Value); return(string.Empty); } return(last.Value.Key); }
public KeyValuePair <string, PathType>?CompileCurrent(TokenzierContext context, int index, out Func <IMorestachioError> errProducer) { if (CurrentPart == ".") { PathParts.Add(null, PathType.SelfAssignment); } else if (CurrentPart == "../") { PathParts.Add(null, PathType.ParentSelector); } else if (CurrentPart == "~") { PathParts.Add(null, PathType.RootSelector); } else if (CurrentPart == "?") { PathParts.Add(null, PathType.ObjectSelector); } else if (CurrentPart.Trim() != string.Empty) { if (!ComputeCurrentPart(context, index, out errProducer)) { errProducer = () => ( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "Invalid character")); return(default);
private bool ComputeCurrentPart(TokenzierContext context, int index) { var checkPathPart = CheckPathPart(); if (checkPathPart != -1) { context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, checkPathPart, CurrentPart)), CurrentPart)); return(false); } if (CurrentPart == "null") { if (PathParts.Any()) { context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An null must be at the start of an expression")); return(false); } PathParts.Add(new KeyValuePair <string, PathType>(null, PathType.Null)); } else if (CurrentPart == "true" || CurrentPart == "false") { if (PathParts.Any()) { context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An boolean must be at the start of an expression")); return(false); } PathParts.Add(new KeyValuePair <string, PathType>(CurrentPart, PathType.Boolean)); } else { PathParts.Add(new KeyValuePair <string, PathType>(CurrentPart, PathType.DataPath)); } return(true); }
public IList <KeyValuePair <string, PathType> > CompileListWithCurrent(TokenzierContext context, int index, out Func <IMorestachioError> errProducer) { var last = CompileCurrent(context, index, out errProducer); if (last == null) { return(PathParts.GetList()); } if (!(PathParts.Many && last.Value.Value == PathType.SelfAssignment)) { PathParts.Add(last.Value.Key, last.Value.Value); } return(PathParts.GetList()); }
public IList <KeyValuePair <string, PathType> > Compile(TokenzierContext context, int index) { if (CurrentPart == ".") { PathParts.Add(new KeyValuePair <string, PathType>(null, PathType.SelfAssignment)); } else if (CurrentPart == "../") { PathParts.Add(new KeyValuePair <string, PathType>(null, PathType.ParentSelector)); } else if (CurrentPart == "~") { PathParts.Add(new KeyValuePair <string, PathType>(null, PathType.RootSelector)); } else if (CurrentPart == "?") { PathParts.Add(new KeyValuePair <string, PathType>(null, PathType.ObjectSelector)); } else if (CurrentPart.Trim() != "") { if (CurrentPartIsNumber) { PathParts.Add(new KeyValuePair <string, PathType>(CurrentPart, PathType.Number)); } else { if (!ComputeCurrentPart(context, index)) { return(new KeyValuePair <string, PathType> [0]); } } } if (PathParts.Count > 1 && PathParts.Last().Value == PathType.SelfAssignment) { PathParts.Remove(PathParts.Last()); } //if (!PathParts.Any()) //{ // hasError = 0; // return PathParts; //} CurrentPart = ""; return(PathParts); }
private void UpdatePath() { PathParts.Clear(); foreach (var student in Path) { PathParts.Add(new PathPart() { Text = student.Name, Color = student.TextColor }); if (student != Path.Last()) { PathParts.Add(new PathPart() { Text = " | ", Color = Colors.Black }); } } }
/// <summary> /// Breaks down the URL used to request the information into chunks that the event handlers can use to decide what to serve. /// </summary> /// <param name="request"></param> /// <remarks><para> /// .NET unescapes percent-escaped characters before it picks out query strings etc. Virtual Radar WebServer uses the URL to /// carry character strings, in particular they could contain encoded reserved characters such as ?, / and =. If you try /// to decode those strings with .NET the escaped reserved characters cause problems, although RFC1738 does say: /// </para><para> /// "On the other hand, characters that are not required to be encoded (including alphanumerics) may be encoded within /// the scheme-specific part of a URL, as long as they are not being used for a reserved purpose". /// </para><para> /// This would imply that .NET's default behaviour is wrong. It should break the URL down using the unescaped string and then /// unescape each part of the string. "As long as they are not being used for a reserved purpose" implies that reserved characters /// should be treated as normal characters and not for their reserved purpose if they have been escaped. In particular a URL such /// as 'http://127.0.0.1/MyRoot/Folder%3FName%3DValue/Hello.txt' should be interpreted as a path of '/MyRoot/Folder?Name=Value' /// and no query strings - the default .NET behaviour is to resolve that as a path of '/MyRoot/Folder' and a name-value of /// Name = Value. /// </para></remarks> private void DecomposeRequestUrl(IRequest request) { WebSite = ""; PathAndFile = ""; Path = ""; if (!String.IsNullOrEmpty(request.RawUrl) && request.RawUrl.StartsWith(Root, StringComparison.OrdinalIgnoreCase)) { WebSite = String.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Authority, Root); var rawUrl = request.RawUrl.Substring(Root.Length); var querySplitPosn = rawUrl.IndexOf('?'); var path = querySplitPosn == -1 ? rawUrl : rawUrl.Substring(0, querySplitPosn); var query = querySplitPosn == -1 ? "" : rawUrl.Substring(querySplitPosn + 1); PathAndFile = HttpUtility.UrlDecode(path); if (PathAndFile.Length == 0) { PathAndFile = "/"; } var pathBuffer = new StringBuilder(); var pathParts = path.Split('/'); for (var i = 0; i < pathParts.Length; ++i) { var chunk = HttpUtility.UrlDecode(pathParts[i]); if (i + 1 == pathParts.Length) { File = chunk; } else if (chunk.Length > 0) { PathParts.Add(chunk); pathBuffer.Append('/'); pathBuffer.Append(chunk); } } Path = pathBuffer.Length == 0 ? "/" : pathBuffer.ToString(); QueryString = HttpUtility.ParseQueryString(query); } }
public bool Add(char c, TokenzierContext context, int index) { if (!Tokenizer.IsExpressionChar(c)) { context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart)); return(false); } if (PathParts.Any(f => f.Value == PathType.Null)) { context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "Nothing can follow on a null")); } LastCharWasDelimiter = c == '.'; if (c == '/') { if (CurrentPart == "..") { if (PathParts.Any() && PathParts.Any(e => e.Value != PathType.ParentSelector)) { context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An Parent selector '..\\' can only follow on another parent selector like and never on an root or an data selector")); return(false); } PathParts.Add(new KeyValuePair <string, PathType>(null, PathType.ParentSelector)); CurrentPart = ""; return(true); } context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "Unexpected '/'. Expected ether the start of an expression or an './'")); return(false); } if (c == '~') { if (CurrentPart != string.Empty || PathParts.Any()) { context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An root selector '~' must be at the start of an expression")); return(false); } PathParts.Add(new KeyValuePair <string, PathType>(null, PathType.RootSelector)); CurrentPart = ""; return(true); } if (c == '?') { PathParts.Add(new KeyValuePair <string, PathType>(null, PathType.ObjectSelector)); CurrentPart = ""; return(true); } if (c != '.' && CurrentPart == "." && PathParts.Count == 0) { //in this case somebody wrote .data //so ignore the dot CurrentPart = ""; } if (CurrentPart != "" && CurrentPart != "." && c == '.') { if (CurrentPartIsNumber) { if (CurrentPart.Contains(".")) { PathParts.Add(new KeyValuePair <string, PathType>(CurrentPart, PathType.Number)); CurrentPart = ""; } else { CurrentPart += c; } return(true); } if (!ComputeCurrentPart(context, index)) { return(false); } CurrentPart = ""; } else { if (CurrentPart == string.Empty && char.IsDigit(c)) { CurrentPartIsNumber = true; if (PathParts.Any()) { context.Errors.Add( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "A number expression must be at the start of the expression and cannot follow on anything else")); return(false); } } CurrentPart += c; } return(true); }
private bool ComputeCurrentPart(TokenzierContext context, int index, out Func <IMorestachioError> errProducer) { errProducer = null; var checkPathPart = CheckPathPart(); if (checkPathPart != -1) { errProducer = () => ( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, checkPathPart, CurrentPart)), CurrentPart)); return(false); } if (CurrentPart == "null") { if (PathParts.Any) { errProducer = () => ( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An null must be at the start of an expression")); return(false); } PathParts.Add(null, PathType.Null); return(true); } if (CurrentPart == "true" || CurrentPart == "false") { if (PathParts.Any) { errProducer = () => ( new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An boolean must be at the start of an expression")); return(false); } PathParts.Add(CurrentPart, PathType.Boolean); return(true); } if (CurrentPart == "../") { PathParts.Add(null, PathType.ParentSelector); return(true); } if (CurrentPart == "~") { PathParts.Add(null, PathType.RootSelector); return(true); } if (CurrentPart == "?") { PathParts.Add(null, PathType.ObjectSelector); return(true); } PathParts.Add(CurrentPart, PathType.DataPath); return(true); }
public bool Add(char c, TokenzierContext context, int index, out Func <IMorestachioError> errProducer) { errProducer = null; if (!Tokenizer.IsExpressionPathChar(c)) { errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart); return(false); } if (PathParts.IsNullValue) { errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "Nothing can follow on a null"); return(false); } LastCharWasDelimiter = c == '.'; if (c == '/') { if (CurrentPart == "..") { if (PathParts.Any && !PathParts.HasParentSelector) { errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An Parent selector '..\\' can only follow on another parent selector like and never on an root or an data selector"); return(false); } PathParts.Add(null, PathType.ParentSelector); CurrentPart = string.Empty; return(true); } errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "Unexpected '/'. Expected ether the start of an expression or an './'"); return(false); } if (c == '~') { if (CurrentPart != string.Empty || PathParts.Any) { errProducer = () => new InvalidPathSyntaxError(context.CurrentLocation.Offset(index) .AddWindow(new CharacterSnippedLocation(1, index, CurrentPart)), CurrentPart, "An root selector '~' must be at the start of an expression"); return(false); } PathParts.Add(null, PathType.RootSelector); CurrentPart = string.Empty; return(true); } if (c == '?') { PathParts.Add(null, PathType.ObjectSelector); CurrentPart = string.Empty; return(true); } if (c != '.' && CurrentPart == "." && !PathParts.Any) { //in this case somebody wrote .data //so ignore the dot CurrentPart = string.Empty; } if (CurrentPart != string.Empty && CurrentPart != "." && c == '.') { if (!ComputeCurrentPart(context, index, out errProducer)) { return(false); } CurrentPart = ""; } else { CurrentPart += c; } return(true); }