コード例 #1
0
 public void test_isSurrogate() throws Exception {
   assertFalse(Character.isSurrogate('\u0000'));
   assertFalse(Character.isSurrogate('\u0666'));
   assertFalse(Character.isSurrogate((char) (Character.MIN_SURROGATE - 1)));
   for (char ch = Character.MIN_SURROGATE; ch <= Character.MAX_SURROGATE; ++ch) {
     assertTrue(Character.isSurrogate(ch));
   }
   assertFalse(Character.isSurrogate((char) (Character.MAX_SURROGATE + 1)));
 }
コード例 #2
0
    private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
      char[] sa = src.array();
      int sp = src.arrayOffset() + src.position();
      int sl = src.arrayOffset() + src.limit();

      byte[] da = dst.array();
      int dp = dst.arrayOffset() + dst.position();
      int dl = dst.arrayOffset() + dst.limit();
      int len = Math.min(dl - dp, sl - sp);

      while (len-- > 0) {
        char c = sa[sp];
        int b = encode(c);
        if (b == UNMAPPABLE_ENCODING) {
          if (Character.isSurrogate(c)) {
            if (sgp == null) sgp = new Surrogate.Parser();
            if (sgp.parse(c, sa, sp, sl) < 0) {
              return withResult(sgp.error(), src, sp, dst, dp);
            }
            return withResult(sgp.unmappableResult(), src, sp, dst, dp);
          }
          return withResult(CoderResult.unmappableForLength(1), src, sp, dst, dp);
        }
        da[dp++] = (byte) b;
        sp++;
      }
      return withResult(sp < sl ? CoderResult.OVERFLOW : CoderResult.UNDERFLOW, src, sp, dst, dp);
    }
コード例 #3
0
 protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
   int mark = src.position();
   if (!doneBOM && src.hasRemaining()) {
     if (dst.remaining() < 4) return CoderResult.OVERFLOW;
     put(BOM_BIG, dst);
     doneBOM = true;
   }
   try {
     while (src.hasRemaining()) {
       char c = src.get();
       if (!Character.isSurrogate(c)) {
         if (dst.remaining() < 4) return CoderResult.OVERFLOW;
         mark++;
         put(c, dst);
       } else if (Character.isHighSurrogate(c)) {
         if (!src.hasRemaining()) return CoderResult.UNDERFLOW;
         char low = src.get();
         if (Character.isLowSurrogate(low)) {
           if (dst.remaining() < 4) return CoderResult.OVERFLOW;
           mark += 2;
           put(Character.toCodePoint(c, low), dst);
         } else {
           return CoderResult.malformedForLength(1);
         }
       } else {
         // assert Character.isLowSurrogate(c);
         return CoderResult.malformedForLength(1);
       }
     }
     return CoderResult.UNDERFLOW;
   } finally {
     src.position(mark);
   }
 }
コード例 #4
0
  private boolean _isValidXmlCharacter(char c) {
    if (((c >= CharPool.SPACE) && (c <= '\ud7ff'))
        || ((c >= '\ue000') && (c <= '\ufffd'))
        || Character.isSurrogate(c)
        || (c == CharPool.TAB)
        || (c == CharPool.NEW_LINE)
        || (c == CharPool.RETURN)) {

      return true;
    }

    return false;
  }
コード例 #5
0
 private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
   int mark = src.position();
   try {
     while (src.hasRemaining()) {
       char c = src.get();
       int b = encode(c);
       if (b == UNMAPPABLE_ENCODING) {
         if (Character.isSurrogate(c)) {
           if (sgp == null) sgp = new Surrogate.Parser();
           if (sgp.parse(c, src) < 0) return sgp.error();
           return sgp.unmappableResult();
         }
         return CoderResult.unmappableForLength(1);
       }
       if (!dst.hasRemaining()) return CoderResult.OVERFLOW;
       dst.put((byte) b);
       mark++;
     }
     return CoderResult.UNDERFLOW;
   } finally {
     src.position(mark);
   }
 }
コード例 #6
0
 /*     */ protected CoderResult encodeLoop(
     CharBuffer paramCharBuffer, ByteBuffer paramByteBuffer) {
   /* 146 */ int i = paramCharBuffer.position();
   /* 147 */ if ((!this.doneBOM) && (paramCharBuffer.hasRemaining())) {
     /* 148 */ if (paramByteBuffer.remaining() < 4) /* 149 */ return CoderResult.OVERFLOW;
     /* 150 */ put(65279, paramByteBuffer);
     /* 151 */ this.doneBOM = true;
     /*     */ }
   /*     */ try {
     /* 154 */ while (paramCharBuffer.hasRemaining()) {
       /* 155 */ char c1 = paramCharBuffer.get();
       /*     */ CoderResult localCoderResult2;
       /* 156 */ if (!Character.isSurrogate(c1)) {
         /* 157 */ if (paramByteBuffer.remaining() < 4) /* 158 */ return CoderResult.OVERFLOW;
         /* 159 */ i++;
         /* 160 */ put(c1, paramByteBuffer);
         /* 161 */ } else if (Character.isHighSurrogate(c1)) {
         /* 162 */ if (!paramCharBuffer.hasRemaining()) /* 163 */ return CoderResult.UNDERFLOW;
         /* 164 */ char c2 = paramCharBuffer.get();
         /*     */ CoderResult localCoderResult4;
         /* 165 */ if (Character.isLowSurrogate(c2)) {
           /* 166 */ if (paramByteBuffer.remaining() < 4) /* 167 */ return CoderResult.OVERFLOW;
           /* 168 */ i += 2;
           /* 169 */ put(Character.toCodePoint(c1, c2), paramByteBuffer);
           /*     */ } else {
           /* 171 */ return CoderResult.malformedForLength(1);
           /*     */ }
         /*     */ }
       /*     */ else {
         /* 175 */ return CoderResult.malformedForLength(1);
         /*     */ }
       /*     */ }
     /* 178 */ return CoderResult.UNDERFLOW;
     /*     */ } finally {
     /* 180 */ paramCharBuffer.position(i);
     /*     */ }
   /*     */ }