Package com.ibm.icu.text

Examples of com.ibm.icu.text.StringPrepParseException


        return IDNA.convertIDNToASCII(host,IDNA.USE_STD3_RULES|IDNA.ALLOW_UNASSIGNED);
    } catch (StringPrepParseException e) {
        throw new MalformedIDNException(e);
    } catch (IndexOutOfBoundsException e) {
        throw new MalformedIDNException(
                new StringPrepParseException("The labels in the input are too long. Length > 64.",
                        StringPrepParseException.LABEL_TOO_LONG_ERROR,host,0)
                );
    }
        /*
        int u[] = new int[host.length()];
View Full Code Here


        return IDNA.convertIDNToASCII(host,IDNA.USE_STD3_RULES|IDNA.ALLOW_UNASSIGNED);
    } catch (StringPrepParseException e) {
        throw new MalformedIDNException(e);
    } catch (IndexOutOfBoundsException e) {
        throw new MalformedIDNException(
                new StringPrepParseException("The labels in the input are too long. Length > 64.",
                        StringPrepParseException.LABEL_TOO_LONG_ERROR,host,0)
                );
    }
        /*
        int u[] = new int[host.length()];
View Full Code Here

        return IDNA.convertIDNToASCII(host,IDNA.USE_STD3_RULES|IDNA.ALLOW_UNASSIGNED);
    } catch (StringPrepParseException e) {
        throw new MalformedIDNException(e);
    } catch (IndexOutOfBoundsException e) {
        throw new MalformedIDNException(
                new StringPrepParseException("The labels in the input are too long. Length > 64.",
                        StringPrepParseException.LABEL_TOO_LONG_ERROR,host,0)
                );
    }
        /*
        int u[] = new int[host.length()];
View Full Code Here

                    ++j;
                   
                    n|=UCharacter.getCodePoint(c, c2);
                } else {
                    /* error: unmatched surrogate */
                    throw new StringPrepParseException("Illegal char found",StringPrepParseException.ILLEGAL_CHAR_FOUND);
                }
                cpBuffer[srcCPCount++]=n;
            }
        }

