/*
Copyright 2002 Steve Jolly

This file is part of Scot

Scot is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; specifically version 2 of the License.

Scot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Scot; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import java.text.*;

public class EscapedString {
	private String mString;

	public EscapedString(String rawstring) {
		StringCharacterIterator iter = new StringCharacterIterator(rawstring);
		StringBuffer escapedstring = new StringBuffer(rawstring.length());
		for (char cchar = iter.first(); cchar != CharacterIterator.DONE; cchar = iter.next()) {
			switch(cchar) {
			case '\0':				// Must be escaped for "mysql"
			case '\n':				// Must be escaped for logs
			case '\r':
			case '\\':
			case '\"':
			case '\'':				// Better safe than sorry
			case '\032':			// This gives problems on Win32
				escapedstring.append('\\');
				break;
			}
			escapedstring.append(cchar);
		}
		mString = new String(escapedstring.toString());
	}

	public String toString() {
		return mString;
	}
}
