instead of using a macro, you could also use a template, which is imho the
better way, since it's a less powerful construct and easier readable:
import unicode
template uc(s: static[string]): Rune =
const runeVal = runeAt(s, 0)
runeVal
Run
Those are very handy idioms to know, thanks!
You can partly achieve this for double quoted strings with the raw string call
syntax:
import unicode
template u(s: string): seq[Rune] =
toRunes(s)
echo u"abcd"
Run
I don't think you can do the same with single quoted strings, however you can
Well, I could just do `Rune('.')` which also works, without the need for
`ord()`, but I'm looking to see if there's something more compact like `u'.'`
or similar.
Since Unicode contains all ASCII characters you can easily do that:
import unicode
let my_rune = Rune(ord('.'))
echo my_rune
Run
If one is looking through Unicode text and wants to compare a given rune with
some literal value like '.' or ',', is there any easy way of declaring ASCII
char values as Rune literals so that they can be compared more readably than
doing `if some_rune == Rune('.')` or similar? Something like