【问题标题】:Invalid UTF-8 bytes无效的 UTF-8 字节
【发布时间】:2013-03-10 17:07:10
【问题描述】:

根据Wikipedia

并非所有字节序列都是有效的 UTF-8。 UTF-8 解码器应该是 准备:

1. the red invalid bytes in the above table
2. an unexpected continuation byte
3. a start byte not followed by enough continuation bytes
4. an Overlong Encoding as described above
5. A 4-byte sequence (starting with 0xF4) that decodes to a value greater than U+10FFFF

根据代码页布局,0xC0 和 0xC1 是无效的,并且不能出现在有效的 UTF-8 序列中。这是我为 CodePoints 0xC0 和 0xC1 提供的内容:

Byte 2   Byte 1      Num   Char
11000011 10000000    192   À
11000011 10000001    193   Á

这些字节序列有对应的字符,但不应该有。我做错了吗?

【问题讨论】:

  • 您混淆了代码点和代码单元。
  • 这两行包含 {xc3+x80} -> xc0 -> 192 和 {xc3+x81} -> xc1 ->193(并且您似乎交换了 byte2 和 byte1)
  • @wildplasser,你可以从位序列中猜测。

标签: utf-8 character-encoding


【解决方案1】:

你只是混淆了术语:

代码点 U+00C0 是字符“À”,U+00C1 是“Á”。
以 UTF-8 编码的它们分别是 字节序列 C3 80C3 81

bytes C0C1 不应出现在 UTF-8 编码中。

代码点表示独立于字节的字符。 字节 是字节。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 2018-04-10
    • 2018-12-26
    • 2012-10-16
    • 2013-07-23
    相关资源
    最近更新 更多