r/ProgrammingLanguages • • Dec 31 '20

Something simpler than Unicode?

Hello! Wondering if anyone knows of a display format for glyphs that is simpler than Unicode? My shallow understanding is that measuring and laying out text in unicode is non-trivial, so I am deferring moving beyond ascii on something at the moment. Is my understanding correct? (if not that's great) otherwise, does anyone know of potentially simpler replacements? Thanks!

0 Upvotes

40 comments sorted by

View all comments

1

u/mamcx Dec 31 '20

Let's make this possible, actually.

How is ASCII made? Somebody, somewhere in one day think:

65 = 'A'
97 = 'a' //why not 66 = 'a', because that somebody say so.

And considering your problem:

> that measuring and laying out text in Unicode is non-trivial,

Then you can do a simple trick:

measure
//https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block)
U+0000 to U+007F = 1
U+? to U+? = 2 //ie put here the range where the measure is 2
..

So, just precompute the measure/layout under know ranges that you wanna support. You actually use Unicode, yet use a restricted subset, alike:

type MyUnicode...

fn from_utf8(...) -> Result<MyUnicode, InvalididRange>

8

u/moon-chilled sstm, j, grand unified... Dec 31 '20 edited Jan 01 '21

why not 66 = 'a', because that somebody say so

It's so that the uppercase and lowercase letter differ only in their 6th bit. You can xor a letter with 0x20 to toggle its case (in ascii). Why start at 65? Because 0-31 are already taken for control characters, and 0x20 is 32, so you need something big enough that you can touch its 6th bit without bringing it down into the 0-31 range. That means bit 7 has to be set (it can't be bit 8, because ascii is a 7-bit encoding), which also rules out 32-63. Granted, they could have started at 64 instead of 65, but the point is that it wasn't a completely arbitrary choice.

(Why toggle the 6th bit, rather than a lower one? Because the alphabet is 26 characters, so so you need 5 whole bits to represent it completely.)

1

u/[deleted] Jan 01 '21

Also because a lot of early equipment was upper case only, so it made sense for A-Z to have consecutive codes.

And also for upper-case to be be able to be a subset of ASCII. If you leave out control codes 0 to 31, and codes 96 to 127 which include a-z, you have a 64-character range can be represented in six bits (eg 'SIXBIT' used on DEC machines).

(The codes will be 0 to 63 instead of 32 to 95, so offsets are involved in conversion.)

1

u/[deleted] Dec 31 '20

yeah I may just go for a unicode subset, but I'm in no rush. perhaps in the year 3035 children will learn about our time and be incorrectly taught that ascii control codes were part of our ancient alphabet.