/******************************************************************************* * Copyright (c) 2011 SAP AG and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * SAP AG - initial API and implementation ******************************************************************************/ package com.sap.furcas.utils; import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class StringUtil { public static String unescapeString(String s) { StringBuilder ret = new StringBuilder(); CharacterIterator ci = new StringCharacterIterator(s); char c = ci.first(); while(c != CharacterIterator.DONE) { char tc = 0; switch(c) { case '\\': c = ci.next(); switch(c) { case 'n': tc = '\n'; break; case 'r': tc = '\r'; break; case 't': tc = '\t'; break; case 'b': tc = '\b'; break; case 'f': tc = '\f'; break; case '"': tc = '"'; break; case '\'': tc = '\''; break; case '\\': tc = '\\'; break; case '0': case '1': case '2': case '3': throw new RuntimeException("octal escape sequences not supported yet"); default: throw new RuntimeException("unknown escape sequence: '\\" + c + "'"); } break; default: tc = c; break; } ret.append(tc); c = ci.next(); } return ret.toString(); } }