Scoring Code Points
When we last saw our heroine, she was finishing up the story for 1 November and breathing deep sighs of relief that it was, in fact, not going to be five thousand pages long and unfinishable in the allotted timespan. She then took a day or two to rest and begin putting together a quick and nasty little Hallowe'en story.
Then, today, she actually did some work. Pay work, that is. Day work. Or, as I sometimes say, workwork.
My codebase has had a problem with extended character translation for many years now. I may even have written about it. I bet somewhere in the Dredge (no, I haven't forgotten the Dredge; we'll come back to it, never fear) there's at least one rant about how the whole fucking thing is unmanageable and makes no sense.
Today I took a major step toward getting everything into some kind of stable, maintainable, fully-working condition for the first time in ... well, ever. This situation has been a mess of duct-tape patches, baling wire, and Band-Aids for more than a decade.
Mostly it's because I've had a solution that was Working Adequately and, as you know, in a world where the developer spends a lot of her time fighting fires (and is also fundamentally a lazy bitch), the things that are Working Adequately almost never get the grease and time they need to convert to Working Well, because all the time is instead spent dealing with things which are Actually Broken. Thus it was here.
Also, the whole thing doesn't make a lot of sense. I've been hours down a rabbit hole about it today and it still doesn't make sense. I know more than I did, and I still don't understand it.
So, let's take a special character that is likely to occur in people's names if they aren't in America and thus haven't largely discarded all this crap. ("Whut are you, some kinda furriner? In The US of A we use the twenty-six letters god give us, dadgum it, and we don't truck with that fancy stuff!")
Let's consider the e-acute. ( é )
Because I've had to do it about thirty times today, I have finally memorized the keys for pulling up Windows' little dialog for inserting special characters, and thus I have inserted the one above directly. I don't know whether it will survive the editor and then being displayed in HTML on the finished page; if you don't see something inside those parentheses, or you see garbage, you'll know why. My cautious habit, because I grew up in the B.U. era -- Before Unicode -- would be to physically type é instead, an HTML "entity" which is a way of putting in special characters by description, in a way that is safe from mangling.
(Note, though, that method doesn't work in URLs, which have an entirely different way of typing special characters to make them safe from mangling.)
(Note also that what I actually typed -- with spaces inserted so you can see the play-by-play -- was
& a m p ; e a c u t e ;
See, the & a m p ; part is the HTML entity for ampersand; otherwise, & e a c u t e ; would be displayed just like an actual e-acute when showing the HTML page, and you wouldn't get to see what the entity looks like. You'd just see an e-acute character. The way I did it, the & a m p ; gets translated into an ampersand and you see what I want you to see ... but note that I can't edit the page after that without taking care, because my editor has a bad habit of translating the escapes/entities into the actual things they are representing, and ... eh, you know what, this is too much of a digression already. One day I'll talk about the Problem With Wikipedia URLs and then we'll go into it again. I can tell you're on the edge of your seat with anticipation.)
& a m p ; e a c u t e ;
See, the & a m p ; part is the HTML entity for ampersand; otherwise, & e a c u t e ; would be displayed just like an actual e-acute when showing the HTML page, and you wouldn't get to see what the entity looks like. You'd just see an e-acute character. The way I did it, the & a m p ; gets translated into an ampersand and you see what I want you to see ... but note that I can't edit the page after that without taking care, because my editor has a bad habit of translating the escapes/entities into the actual things they are representing, and ... eh, you know what, this is too much of a digression already. One day I'll talk about the Problem With Wikipedia URLs and then we'll go into it again. I can tell you're on the edge of your seat with anticipation.)
OK, an e-acute is actually stored/represented as an E9 in hexadecimal. Hexadecimal is used here because it means we can represent a byte (any value from 0 to 255) as two "digits" -- digits in quotes because they're sometimes letters. It's just base sixteen, which means you have to use letters because you need extra digits. [mimes counting on fingers except I have eight fingers on each hand] 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10! (I pretty much can think in hex at this stage in my misspent life, but I try to explain that every time because I've learned how weird laypeople find it.)
So it's 233 decimal, and E9 hex ... except, uh, a little math will make you realize that if you store characters using only one byte, you are not going to be able to store more than 255 characters. Unicode has thousands of characters.
When I was a child, B.U., if you had to work in Chinese or Japanese these required special tools to work in what we called "double-byte" characters, which meant what it said; you needed two bytes to store each character. (And there was inevitably fuss, because some systems felt the first byte should be the high end and some felt it should be the low end; that is, if your character is 01 A1, is that 01A1 = 417, or A101 = 41217?)
Nowadays, everything is a double-byte character. Or a triple-byte character. Maybe even a quadruple-byte character. In an effort to get Every Single Character Ever Conceived Into A Unified Ordinal Space, the Unicode people require lots of numbers.
Anyway, so, read this:
The character é is Unicode code point U+00E9; in UTF-8 that is the two bytes C3 A9 ... The critical detail people get wrong is stage one. The code point of é is U+00E9, decimal 233, which fits in a single byte -- so it is tempting to write %E9. That is Latin-1 encoding, not UTF-8. In UTF-8, every character above U+007F is stored as multiple bytes, and U+00E9 becomes C3 A9. Encode the bytes UTF-8 produces, never the raw code-point value.
That's from a web page I consulted earlier today. If you think that makes no fucking sense, I am here to tell you that I have been writing code as a steady occupation since I was a teenager and I am now pushing sixty and it makes no fucking sense. Maybe I'm just too old for it to make sense. I also still know what a carburetor is.
OK, so, my problem is I have to shove data between about six different data systems -- that is, in a nutshell, my job -- using a local DB of my own as a holding pen and accumulation point. That Oracle DB grabs "upstream" data from various master sources, coagulates it, munges it, accumulates it, etc and spits it out for the use and benefit of various "downstream" clients, mostly web pages. And in the process, I have to translate special characters. Mostly in people's names. They get kind of picky about this (and with justification; if you leave out the special characters it means you're mispronouncing their names, and people hate it when you do that).
And it's been a mess. So much so that in some places these special characters have been getting omitted or "normalized" (that is, the e-acute turns into a normal e, the o-umlaut loses its umlaut, etc) because the translation was dodgy and it was deemed better to have the slight misspelling than have an unreadable garbage character in the middle of the name.
In recent years I have been trying as hard as I can to get away from my own ad-hoc solutions and just try to standardize. UTF-8, which is to say, realio trulio Unicode, everywhere. Nothing but. And I've had some success, but other parts have been frustrating and unsolved for years. I have a set of web pages where these extended characters show up as garbage. Always. Why? The web pages are set to use UTF-8. The HTTP header says "UTF-8, bitches." Across the board. But characters are still getting mangled. I have taken pains to set the NLS_LANG environment variable everywhere (this is the Oracle "what character set are you using" variable). Still getting mangled.
Well. Turns out.
I did a deep dive today into Oracle docs and helpful ancillary pages. Oracle docs are some of the worst in the world, so it's become a religious-text situation; the Oracle docs are the Torah, and a lot of other people have developed a Talmud around it, writing commentary and real instructions and interpretation -- "OK, so this is what they mean when they say this."
The NLS_LANG variable is to tell Oracle what codeset the client is using. It's not a "Hey, Oracle, do this." It's "Hey, Oracle, this is what we're using, please adjust your output accordingly." And while there was certainly something to be gained by setting that everywhere, the output usually still required another encoding step ... leaving me frustrated why I would need to encode something as UTF-8 that was already supposed to be in UTF-8.
Once I learned what NLS_LANG was really for, the obvious next step was to descend way into the bowels of my Oracle database and ask it timidly "OK, so, uh, what character encoding do you think you're using?"
Hint: It's not UTF-8.
This is a design decision of this particular database which precedes me. It was actually a design choice made by the previous DBA, and when I say "the previous DBA" you need to understand that she handed the entire database to me and went off to other things nearly twenty years ago. She had absolutely no reason to know or believe back then that she was creating technical debt for me by not making that DB Unicode-aware. In 2006 only a handful of zealots were Unicode-aware, and they were mostly regarded as the kind of people where you'd cross to the other side of the street if you saw them walking toward you.
The bad news is that changing the character set of an Oracle database -- and it's a whole-DB thing, you can't do it on a by-schema or by-table basis -- is the kind of Deep DBA Stuff which I find very daunting, especially when it comes with warnings like "scan your DB and back it up first." (There's a valid reason, not worth going into here.) I am not prepared to contemplate that at this time; I just want people to have their accent marks everywhere so they'll stop yelling.
The good news is, now that I know what Oracle's problem is, I can work around it consistently everywhere. I just have to make sure I do UTF-8 translation even in places I wouldn't have thought it necessary. (I did it on the output for one of those mangled web pages today and -- poof! -- no longer mangled.)
It is not a complete solution. Oracle's character set only handles the "Latin-1" codepage. It'll deal perfectly fine with the most common special characters, the ones found in names, but you can throw it a curve ball and it'll mangle it. For example, the guy who wanted Chinese characters in some of his text. He is out of luck for the time being. Not supported. (He didn't want the whole text in Chinese; he just wanted the "mountain water" characters in one place for reasons.)
One day I will be ready to take another dive into this insanity and possibly change my database over. But, based on previous track record, I will need at least another six months to recuperate from this bout before I do.
I tell you again, if everybody'd just speak Amurrican we wouldn't have any trouble. ASCII was good enough for grandpa, by golly!
26 October 2026
