Example #1
0
 public static CodePoint Decode(byte[] buffer, Index index)
 {
     var i = index.index;
     uint x = buffer[i];
     uint code = 0;
     switch (index.byteCount)
     {
         case 1:
             return new CodePoint(x);
         case 2:
             code = x & 0b1_1111;
             code = (code << 6) | (uint)(buffer[++i] & 0b0011_1111);
             return new CodePoint(code);
         case 3:
             code = x & 0b1111;
             code = (code << 6) | (uint)(buffer[++i] & 0b0011_1111);
             code = (code << 6) | (uint)(buffer[++i] & 0b0011_1111);
             return new CodePoint(code);
         case 4:
             code = x & 0b0111;
             code = (code << 6) | (uint)(buffer[++i] & 0b0011_1111);
             code = (code << 6) | (uint)(buffer[++i] & 0b0011_1111);
             code = (code << 6) | (uint)(buffer[++i] & 0b0011_1111);
             return new CodePoint(code);
         default:
             throw new IndexOutOfRangeException();
     }
 }