public static CalendarProperty ReadFrom(CalendarReader reader) { var line = new CalendarProperty { Name = reader.ReadName() }; if (line.Name.Length == 0) { return(line); } while (reader.PeekOrRead(';')) { var param = CalendarPropertyParameter.ReadFrom(reader); if (line.Parameters == null) { line.Parameters = new List <CalendarPropertyParameter>(); } line.Parameters.Add(param); } reader.ReadChar(':'); line.Value = ReadValue(reader); if (!reader.IsEof) { reader.ReadChar('\r'); } if (!reader.IsEof) { reader.ReadChar('\n'); } return(line); }
public static CalendarPropertyParameter ReadFrom(CalendarReader reader) { var res = new CalendarPropertyParameter { Name = reader.ReadName() }; reader.ReadChar('='); res.Values = ParseParamValues(reader); return(res); }
private static IList <string> ParseParamValues(CalendarReader reader) { var res = new List <string>(); do { var val = ParseParamValue(reader); if (val == null) { if (res.Count == 0) { throw new Exception("Param value expected"); } return(res); } res.Add(val); } while (reader.PeekOrRead(',')); return(res); }
private static string ParseParamValue(CalendarReader reader) { StringBuilder sb = null; while (!reader.IsEof) { var ch = reader.PeekChar(); if (ch == ':' || ch == ';' || ch == ',' || ch == '"' || ch == 0x7f || (ch < 0x20 && ch != 0x09)) { return(sb?.ToString()); } ch = reader.ReadChar(); if (sb == null) { sb = new StringBuilder(); } sb.Append(ch); } return(sb?.ToString()); }
public static CalendarObject Parse(CalendarReader reader) { var begin = CalendarProperty.ReadFrom(reader); if (begin.NameUpper != "BEGIN") { throw new Exception("object expected"); } var type = begin.ValueUpper; var obj = CreateObject(type); while (!reader.IsEof) { var pos = reader.GetPosition(); var line = CalendarProperty.ReadFrom(reader); switch (line.NameUpper) { case "BEGIN": reader.SetPosition(pos); var sub = Parse(reader); obj.Children.Add(sub); break; case "END": if (line.ValueUpper != type) { throw new Exception($"Expected {type} object close but {line.ValueUpper} appeared"); } return(obj); default: obj.Properties.Add(line); break; } } return(obj); }
private static string ReadValue(CalendarReader reader) { var preview = reader.PeekChar(); if (preview == '"') { return(reader.ReadQuotedString()); } var sb = new StringBuilder(); while (!reader.IsEof) { var ch = reader.PeekChar(); if ((ch == '\t' || ch >= 0x20) && ch != 0x7f) { sb.Append(reader.ReadChar()); } else { return(sb.ToString()); } } return(sb.ToString()); }