📄 municodeurldecoder.java
字号:
package net.jumperz.net;
public class MUnicodeUrlDecoder
{
private static final int HEX = 16;
//-------------------------------------------------------------------------------------
public static boolean isUrlDecoded( String in )
{
if( in.indexOf( "%" ) == -1 )
{
return false;
}
else if( in.indexOf( "%u") == -1
&& in.indexOf( "%U" ) == -1
)
{
return false;
}
return true;
}
//-------------------------------------------------------------------------------------
public static String decode( String in )
throws IllegalArgumentException
{
int len = in.length();
StringBuffer buf = new StringBuffer( len );
char c1, c2;
char decoded;
int i = 0;
while( i < len )
{
c1 = in.charAt( i );
if( c1 == '%' )
{
if( i + 5 >= len )
{
throw new IllegalArgumentException( "Incomplete trailing escape (%) pattern" );
}
c2 = in.charAt( i + 1 );
if( c2 != 'u'
&& c2 != 'U'
)
{
throw new IllegalArgumentException( "MUnicodeUrlDecoder: Illegal characters in escape (%) pattern" );
}
int decodedInt = 0;
for( int j = 0; j < 4; ++j )
{
char c3 = in.charAt( i + 2 + j );
int i1 = Character.digit( c3, HEX );
if( i1 < 0 )
{
throw new IllegalArgumentException( "MUnicodeUrlDecoder: Illegal characters in escape (%) pattern" );
}
decodedInt += ( i1 << ( 12 - ( 4 * j ) ) );
}
decoded = ( char )decodedInt;
buf.append( decoded );
i += 6;
}
else
{
buf.append( c1 );
++i;
}
}
return buf.toString();
}
//-------------------------------------------------------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -