4 ms·
NUL, DEL and ESC are control characters. > For example it's common to define some sort of sub-string function substr(string, A, B) and say that A and B are ind
by kazinator 4y ago
NUL, DEL and ESC are control characters.
> For example it's common to define some sort of sub-string function substr(string, A, B) and say that A and B are indexes into the code points. But, to what end?
Right; this is what I'm getting at. substr(str, A, B) is a low level function: a servant. A and B have a meaning somewhere, but not to this routine.
substr does not need to know what the indices mean. The indices could mean "start and end of a file suffix" or "third field in a line of CSV", or "integer part of floating-point token".
Software is layered and not all the semantics can be known to every layer. Usually when we have semantic leakage/sharign across crossings, it's for some optimization purpose.
For instance, the ethernet driver and hardware don't know that the frames passing through them are IP or whatever else. (Though, for instance, when you have TCP offloading to the hardware, then the hardware groks that semantics info.)
- tialaramex 4y ago> NUL, DEL and ESC are control characters. You have confused nomenclature for category. Thus begging the question. > Right; this is what I'm getting at. substr(str, A, B) is a low level function: a servant. A and B have a meaning somewhere, but not to this routine. For the purpose you're talking about the code point index is completely irrelevant, and so the byte index works fine here.
- kazinator 4y agoA character isn't just something that produces a picture, and advances the printing position to the right. Yes, a byte index will work if we have a multi-byte string such as UTF-8; and a code point index would be inconvenient since displacement calculations on it are meaningless. If we are talking about a string as an array of code points (like a wchar_t * string on sane platforms where a wchar_t can hold any code point) then we use code point indexing. C has wmemcpy, wmalloc, wstrlen, ...
- spc476 4y agoI have a graphical window, and I have a bunch of text (in whatever Unicode encoding you want---it doesn't matter to me) that I need to display in said graphical window such that the text just doesn't run off one edge of the window and can't be read. How do I break the text up into segments that will fit within the horizontal width of the graphical window without changing the meaning of any of the text? Fourty years ago I could assume ASCII and be done with it. These days? With the yearly changes to the "Rules of Unicode"? Screw that, let's build a self-landing rocket which appears to be easier these days than actually displaying text.
- kazinator 4y ago> How do I break the text up into segments that will fit within the horizontal width of the graphical window without changing the meaning of any of the text? This is language dependent. For instance, the Japanese don't care. I was reading a novel a few months ago, and a chapter ended in a sentence ending in "た。" (ta.) due to some past tense verb. This "た。" did not fit, and so was just punted to the next page, which was otherwise entirely blank. There is no concept of hyphenation. So if the text is Japanese, you just chop it into the required line length, and you're pretty much done; no hyphenation is required, no multi-pass breaking algorithm to create an evenly gray page, nothing.