Java File Name Decode fileNameDecode(String str)

Here you can find the source of fileNameDecode(String str)

Description

Decode a string from the encoding used by #fileNameEncode(String) .

License

Open Source License

Parameter

Parameter Description
str the string previously encoded by #fileNameEncode(String)

Return

the original contents of the string

Declaration

public static String fileNameDecode(String str) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w w  w .j a  v a2 s .co m
     * Decode a string from the encoding used by {@link #fileNameEncode(String)}.
     * @param str the string previously encoded by {@link #fileNameEncode(String)}
     * @return the original contents of the string
     */
    public static String fileNameDecode(String str) {

        StringBuilder sb = new StringBuilder();
        int encCharStart, encCharEnd;

        while ((encCharStart = str.indexOf('[')) != -1 && (encCharEnd = str.indexOf(']')) != -1) {

            sb.append(str.substring(0, encCharStart));
            sb.append((char) Integer.parseInt(str.substring(encCharStart + 1, encCharEnd), 16));
            str = encCharEnd == str.length() - 1 ? "" : str.substring(encCharEnd + 1);
        }
        sb.append(str);
        return sb.toString();
    }
}