Java String Unescape unescape(String src)

Here you can find the source of unescape(String src)

Description

unescape

License

Apache License

Declaration

public static String unescape(String src) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String unescape(String src) {
        StringBuilder sb = new StringBuilder();
        sb.ensureCapacity(src.length());
        int lastPos = 0;
        int pos = 0;
        while (lastPos < src.length()) {
            pos = src.indexOf("%", lastPos);
            if (pos == lastPos) {
                if (src.charAt(pos + 1) == 'u') {
                    char ch = (char) Integer.parseInt(src.substring(pos + 2, pos + 6), 16);
                    sb.append(ch);//from ww w.  j  ava2  s .  c  o m
                    lastPos = pos + 6;
                } else {
                    char ch = (char) Integer.parseInt(src.substring(pos + 1, pos + 3), 16);
                    sb.append(ch);
                    lastPos = pos + 3;
                }
            } else if (pos == -1) {
                sb.append(src.substring(lastPos));
                lastPos = src.length();
            } else {
                sb.append(src.substring(lastPos, pos));
                lastPos = pos;
            }
        }
        return sb.toString();
    }
}

Related

  1. unescape(String s, int i)
  2. unescape(String s, String toUnescape)
  3. unescape(String source)
  4. unescape(String src)
  5. unescape(String src)
  6. unescape(String src)
  7. unescape(String st)
  8. unescape(String str)
  9. unescape(String str)