private static StringBuffer CleanValue(StringBuffer rawValue, bool stopAtKey = false) { var cleanValue = new StringBuffer(); while (!rawValue.IsEmpty) { switch (rawValue.PeekStart()) { case ' ': // spaces rawValue.TrimStart(' '); break; case '\t': // tabs rawValue.TrimStart('\t'); break; case '\r': // line breaks case '\n': rawValue.TrimStart('\r', '\n'); break; case SpChar_CommentBlock: // comments rawValue.PopFromStart(); // Pop first # char poppedChar; do { poppedChar = rawValue.PopFromStart(); } while (!rawValue.IsEmpty && poppedChar != SpChar_CommentBlock); break; case SpChar_KeyDelimiter when stopAtKey: return(cleanValue); case SpChar_LiteralStringBlock: cleanValue.PushToEnd(rawValue.PopFromStart()); // Add first " char popped; do { popped = rawValue.PopFromStart(); cleanValue.PushToEnd(popped); } while (popped != SpChar_LiteralStringBlock); break; case SpChar_EscapeChar: cleanValue.PushToEnd(rawValue.PopFromStart()); // Pop escape char cleanValue.PushToEnd(rawValue.PopFromStart()); // Add escaped char break; default: cleanValue.PushToEnd(rawValue.PopFromStart()); break; } } return(cleanValue); }