01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.util.transformers;
11:
12: import java.io.Reader;
13: import java.io.Writer;
14:
15: import org.mmbase.util.logging.*;
16:
17: /**
18: * Transforms strings to identifiers, replacing punctuation and whitespace with
19: * underscores.
20: *
21: * @author Pierre van Rooden
22: * @since MMBase-1.7
23: * @version $Id: Identifier.java,v 1.3 2004/07/09 20:38:42 michiel Exp $
24: */
25:
26: public class Identifier extends ReaderTransformer implements
27: CharTransformer {
28: private static Logger log = Logging
29: .getLoggerInstance(Identifier.class);
30:
31: public Writer transform(Reader r, Writer w) {
32: try {
33: log.debug("Starting identifier");
34: while (true) {
35: int c = r.read();
36: if (c == -1)
37: break;
38: if (Character.isLetterOrDigit((char) c)) {
39: w.write((char) c);
40: } else {
41: w.write('_');
42: }
43: }
44: log.debug("Finished identifier");
45: } catch (java.io.IOException e) {
46: log.error(e.toString());
47: }
48: return w;
49: }
50:
51: public String toString() {
52: return "IDENTIFIER";
53: }
54: }
|