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;
11:
12: /**
13: * Class for escaping single quotes in a string, so that they can be safely
14: * included in a SQL statement.
15: *
16: * @deprecated Use org.mmbase.util.Encode
17: * @version $Id: Escape.java,v 1.8 2007/02/10 16:22:36 nklasens Exp $
18: */
19: public class Escape {
20:
21: /**
22: * Escapes single quotes in a string.
23: * Escaping is done by doubling any quotes encountered.
24: * Strings that are rendered in such way can more easily be included
25: * in a SQL query.
26: * @param in the string to escape
27: * @return the escaped string
28: * @duplicate use {@link Encode} Encode encoder = new Encode("ESCAPE_SINGLE_QUOTE");<BR>encoder.encode("MMBase it's escaping quotes");
29: */
30: static public String singlequote(String in) {
31: if (in == null || in.indexOf('\'') == -1)
32: return in;
33:
34: StringBuffer sb = new StringBuffer();
35: char[] data = in.toCharArray();
36: for (char element : data) {
37: if (element == '\'')
38: sb.append("''");
39: else
40: sb.append(element);
41: }
42: return sb.toString();
43: }
44: }
|