Java String Unescape unescape(String line, int start, int end)

Here you can find the source of unescape(String line, int start, int end)

Description

unescape

License

Open Source License

Declaration

private static String unescape(String line, int start, int end) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * This file is part of the Prolog Development Tool (PDT)
 * /* w  w w .j  a va 2 s.  co  m*/
 * Author: Lukas Degener (among others)
 * WWW: http://sewiki.iai.uni-bonn.de/research/pdt/start
 * Mail: pdt@lists.iai.uni-bonn.de
 * Copyright (C): 2004-2012, CS Dept. III, University of Bonn
 * 
 * All rights reserved. This program is  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
 * 
 ****************************************************************************/

public class Main {
    private static String unescape(String line, int start, int end) {
        StringBuffer sb = new StringBuffer();
        boolean escape = false;
        StringBuffer escBuf = new StringBuffer();
        for (int i = start; i < end; i++) {
            char c = line.charAt(i);
            switch (c) {
            case '&':
                escape = true;
                break;
            case ';':
                if (escape) {
                    escape = false;
                    String escSeq = escBuf.toString();
                    escBuf.setLength(0);
                    if ("lt".equals(escSeq)) {
                        sb.append('<');
                    } else if ("gt".equals(escSeq)) {
                        sb.append('>');
                    } else if ("cbo".equals(escSeq)) {
                        sb.append('{');
                    } else if ("cbc".equals(escSeq)) {
                        sb.append('}');
                    } else if ("amp".equals(escSeq)) {
                        sb.append('&');
                    } else if ("apos".equals(escSeq)) {
                        sb.append('\'');
                    } else if ("quot".equals(escSeq)) {
                        sb.append('\"');
                    }
                } else {
                    sb.append(c);
                }
                break;
            default:
                if (escape) {
                    escBuf.append(c);
                } else {
                    sb.append(c);
                }
                break;
            }
        }
        return sb.toString();
    }
}

Related

  1. unescape(String input)
  2. unescape(String input)
  3. unescape(String input, char escapeChar)
  4. unescape(String line)
  5. unescape(String line)
  6. unescape(String literal, String escapedChars)
  7. unescape(String name)
  8. unescape(String oldStr)
  9. unescape(String original, char[] spec)