public static boolean isValidUtf8(byte[] b,int aMaxCount){
       int lLen=b.length,lCharCount=0;
       for(int i=0;i<lLen && lCharCount<aMaxCount;++lCharCount){
              byte lByte=b[i++];//to fast operation, ++ now, ready for the following for(;;)
              if(lByte>=0) continue;//>=0 is normal ascii
              if(lByte<(byte)0xc0 || lB yte>(byte)0xfd) return false;
              int lCount=lByte>(byte)0xfc?5:lByte>(byte)0xf8?4
                     :lByte>(byte)0xf0?3:lByte>(byte)0xe0?2:1;
              if(i+lCount>lLen) return false;
              for(int j=0;j<lCount;++j,++i) if(b[i]>=(byte)0xc0) return false;
       }
       return true;
}
收藏的一个判断UTF-8的代码

  

 

相关文章:

  • 2022-02-09
  • 2021-11-06
  • 2021-11-17
  • 2021-12-09
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
猜你喜欢
  • 2021-11-06
  • 2021-11-06
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案