Mercurial > public > html2wiki
comparison src/org/nwoca/ssdt/tools/html2wiki/ReplaceTransformer.java @ 0:f8b1ea49d065
Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
author | smith@nwoca.org |
---|---|
date | Fri, 12 May 2006 16:45:42 -0400 |
parents | |
children | 22ed6d93442c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f8b1ea49d065 |
---|---|
1 package org.nwoca.ssdt.tools.html2wiki; | |
2 | |
3 import java.util.regex.*; | |
4 | |
5 class ReplaceTransformer implements Transformer { | |
6 | |
7 private Pattern replace; | |
8 private String replacement; | |
9 | |
10 public ReplaceTransformer(String regex, String replacement) { | |
11 replace = Pattern.compile(regex); | |
12 this.replacement = replacement; | |
13 | |
14 } | |
15 public void apply(StringBuffer buffer) { | |
16 Matcher matcher = replace.matcher(buffer); | |
17 | |
18 boolean first = true; | |
19 while (matcher.find(first ? 0 : matcher.end())) { | |
20 buffer.replace(matcher.start(),matcher.end(),replacement); | |
21 first = false; | |
22 } | |
23 | |
24 } | |
25 | |
26 public String toString() { | |
27 return "Replace: " + replace.pattern() + " with " +replacement; | |
28 } | |
29 | |
30 | |
31 } |