public static string GetContentAndClear(this StringWriter writer) { var content = writer.GetContent(); writer.Clear(); return(content); }
public object Parse(string value, object argument) { var headers = new List <HeaderField>(); using (var sr = new StringReader(value)) { using (var sw = new StringWriter()) { while (true) { var line = sr.ReadLine(); // end of block reached, no more headers if (string.IsNullOrEmpty(line)) { break; } sw.Write(line); while (true) { var next = sr.Peek(); var isContinuation = next == Characters.Space || next == Characters.Tabulator; if (isContinuation) { var continuation = sr.ReadLine(); if (string.IsNullOrEmpty(continuation)) { break; } sw.Write(continuation.Trim()); } else { break; } } var literals = sw.ToString(); if (!string.IsNullOrEmpty(literals)) { var header = new HeaderField(); sw.Clear(); header.Deserialize(literals); headers.Add(header); } } } } return(headers); }
public SearchTranslationResult Translate(Expression expression) { _writer.Clear(); AppendWord(SearchCommands.Search); Visit(expression); ProcessDeferredCommands(); return(new SearchTranslationResult { SearchCommand = _writer.ToString().TrimEnd(), IsUid = _uidSet.IsTouched }); }
private static IEnumerable <string> ReadBoundaryBlocks(string name, TextReader reader) { var parts = new List <string>(); var boundaryStart = "--" + name; var boundaryTerminator = "--" + name + "--"; using (var writer = new StringWriter()) { while (true) { var line = reader.ReadLine(); if (line != null) { var isBoundaryTerminator = line.StartsWith(boundaryTerminator); var isBoundaryStart = line == boundaryStart; if (isBoundaryTerminator || isBoundaryStart) { var content = writer.ToString(); parts.Add(content); writer.Clear(); // last line or end of boundary if (isBoundaryTerminator) { break; } continue; } } writer.WriteLine(line); } } return(parts); }