Package com.ibm.icu.text

Examples of com.ibm.icu.text.StringPrepParseException


    }
    private void doTestCompareReferenceImpl(StringBuffer src) throws Exception{
       
        StringBuffer label = src; 

        StringPrepParseException expected = null;
        StringBuffer ascii = null;
        int options = IDNA.DEFAULT;
        logln("Comparing idnaref_toASCII with uidna_toASCII for input: " + prettify(label));
        try{      
            ascii = IDNAReference.convertToASCII(label, options);
        }catch( StringPrepParseException e){
            expected = e;
            if(e.equals(unassignedException)){
                options = IDNA.ALLOW_UNASSIGNED;
                expected = null;
                try{
                    ascii = IDNAReference.convertToASCII(label, options);
                }catch( StringPrepParseException ex){
                    expected = ex;                 
                }
            }
        }
       
        doTestToASCII(label.toString(),
                      (ascii == null) ? null : ascii.toString(),
                      options,
                      expected);

        logln("Comparing idnaref_toUnicode with uidna_toUnicode for input: " + prettify(label));
        StringBuffer uni =null;
       
        if(expected == null){
            options = IDNA.DEFAULT;
            try{
                 uni = IDNAReference.convertToUnicode(ascii, options);
            }catch( StringPrepParseException e ){
                expected = e;
                if(expected.equals(unassignedException)){
                    options = IDNA.ALLOW_UNASSIGNED;
                    expected = null;
                    try{
                        uni = IDNAReference.convertToUnicode(ascii, options);
                    }catch(StringPrepParseException ex){
View Full Code Here


    private static void getException(int rc)
                   throws StringPrepParseException{
         switch(rc){
             case punycode_big_output:
                throw new StringPrepParseException("The output capacity was not sufficient.",StringPrepParseException.BUFFER_OVERFLOW_ERROR);
             case punycode_bad_input:
                throw new StringPrepParseException("Illegal char found in the input",StringPrepParseException.ILLEGAL_CHAR_FOUND);
             case punycode_overflow:
                throw new StringPrepParseException("Invalid char found in the input",StringPrepParseException.INVALID_CHAR_FOUND);  
         }
       
    }
View Full Code Here

            /* special prefixes must not be followed by suffixes! */
            String prefixString = s.substring(0,index);
            int i= findStringIndex(special_prefixes, prefixString);
            String suffixString = s.substring(index+1, s.length());
            if(i>-1 && !suffixString.equals("")){
                throw new StringPrepParseException("Suffix following a special index", StringPrepParseException.INVALID_CHAR_FOUND);
            }
            UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
            UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
            out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
            out.append(AT_SIGN); // add the delimiter
View Full Code Here

        String caseMapOut = transform.mapTransform.transliterate(src);   
        UCharacterIterator iter = UCharacterIterator.getInstance(caseMapOut);
        int ch;
        while((ch=iter.nextCodePoint())!=UCharacterIterator.DONE){                         
            if(transform.unassignedSet.contains(ch)==true && allowUnassigned ==false){
                throw new StringPrepParseException("An unassigned code point was found in the input",
                                         StringPrepParseException.UNASSIGNED_ERROR);
            }
        }
        return caseMapOut;
    }
View Full Code Here

          
        while((ch=iter.nextCodePoint())!= UCharacterIterator.DONE){


            if(transform.prohibitedSet.contains(ch)==true && ch!=0x0020){
                throw new StringPrepParseException("A prohibited code point was found in the input",
                                         StringPrepParseException.PROHIBITED_ERROR,
                                         iter.getText(),iter.getIndex());
            }

            direction = UCharacter.getDirection(ch);
            if(firstCharDir == UCharacterDirection.CHAR_DIRECTION_COUNT){
                firstCharDir = direction;
            }
            if(direction == UCharacterDirection.LEFT_TO_RIGHT){
                leftToRight = true;
                ltrPos = iter.getIndex()-1;
            }
            if(direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC){
                rightToLeft = true;
                rtlPos = iter.getIndex()-1;
            }
        }          

        // satisfy 2
        if( leftToRight == true && rightToLeft == true){
            throw new StringPrepParseException("The input does not conform to the rules for BiDi code points.",
                                     StringPrepParseException.CHECK_BIDI_ERROR,iter.getText(),(rtlPos>ltrPos) ? rtlPos : ltrPos);
        }

        //satisfy 3
        if( rightToLeft == true &&
            !((firstCharDir == UCharacterDirection.RIGHT_TO_LEFT || firstCharDir == UCharacterDirection.RIGHT_TO_LEFT_ARABIC) &&
            (direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC))
           ){
            throw new StringPrepParseException("The input does not conform to the rules for BiDi code points.",
                                      StringPrepParseException.CHECK_BIDI_ERROR,iter.getText(),(rtlPos>ltrPos) ? rtlPos : ltrPos);
        }
       
        return new StringBuffer(mapOut);
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

      processOut = new StringBuffer(src.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
        caseFlags = new boolean[poLen];

        StringBuilder punyout = Punycode.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 > 63.",
          StringPrepParseException.LABEL_TOO_LONG_ERROR, dest.toString(), 0);
    }
    return dest;
  }
View Full Code Here

      sepIndex++;
      oldSepIndex = sepIndex;
      result.append((char) FULL_STOP);
    }
    if (result.length() > MAX_DOMAIN_NAME_LENGTH) {
      throw new StringPrepParseException("The output exceed the max allowed length.",
          StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
  }
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;
      }
      // Unlike the ToASCII operation we don't normalize the label separators
      result.append(srcArr[sepIndex]);
      // increment the sepIndex to skip past the separator
      sepIndex++;
      oldSepIndex = sepIndex;
    }
    if (result.length() > MAX_DOMAIN_NAME_LENGTH) {
      throw new StringPrepParseException("The output exceed the max allowed length.",
          StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
  }
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.