diff trunk/src/docgen/misc/textutils.d @ 451:3f44c38bf870

Page templates, more flexible writer interfaces, small fixes.
author Jari-Matti M?kel? <jmjm@iki.fi>
date Wed, 24 Oct 2007 17:25:52 +0300
parents
children 4e5b35df3060
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trunk/src/docgen/misc/textutils.d	Wed Oct 24 17:25:52 2007 +0300
@@ -0,0 +1,50 @@
+/**
+ * Author: Aziz Köksal & Jari-Matti Mäkelä
+ * License: GPL3
+ */
+module docgen.misc.textutils;
+
+import tango.io.model.IConduit;
+import tango.io.stream.GreedyStream;
+
+// copied from Generate.d
+char[] xml_escape(char[] text)
+{
+  char[] result;
+  result.length = text.length;
+  foreach(c; text)
+    switch(c)
+    {
+      case '<': result ~= "&lt;";  break;
+      case '>': result ~= "&gt;";  break;
+      case '&': result ~= "&amp;"; break;
+      default:  result ~= c;
+    }
+  return result;
+}
+
+class XMLEscapeOutput : GreedyOutput {
+  this (OutputStream stream) {
+    super(stream);
+  }
+
+  uint write (void[] src) {
+    return super.write( xml_escape(cast(char[])src) );
+  }
+}
+
+char[] plainTextHeading(char[] s) {
+  char[] line;
+  line.length = 80;
+  line[] = "=";
+
+  return s ~ \n ~ line[0..s.length].dup ~ \n ~ \n;
+}
+
+char[] plainTextHorizLine(int l = 80) {
+  char[] line;
+  line.length = 80;
+  line[] = "-";
+  
+  return line[0..l].dup ~ \n;
+}
\ No newline at end of file