Skip to content

Instantly share code, notes, and snippets.

@LordJZ
Created August 6, 2011 02:19
Show Gist options
  • Select an option

  • Save LordJZ/1128920 to your computer and use it in GitHub Desktop.

Select an option

Save LordJZ/1128920 to your computer and use it in GitHub Desktop.
IRC command RFC parser
using (var reader = new StreamReader("rfc.txt"))
using (var writer = new StreamWriter("rfc.parsed"))
{
string pad = " ";
string line;
var builder = new StringBuilder(10240);
string cmd = string.Empty;
while ((line = reader.ReadLine()) != null)
{
if (line.Length > 0 && line[0] != ' ')
{
builder.AppendLine(pad + "/// </example>");
writer.Write(builder.ToString());
builder.Clear();
writer.WriteLine(pad + cmd + ",");
writer.WriteLine();
builder.AppendLine(pad + "/// <summary>");
continue;
}
int idx;
if ((idx = line.IndexOf("Command: ")) != -1)
{
idx += "Command: ".Length;
cmd = line.Substring(idx).Trim();
}
if (line.IndexOf("Examples:") != -1 || line.IndexOf("Example:") != -1)
{
builder.AppendLine(pad + "/// </summary>");
builder.AppendLine(pad + "/// <example>");
continue;
}
builder.AppendLine(pad + "/// " + SecurityElement.Escape(line.Length >= 3 ? line.Substring(3) : line));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment