コード例 #1
0
 public void test_lowSurrogate() throws Exception {
   // The behavior for non-supplementary code points (like these two) is undefined.
   // These are the obvious results if you don't do anything special.
   assertEquals(0xdc00, Character.lowSurrogate(0x0000));
   assertEquals(0xde66, Character.lowSurrogate(0x0666));
   // These two tests must pass, though.
   assertEquals(0xdc00, Character.lowSurrogate(0x010000));
   assertEquals(0xdfff, Character.lowSurrogate(0x10ffff));
 }
コード例 #2
0
ファイル: TokenStream.java プロジェクト: rwaldron/es6draft
 void addCodepoint(int c) {
   if (c > 0xFFFF) {
     add(Character.highSurrogate(c));
     add(Character.lowSurrogate(c));
   } else {
     add(c);
   }
 }
コード例 #3
0
 /*     */ protected CoderResult decodeLoop(
     ByteBuffer paramByteBuffer, CharBuffer paramCharBuffer)
       /*     */ {
   /*  65 */ if (paramByteBuffer.remaining() < 4) /*  66 */ return CoderResult.UNDERFLOW;
   /*  67 */ int i = paramByteBuffer.position();
   /*     */ try
   /*     */ {
     /*     */ int j;
     /*  70 */ if (this.currentBO == 0) {
       /*  71 */ j =
           (paramByteBuffer.get() & 0xFF) << 24
               | (paramByteBuffer.get() & 0xFF) << 16
               | (paramByteBuffer.get() & 0xFF) << 8
               | paramByteBuffer.get() & 0xFF;
       /*     */
       /*  75 */ if ((j == 65279) && (this.expectedBO != 2)) {
         /*  76 */ this.currentBO = 1;
         /*  77 */ i += 4;
         /*  78 */ } else if ((j == -131072) && (this.expectedBO != 1)) {
         /*  79 */ this.currentBO = 2;
         /*  80 */ i += 4;
         /*     */ } else {
         /*  82 */ if (this.expectedBO == 0) /*  83 */ this.currentBO = 1;
         /*     */ else /*  85 */ this.currentBO = this.expectedBO;
         /*  86 */ paramByteBuffer.position(i);
         /*     */ }
       /*     */ }
     /*     */ CoderResult localCoderResult;
     /*  89 */ while (paramByteBuffer.remaining() >= 4) {
       /*  90 */ j = getCP(paramByteBuffer);
       /*  91 */ if (Character.isBmpCodePoint(j)) {
         /*  92 */ if (!paramCharBuffer.hasRemaining()) /*  93 */ return CoderResult.OVERFLOW;
         /*  94 */ i += 4;
         /*  95 */ paramCharBuffer.put((char) j);
         /*  96 */ } else if (Character.isValidCodePoint(j)) {
         /*  97 */ if (paramCharBuffer.remaining() < 2) /*  98 */ return CoderResult.OVERFLOW;
         /*  99 */ i += 4;
         /* 100 */ paramCharBuffer.put(Character.highSurrogate(j));
         /* 101 */ paramCharBuffer.put(Character.lowSurrogate(j));
         /*     */ } else {
         /* 103 */ return CoderResult.malformedForLength(4);
         /*     */ }
       /*     */ }
     /* 106 */ return CoderResult.UNDERFLOW;
     /*     */ } finally {
     /* 108 */ paramByteBuffer.position(i);
     /*     */ }
   /*     */ }
コード例 #4
0
 protected CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
   if (src.remaining() < 4) return CoderResult.UNDERFLOW;
   int mark = src.position();
   int cp;
   try {
     if (currentBO == NONE) {
       cp =
           ((src.get() & 0xff) << 24)
               | ((src.get() & 0xff) << 16)
               | ((src.get() & 0xff) << 8)
               | (src.get() & 0xff);
       if (cp == BOM_BIG && expectedBO != LITTLE) {
         currentBO = BIG;
         mark += 4;
       } else if (cp == BOM_LITTLE && expectedBO != BIG) {
         currentBO = LITTLE;
         mark += 4;
       } else {
         if (expectedBO == NONE) currentBO = BIG;
         else currentBO = expectedBO;
         src.position(mark);
       }
     }
     while (src.remaining() >= 4) {
       cp = getCP(src);
       if (Character.isBmpCodePoint(cp)) {
         if (!dst.hasRemaining()) return CoderResult.OVERFLOW;
         mark += 4;
         dst.put((char) cp);
       } else if (Character.isValidCodePoint(cp)) {
         if (dst.remaining() < 2) return CoderResult.OVERFLOW;
         mark += 4;
         dst.put(Character.highSurrogate(cp));
         dst.put(Character.lowSurrogate(cp));
       } else {
         return CoderResult.malformedForLength(4);
       }
     }
     return CoderResult.UNDERFLOW;
   } finally {
     src.position(mark);
   }
 }