savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
155 stars 12 forks source link

Add `Integer.Format.ASCII` to format `U8`... as ASCII character(s) #350

Closed mneumann closed 1 year ago

mneumann commented 1 year ago

Ideally, we'd have a separate Char or Rune type.

Use case: Display Postgres frame types, e.g. 'F' as 'F' and not as 70.

frame_type U8 = 'F'
env.out.print("Frame type \( frame_type.format.ascii )")
jemc commented 1 year ago

I like this idea, but I think we should go further and make it able to format any Unicode codepoint, including those beyond the ASCII range. So you can take any codepoint value and put it into a string.

Thus we'd probably name it something like .format.unicode instead of .format.ascii, and it would use the existing _UTF8Encoder.encode function that we already have in the core library.

What do you think?