WIP: implement case switching as key action - #1383
Conversation
rnpnr
left a comment
There was a problem hiding this comment.
Thanks for this! I will have to test with the previous non-ASCII examples a little later.
This is an quick draft. I have not tested it thoroughly. Especially since I am no encoding expert, I am not sure if the assertion that case switched wchars need the same amount of bytes holds.
I'm not sure either but I suspect its fine. I would just leave it as you wrote until someone reports otherwise. Here are a few other points:
- I do know that the number of wide characters will be strictly less than the number of multibyte characters. Therefore I would prefer if you just did a single allocation for both the wide character buffer and the text buffer with that assumption (i.e. allocate N wide characters for a selection containing N bytes). To avoid an alignment issue put the wide char buffer at the start of the allocation. The NUL termination is not needed in either case, we know both lengths. You don't need to separately measure the wide char string the conversion result will give you the resulting count of wide characters.
- You forgot to free the wide character buffer in the normal case (moot if you do the above suggestion).
- No need to abort for all selections just because one selection contains an illegal sequence.
I do not understand what you mean. How can we reuse the multibyte buffer for our wide-character string? The wide-character string may need more bytes. We could skip the initial counting, if we always allocate N wide-characters for a N byte selection.
Measuring the actual amount of bytes required for the modified wide-character string is indeed unnecessary if your assumption (#bytes == #modified bytes) holds.
|
Currently you do an allocation in Even if you want to ignore the performance implications, doing what I'm suggesting is less error prone because you only need to free a single allocation. |
A now I get it :) |
Use malloc instead of calloc since we only care about a single 0-byte. Since we no longer 0-terminate the wcs the wcstombs(NULL, wcs, 0) call can no longer detect the amount of bytes required by the resulting multibyte string.
rnpnr
left a comment
There was a problem hiding this comment.
I have tested with some non-ASCII and everything seemed fine to me (I can't read the languages I was testing). This is good to go on my end!
Implement case switching internally as key action.
This does no longer rely on piping to external tools and breaking new lines.
This is an quick draft. I have not tested it thoroughly.
Especially since I am no encoding expert, I am not sure if the assertion that case switched wchars need the same amount of bytes holds.
Fixes #1320, #1238.
Supersedes #1381, #1382.