Mercurial > projects > dil
annotate 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 |
rev | line source |
---|---|
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
1 /** |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
2 * Author: Aziz Köksal & Jari-Matti Mäkelä |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
3 * License: GPL3 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
4 */ |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
5 module docgen.misc.textutils; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
6 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
7 import tango.io.model.IConduit; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
8 import tango.io.stream.GreedyStream; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
9 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
10 // copied from Generate.d |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
11 char[] xml_escape(char[] text) |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
12 { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
13 char[] result; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
14 result.length = text.length; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
15 foreach(c; text) |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
16 switch(c) |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
17 { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
18 case '<': result ~= "<"; break; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
19 case '>': result ~= ">"; break; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
20 case '&': result ~= "&"; break; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
21 default: result ~= c; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
22 } |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
23 return result; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
24 } |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
25 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
26 class XMLEscapeOutput : GreedyOutput { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
27 this (OutputStream stream) { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
28 super(stream); |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
29 } |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
30 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
31 uint write (void[] src) { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
32 return super.write( xml_escape(cast(char[])src) ); |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
33 } |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
34 } |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
35 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
36 char[] plainTextHeading(char[] s) { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
37 char[] line; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
38 line.length = 80; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
39 line[] = "="; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
40 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
41 return s ~ \n ~ line[0..s.length].dup ~ \n ~ \n; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
42 } |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
43 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
44 char[] plainTextHorizLine(int l = 80) { |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
45 char[] line; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
46 line.length = 80; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
47 line[] = "-"; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
48 |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
49 return line[0..l].dup ~ \n; |
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
50 } |