19

Reading the Wikipedia article on UTF-8, I've been wondering about the term overlong. This term is used various times but the article doesn't provide a definition or reference for its meaning.

I would like to know if someone can explain the term and its purpose.

Stuart Cook
  • 3,994
  • 25
  • 23
nEAnnam
  • 1,246
  • 2
  • 16
  • 22

2 Answers2

20

It's an encoding of a code point which takes more code units than it needs to.

For example, U+0020 is represented in UTF-8 by the single byte 0x20. If you decode the two bytes 0xc0 0xa0 in the normal fashion, you'll still end up back at U+0020, but that's an invalid representation.

The Unicode Corrigendum #1 has more information, particularly around table 3.1B.

Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
6

UTF-8 theoretically allows for different representations of characters that also have a shorter one. For example, you could encode an ASCII character in two bytes by setting the MSBs to zero. The UTF-8 specification explicitly forbids this.

Joey
  • 344,408
  • 85
  • 689
  • 683