tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Сергеев Кирилл" <kir...@ufanet.ru>
Subject Please add full support UTF-8
Date Sat, 24 Feb 2001 07:57:06 GMT
method POST

# *****************************************************************
#   replace in javax/servlet/http/HttpUtils.java
# *****************************************************************

    private static String parseName( String data, StringBuffer buf )
    {
  buf.setLength(0);

        for( int i = 0; i < data.length(); i++ )
        {
            char c = data.charAt(i);
            switch(c)
            {
   case 0:
    break;

            case 43: // '+'
                buf.append(' ');
                break;

            case 37: // '%'
                try
                {
     if ( data.length() - i < 3 ) break;
     int b1 = Integer.parseInt( "" + data.charAt(++i) + data.charAt(++i),
16);

     if ( ( b1 & 128 ) == 0 )
     {
      buf.append( (char)b1 );
      break;
     }

     if ( data.length() - i < 4 || data.charAt(++i) != '%' ) break;
     int b2 = Integer.parseInt( "" + data.charAt(++i) + data.charAt(++i),
16);

     if ( ( ( b1 & 192 ) == 192 ) && ( ( b2 & 128 ) == 128 ) )
     {
      buf.append( (char)( ( ( b1 & 31 ) << 6 ) | ( b2 & 63 ) ) );
      break;
     }

     if ( data.length() - i < 4 || data.charAt(++i) != '%' ) break;
     int b3 = Integer.parseInt( "" + data.charAt(++i) + data.charAt(++i),
16);

     if ( ( ( b1 & 192 ) == 192 ) && ( ( b2 & 128 ) == 128 ) && (
( b3 &
128 ) == 128 ) )
      buf.append((char)( ( ( b1 & 15 ) << 12 ) | ( ( b2 & 63 ) << 6 )
| ( b3
& 63 ) ) );

                    break;
                }
                catch(NumberFormatException _ex)
                {
                    String msg = "Decode error ";
                    throw new IllegalArgumentException(msg);
                }
                catch(StringIndexOutOfBoundsException _ex) {}
                break;

            default:
                buf.append(c);
                break;
            }
        }

        return buf.toString();
    }


method GET

# *****************************************************************
#  replace in org/apache/tomcat/util/RequestUtil.java
# *****************************************************************

    public static String unUrlDecode(String data)
    {
        StringBuffer buf = new StringBuffer();
        for(int i = 0; i < data.length(); i++)
        {
            char c = data.charAt(i);
            switch(c)
            {
            case 43: // '+'
                buf.append(' ');
                break;

            case 37: // '%'
                try
                {
     if ( data.length() - i < 3 ) break;
     int b1 = Integer.parseInt( "" + data.charAt(++i) + data.charAt(++i),
16);

     if ( ( b1 & 128 ) == 0 )
     {
      buf.append( (char)b1 );
      break;
     }

     if ( data.length() - i < 4 || data.charAt(++i) != '%' ) break;
     int b2 = Integer.parseInt( "" + data.charAt(++i) + data.charAt(++i),
16);

     if ( ( ( b1 & 192 ) == 192 ) && ( ( b2 & 128 ) == 128 ) )
     {
      buf.append( (char)( ( ( b1 & 31 ) << 6 ) | ( b2 & 63 ) ) );
      break;
     }

     if ( data.length() - i < 4 || data.charAt(++i) != '%' ) break;
     int b3 = Integer.parseInt( "" + data.charAt(++i) + data.charAt(++i),
16);

     if ( ( ( b1 & 192 ) == 192 ) && ( ( b2 & 128 ) == 128 ) && (
( b3 &
128 ) == 128 ) )
      buf.append((char)( ( ( b1 & 15 ) << 12 ) | ( ( b2 & 63 ) << 6 )
| ( b3
& 63 ) ) );

                    break;
                }
                catch(NumberFormatException _ex)
                {
                    String msg = "Decode error ";
                    throw new IllegalArgumentException(msg);
                }
                catch(StringIndexOutOfBoundsException _ex) {}
                break;

            default:
                buf.append(c);
                break;
            }
        }

        return buf.toString();
    }



Mime
View raw message