Package com.ibm.icu.text

Examples of com.ibm.icu.text.UCharacterIterator


    public void TestIterationUChar32() {
        String text="\u0061\u0062\ud841\udc02\u20ac\ud7ff\ud842\udc06\ud801\udc00\u0061";
        int c;
        int i;
        {
            UCharacterIterator iter = UCharacterIterator.getInstance(text);
   
            String iterText = iter.getText();
            if (!iterText.equals(text))
              errln("iter.getText() failed");
           
            iter.setIndex(1);
            if (iter.currentCodePoint() != UTF16.charAt(text,1))
                errln("Iterator didn't start out in the right place.");
   
            iter.setToStart();
            c=iter.currentCodePoint();
            i=0;
            i=iter.moveCodePointIndex(1);
            c=iter.currentCodePoint();
            if(c != UTF16.charAt(text,1) || i!=1)
                errln("moveCodePointIndex(1) didn't work correctly expected "+ hex(c) +" got "+hex(UTF16.charAt(text,1)) + " i= " + i);
   
            i=iter.moveCodePointIndex(2);
            c=iter.currentCodePoint();
            if(c != UTF16.charAt(text,4) || i!=4)
                errln("moveCodePointIndex(2) didn't work correctly expected "+ hex(c) +" got "+hex(UTF16.charAt(text,4)) + " i= " + i);
               
            i=iter.moveCodePointIndex(-2);
            c=iter.currentCodePoint();
            if(c != UTF16.charAt(text,1) || i!=1)
                 errln("moveCodePointIndex(-2) didn't work correctly expected "+ hex(c) +" got "+hex(UTF16.charAt(text,1)) + " i= " + i);

            iter.setToLimit();
            i=iter.moveCodePointIndex(-2);
            c=iter.currentCodePoint();
            if(c != UTF16.charAt(text,(text.length()-3)) || i!=(text.length()-3))
                errln("moveCodePointIndex(-2) didn't work correctly expected "+ hex(c) +" got "+hex(UTF16.charAt(text,(text.length()-3)) ) + " i= " + i);
           
            iter.setToStart();
            c = iter.currentCodePoint();
            i = 0;
   
            //testing first32PostInc, nextCodePointPostInc, setTostart
            i = 0;
            iter.setToStart();
            c =iter.next();
            if(c != UTF16.charAt(text,i))
                errln("first32PostInc failed.  Expected->"+hex(UTF16.charAt(text,i))+" Got-> "+hex(c));
            if(iter.getIndex() != UTF16.getCharCount(c) + i)
                errln("getIndex() after first32PostInc() failed");
   
            iter.setToStart();
            i=0;
            if (iter.getIndex() != 0)
                errln("setToStart failed");
          
            logln("Testing forward iteration...");
            do {
                if (c != UCharacterIterator.DONE)
                    c = iter.nextCodePoint();
   
                if(c != UTF16.charAt(text,i))
                    errln("Character mismatch at position "+i+", iterator has "+hex(c)+", string has "+hex(UTF16.charAt(text,i)));
   
                i+=UTF16.getCharCount(c);
                if(iter.getIndex() != i)
                    errln("getIndex() aftr nextCodePointPostInc() isn't working right");
                c = iter.currentCodePoint();                  
                if( c!=UCharacterIterator.DONE && c != UTF16.charAt(text,i))
                    errln("current() after nextCodePointPostInc() isn't working right");

            } while (c!=UCharacterIterator.DONE);
            c=iter.nextCodePoint();
            if(c!= UCharacterIterator.DONE)
                errln("nextCodePointPostInc() didn't return DONE at the beginning");
   
   
        }
View Full Code Here


                UTF16.getLeadSurrogate(0x1d15f), UTF16.getTrailSurrogate(0x1d15f),
                0xc4,
                0x1ed0
            };
        // iterators
        UCharacterIterator iter1 = UCharacterIterator.getInstance(new ReplaceableString(new String(src)));
        UCharacterIterator iter2 = UCharacterIterator.getInstance(src/*char array*/);
        UCharacterIterator iter3 = UCharacterIterator.getInstance(new StringCharacterIterator(new String(src)));
        UCharacterIterator iter4 = UCharacterIterator.getInstance(new StringBuffer(new String(src)));
        previousNext(iter1);
        previousNext(iter2);
        previousNext(iter3);
        previousNext(iter4);
        getText(iter1,new String(src));
        getText(iter2,new String(src));
        getText(iter3,new String(src));
        /* getCharacterIterator */
        CharacterIterator citer1 = iter1.getCharacterIterator();
        CharacterIterator citer2 = iter2.getCharacterIterator();
        CharacterIterator citer3 = iter3.getCharacterIterator();
        if(citer1.first() !=iter1.current()){
            errln("getCharacterIterator for iter1 failed");
        }
        if(citer2.first() !=iter2.current()){
            errln("getCharacterIterator for iter2 failed");
        }
        if(citer3.first() !=iter3.current()){
            errln("getCharacterIterator for iter3 failed");
        }
        /* Test clone()  && moveIndex()*/
        try{
            UCharacterIterator clone1 = (UCharacterIterator)iter1.clone();
            UCharacterIterator clone2 = (UCharacterIterator)iter2.clone();
            UCharacterIterator clone3 = (UCharacterIterator)iter3.clone();
            if(clone1.moveIndex(3)!=iter1.moveIndex(3)){
                errln("moveIndex for iter1 failed");
            }
            if(clone2.moveIndex(3)!=iter2.moveIndex(3)){
                errln("moveIndex for iter2 failed");
            }
            if(clone3.moveIndex(3)!=iter3.moveIndex(3)){
                errln("moveIndex for iter1 failed");
            }
        }catch (Exception e){
            errln("could not clone the iterator");
        }
View Full Code Here

            }
        }
    }
    public void TestUCharacterIteratorWrapper(){
        String source ="asdfasdfjoiuyoiuy2341235679886765";
        UCharacterIterator it = UCharacterIterator.getInstance(source);
        CharacterIterator wrap_ci = it.getCharacterIterator();
        CharacterIterator ci = new StringCharacterIterator(source);
        wrap_ci.setIndex(10);
        ci.setIndex(10);
        String moves="0+0+0--0-0-+++0--+++++++0--------++++0000----0-";
        int c1, c2;
View Full Code Here

    private static final int ITERATION_SUPPLEMENTARY_INDEX = 14;
   
    public void TestJitterbug1952(){
        //test previous code point
        char[] src = new char[]{ '\uDC00','\uD800','\uDC01','\uD802','\uDC02','\uDC03'};
        UCharacterIterator iter = UCharacterIterator.getInstance(src);
        iter.setIndex(1);
        int ch;
        // this should never go into a infinite loop
        // if it does then we have a problem
        while((ch=iter.previousCodePoint())!=UCharacterIterator.DONE){
            if(ch!=0xDc00){
                errln("iter.previousCodePoint() failed");
            }
        }
        iter.setIndex(5);
        while((ch=iter.nextCodePoint()) !=UCharacterIterator.DONE){
            if(ch!= 0xDC03){
                errln("iter.nextCodePoint() failed");
            }
        }     
    }
View Full Code Here

    public static boolean isValidDigitString(String str) {

        int c;
        int prev = 0;
        int i = 0;
        UCharacterIterator it = UCharacterIterator.getInstance(str);

        it.setToStart();
        while ( (c = it.nextCodePoint()) != UCharacterIterator.DONE) {
            if ( UCharacter.digit(c) != i ) { // Digits outside the Unicode decimal digit class are not currently supported
                return false;
            }
            if ( prev != 0 && c != prev + 1 ) { // Non-contiguous digits are not currently supported
                return false;
View Full Code Here

    }
   
    private void doTestToUnicode(String src, String expected, int options, Object expectedException)
                throws Exception{
        StringBuffer inBuf = new StringBuffer(src);
        UCharacterIterator inIter = UCharacterIterator.getInstance(src);
        try{
           
            StringBuffer out = IDNAReference.convertToUnicode(src,options);
            if(expected!=null && out != null && !out.toString().equals(expected)){
                errln("convertToUnicode did not return expected result with options : "+ options +
View Full Code Here

    }
   
    private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException)
                throws Exception{
        StringBuffer inBuf = new StringBuffer(src);
        UCharacterIterator inIter = UCharacterIterator.getInstance(src);
        try{
           
            StringBuffer out = IDNAReference.convertIDNToUnicode(src,options);
            if(expected!=null && out != null && !out.toString().equals(expected)){
                errln("convertToUnicode did not return expected result with options : "+ options +
View Full Code Here

        }
    }
    private void doTestToASCII(String src, String expected, int options, Object expectedException)
                throws Exception{
        StringBuffer inBuf = new StringBuffer(src);
        UCharacterIterator inIter = UCharacterIterator.getInstance(src);
        try{
           
            StringBuffer out = IDNAReference.convertToASCII(src,options);
            if(!unassignedException.equals(expectedException) && expected!=null && out != null && expected!=null && out != null && !out.toString().equals(expected.toLowerCase())){
                errln("convertToASCII did not return expected result with options : "+ options +
View Full Code Here

    }
    private void doTestIDNToASCII(String src, String expected, int options, Object expectedException)
                throws Exception{
       
        StringBuffer inBuf = new StringBuffer(src);
        UCharacterIterator inIter = UCharacterIterator.getInstance(src);
        try{
           
            StringBuffer out = IDNAReference.convertIDNToASCII(src,options);
            if(expected!=null && out != null && !out.toString().equals(expected)){
                errln("convertToIDNAReferenceASCII did not return expected result with options : "+ options +
View Full Code Here

    public void TestNamePrepConformance() throws Exception{
        try{
            NamePrepTransform namePrep = NamePrepTransform.getInstance();
            for(int i=0; i<TestData.conformanceTestCases.length;i++){
                TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
                UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
                try{
                    StringBuffer output = namePrep.prepare(iter,NamePrepTransform.NONE);
                    if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                        errln("Did not get the expected output. Expected: " + prettify(testCase.output)+
                              " Got: "+ prettify(output) );
                    }
                    if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
                        errln("Did not get the expected exception. The operation succeeded!");
                    }
                }catch(StringPrepParseException ex){
                    if(testCase.expected == null || !ex.equals(testCase.expected)){
                        errln("Did not get the expected exception for source: " +testCase.input +" Got:  "+ ex.toString());
                    }
                }
               
                try{
                    iter.setToStart();
                    StringBuffer output = namePrep.prepare(iter,NamePrepTransform.ALLOW_UNASSIGNED);
                    if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                        errln("Did not get the expected output. Expected: " + prettify(testCase.output)+
                              " Got: "+ prettify(output) );
                    }
View Full Code Here

TOP

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

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.