View Full Code Here

        destLength=basicLength=destCPCount=j;

        while(j>0) {
            b=src.charAt(--j);
            if(!isBasic(b)) {
                throw new StringPrepParseException("Illegal char found", StringPrepParseException.INVALID_CHAR_FOUND);
            }

            if(j<destCapacity) {
                dest[j]= b;

                if(caseFlags!=null) {
                    caseFlags[j]=isBasicUpperCase(b);
                }
            }
        }

        /* Initialize the state: */
        n=INITIAL_N;
        i=0;
        bias=INITIAL_BIAS;
        firstSupplementaryIndex=1000000000;

        /*
         * Main decoding loop:
         * Start just after the last delimiter if any
         * basic code points were copied; start at the beginning otherwise.
         */
        for(in=basicLength>0 ? basicLength+1 : 0; in<srcLength; /* no op */) {
            /*
             * in is the index of the next character to be consumed, and
             * destCPCount is the number of code points in the output array.
             *
             * Decode a generalized variable-length integer into delta,
             * which gets added to i.  The overflow checking is easier
             * if we increase i as we go, then subtract off its starting
             * value at the end to obtain delta.
             */
            for(oldi=i, w=1, k=BASE; /* no condition */; k+=BASE) {
                if(in>=srcLength) {
                    throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
                }

                digit=basicToDigit[src.charAt(in++) & 0xFF];
                if(digit<0) {
                    throw new StringPrepParseException("Invalid char found", StringPrepParseException.INVALID_CHAR_FOUND);
                }
                if(digit>(0x7fffffff-i)/w) {
                    /* integer overflow */
                    throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
                }

                i+=digit*w;
                t=k-bias;
                if(t<TMIN) {
                    t=TMIN;
                } else if(k>=(bias+TMAX)) {
                    t=TMAX;
                }
                if(digit<t) {
                    break;
                }

                if(w>0x7fffffff/(BASE-t)) {
                    /* integer overflow */
                    throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
                }
                w*=BASE-t;
            }

            /*
             * Modification from sample code:
             * Increments destCPCount here,
             * where needed instead of in for() loop tail.
             */
            ++destCPCount;
            bias=adaptBias(i-oldi, destCPCount, (oldi==0));

            /*
             * i was supposed to wrap around from (incremented) destCPCount to 0,
             * incrementing n each time, so we'll fix that now:
             */
            if(i/destCPCount>(0x7fffffff-n)) {
                /* integer overflow */
                throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
            }

            n+=i/destCPCount;
            i%=destCPCount;
            /* not needed for Punycode: */
            /* if (decode_digit(n) <= BASE) return punycode_invalid_input; */

            if(n>0x10ffff || isSurrogate(n)) {
                /* Unicode code point overflow */
                throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
            }

            /* Insert n at position i of the output: */
            cpLength=UTF16.getCharCount(n);
            if((destLength+cpLength)<destCapacity) {
View Full Code Here

    {
        public Object[] getTestObjects()
        {
            Locale locales[] = SerializableTest.getLocales();
            String rules = "This is a very odd little set of rules, just for testing, you know...";
            StringPrepParseException exceptions[] = new StringPrepParseException[locales.length];
           
            for (int i = 0; i < locales.length; i += 1) {
                exceptions[i] = new StringPrepParseException(locales[i].toString(), i, rules, i);
            }
           
            return exceptions;
        }
View Full Code Here

            errln("Got unexpected exception: " + e.toString());
        }
    }
   
    public void TestCoverage(){
        if (new StringPrepParseException("coverage", 0, "", 0,0) == null){
            errln("Construct StringPrepParseException(String, int, String, int, int)");
        }
    }
View Full Code Here

        }else{
            processOut = new StringBuffer(srcIter.getText());
        }
        int poLen = processOut.length();
        if(poLen==0){
            throw new StringPrepParseException("Found zero length lable after NamePrep.",StringPrepParseException.ZERO_LENGTH_LABEL);
        }
        StringBuffer dest = new StringBuffer();
       
        // reset the variable to verify if output of prepare is ASCII or not
        srcIsASCII = true;
       
        // step 3 & 4
        for(int j=0;j<poLen;j++ ){
            ch=processOut.charAt(j);
            if(ch > 0x7F){
                srcIsASCII = false;
            }else if(isLDHChar(ch)==false){
                // here we do not assemble surrogates
                // since we know that LDH code points
                // are in the ASCII range only
                srcIsLDH = false;
                failPos = j;
            }
        }
   
        if(useSTD3ASCIIRules == true){
            // verify 3a and 3b
            if( srcIsLDH == false /* source contains some non-LDH characters */
                || processOut.charAt(0) ==  HYPHEN
                || processOut.charAt(processOut.length()-1) == HYPHEN){

                /* populate the parseError struct */
                if(srcIsLDH==false){
                     throw new StringPrepParseException( "The input does not conform to the STD 3 ASCII rules",
                                              StringPrepParseException.STD3_ASCII_RULES_ERROR,
                                              processOut.toString(),
                                             (failPos>0) ? (failPos-1) : failPos);
                }else if(processOut.charAt(0) == HYPHEN){
                    throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
                                              StringPrepParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),0);
    
                }else{
                     throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
                                              StringPrepParseException.STD3_ASCII_RULES_ERROR,
                                              processOut.toString(),
                                              (poLen>0) ? poLen-1 : poLen);

                }
            }
        }
        if(srcIsASCII){
            dest =  processOut;
        }else{
            // step 5 : verify the sequence does not begin with ACE prefix
            if(!startsWithPrefix(processOut)){

                //step 6: encode the sequence with punycode
                StringBuffer punyout = PunycodeReference.encode(processOut,caseFlags);
               
                // convert all codepoints to lower case ASCII
                StringBuffer lowerOut = toASCIILower(punyout);

                //Step 7: prepend the ACE prefix
                dest.append(ACE_PREFIX,0,ACE_PREFIX_LENGTH);
                //Step 6: copy the contents in b2 into dest
                dest.append(lowerOut);
            }else{
                throw new StringPrepParseException("The input does not start with the ACE Prefix.",
                                   StringPrepParseException.ACE_PREFIX_ERROR,processOut.toString(),0);
            }
        }
        if(dest.length() > MAX_LABEL_LENGTH){
            throw new StringPrepParseException("The labels in the input are too long. Length > 64.",
                                    StringPrepParseException.LABEL_TOO_LONG_ERROR,dest.toString(),0);
        }
        return dest;
    }
View Full Code Here

            //step 6:Apply toASCII
            StringBuffer toASCIIOut = convertToASCII(decodeOut, options);

            //step 7: verify
            if(compareCaseInsensitiveASCII(processOut, toASCIIOut) !=0){
                throw new StringPrepParseException("The verification step prescribed by the RFC 3491 failed",
                                          StringPrepParseException.VERIFICATION_ERROR);
             }

            //step 8: return output of step 5
            return decodeOut;
           
        }else{
            // verify that STD3 ASCII rules are satisfied
            if(useSTD3ASCIIRules == true){
                if( srcIsLDH == false /* source contains some non-LDH characters */
                    || processOut.charAt(0) ==  HYPHEN
                    || processOut.charAt(processOut.length()-1) == HYPHEN){
   
                        if(srcIsLDH==false){
                            throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
                                                     StringPrepParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),
                                                     (failPos>0) ? (failPos-1) : failPos);
                        }else if(processOut.charAt(0) == HYPHEN){
                            throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
                                                     StringPrepParseException.STD3_ASCII_RULES_ERROR,
                                                     processOut.toString(),0);
        
                        }else{
                            throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
                                                     StringPrepParseException.STD3_ASCII_RULES_ERROR,
                                                     processOut.toString(),
                                                     processOut.length());
   
                        }
View Full Code Here

        int oldSepIndex=0;
        for(;;){
            sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
            String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
            if(label.length()==0 && sepIndex!=srcArr.length ){
                throw new StringPrepParseException("Found zero length lable after NamePrep.",StringPrepParseException.ZERO_LENGTH_LABEL);
            }
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            result.append(convertToUnicode(iter,options));
            if(sepIndex==srcArr.length){
                break;
View Full Code Here

TOP

Related Classes of com.ibm.icu.text.StringPrepParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.