Bug: Save game > filename caret is misaligned
DanSorrell opened this issue · 3 comments
DanSorrell commented
./src/uqm/gameopt.c
static BOOLEAN
DrawSaveNameString (UNICODE *Str, COUNT CursorPos, COUNT state, COUNT gameIndex)
{
Currently line 494 ...
Change this:
FullCursorPos = CursorPos + (COUNT)strlen(dateStr) - 1;
To this:
FullCursorPos = CursorPos + (COUNT)strlen(dateStr);
JHGuitarFreak commented
DanSorrell commented
My initial, low effort, analysis started with me implementing the ISO date format in my local copy of the game’s code:
I then “fixed” the caret on my end by deleting the minus one. The real solution is to change the line to:
FullCursorPos = CursorPos + (COUNT)utf8StringCount(dateStr);
Explanation:
- Caret positioning is based on the count of code points, not the count of bytes.
- utf8StringCount() within ./src/libs/strings/unicode.c counts code points.
- strlen() within C’s standard lib counts bytes.
- The middle-dot (code point 183) separator within the date strings is 2 bytes wide in utf-8.
- The default date format of “MMM DD·YYYY” has one middle-dot making the string’s byte count longer than its code-point count by one. Somebody arbitrarily subtracted one to resolve the difference.
- Two of the date formats have 2 middle-dots. These require a subtraction of 2 to work properly.
- My ISO implementation has the same count of bytes as its count of code points. So this requires a subtraction of zero to work properly.
JHGuitarFreak commented
Ah, there we go, I knew there had to be a more elegant solution.
Implemented in commit 4e12529

