Created
August 6, 2011 02:19
-
-
Save LordJZ/1128920 to your computer and use it in GitHub Desktop.
IRC command RFC parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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