/// <summary> /// Exports the XML. /// </summary> private void ExportXml() { string content = new TextRange(txtLines.Document.ContentStart, txtLines.Document.ContentEnd).Text; var lines = content.Split("\n".ToCharArray()); var xml = new XElement( "output", lines.Select( line => new XElement( "Item", line.Split(',').Select((column, index) => new XElement("Column" + index, column))))); var builder = new StringBuilder(); xml.WriteTo(new XmlTextWriter(new IndentedTextWriter(new StringWriter(builder)))); txtLines.Document.Blocks.Clear(); txtLines.AppendText(builder.ToString()); }
private void OutputEnumCode_Click(object sender, RoutedEventArgs e) { string myText = new TextRange(EnumInBox.Document.ContentStart, EnumInBox.Document.ContentEnd).Text; if (myText.Length > 0) { try { EnumOutBox.Document.Blocks.Clear(); string[] lines = myText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); int lastSpaceIndex = lines[0].LastIndexOf(" "); string enumName = lines[0].Substring(lastSpaceIndex, lines[0].Length - lastSpaceIndex).Trim(); StringBuilder output1 = new StringBuilder(); StringBuilder output2 = new StringBuilder(); output1.AppendLine("boost::unordered_map<std::string, " + enumName + "> = boost::assign::map_list_of"); output2.AppendLine("boost::unordered_map<" + enumName + ", std::string> = boost::assign::map_list_of"); for (int i = 1; i < lines.Length; ++i) { lines[i] = lines[i].Trim(); lines[i] = lines[i].Replace("\r", String.Empty); lines[i] = lines[i].Replace("\t", String.Empty); lines[i] = lines[i].Replace("\n", String.Empty); lines[i] = lines[i].Replace(",", String.Empty); if (lines[i] != "};" && lines[i] != "{" && lines[i] != String.Empty) { int commentIndex = lines[i].IndexOf("//"); if (commentIndex > 0) { lines[i] = lines[i].Substring(0, commentIndex).Trim(); } output1.AppendLine("\t(\"" + lines[i] + "\", " + enumName + "::" + lines[i] + ")"); output2.AppendLine("\t(" + enumName + "::" + lines[i] + ", \"" + lines[i] + "\")"); } } output1.AppendLine(";"); output2.AppendLine(";"); output1.Append(output2.ToString()); EnumOutTextBox.Text = output1.ToString(); //System.IO.MemoryStream stream = new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes(output1.ToString())); //this.EnumOutBox.Selection.Load(stream, DataFormats.Rtf); } catch (System.Exception ex) { } } }