The Wayback Machine - https://web.archive.org/web/20200701191142/https://github.com/RandyGaul/cute_headers/issues/75
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in null terminator for outputs in cu_shorten/cu_widen in cute_utf.h #75

Open
ddengster opened this issue Dec 15, 2017 · 10 comments
Open

Comments

@ddengster
Copy link

@ddengster ddengster commented Dec 15, 2017

I've been treating tuShorten/tuWiden as a string-ish conversion between UTF16 and UTF 8, so I recommend this.

Here's the code; add it to the end of every tuShorten/tuWiden function.
if (out < (original_out + out_len)) out = 0;

@ddengster
Copy link
Author

@ddengster ddengster commented Dec 15, 2017

Also some feedback regarding your example tuWiden functions in #74 (comment)

The 3rd and the 4th functions are likely going to be the most commonly used ones, the others are subsets of the 3rd and 4th function. I would use the 4th function on say, internal strings that I know are safe, but if I need extra validating (example: non-null terminated text from foreign sources) I can use the 3rd function.

@RandyGaul
Copy link
Owner

@RandyGaul RandyGaul commented Dec 29, 2017

Did you mean:

if (out < (original_out + out_len)) *out = 0;

?

(added *out instead of just out)

@ddengster
Copy link
Author

@ddengster ddengster commented Jan 4, 2018

yes

@shreyabhandare
Copy link

@shreyabhandare shreyabhandare commented Dec 13, 2018

Can i do this one?

@RandyGaul
Copy link
Owner

@RandyGaul RandyGaul commented Dec 13, 2018

Yes of course :)

@shreyabhandare
Copy link

@shreyabhandare shreyabhandare commented Dec 17, 2018

I can't seem to find tinyutf.h and what are tuShorten/tuWiden functions? do I need to read up something before i attempt to do this?

@sro5h
Copy link
Contributor

@sro5h sro5h commented Dec 17, 2018

The prefix of the header files changed to cute, so you‘re looking for cute_utf.h. I can‘t help you with your other question.

@RandyGaul RandyGaul changed the title Add in null terminator for outputs in tuShorten/tuWiden in tinyutf.h Add in null terminator for outputs in cu_shorten/cu_widen in cute_utf.h Dec 17, 2018
@RandyGaul
Copy link
Owner

@RandyGaul RandyGaul commented Dec 17, 2018

Ah yes a while ago I renamed things. The file is cute_utf.h like sro5h mentioned, and the functions are cu_widen and cu_shorten.

https://github.com/RandyGaul/cute_headers/blob/master/cute_utf.h

The widen/shorten functions are used to convert to utf16 and back to utf8 respectively. The docs has some more info on why this conversion is useful (it's just useful for some Windows APIs that need 16-bit characters, aka utf16).

Let me know if you had other questions :)

@shreyabhandare
Copy link

@shreyabhandare shreyabhandare commented Dec 17, 2018

thanks, is there a way to test or build this once i make the changes?

@RandyGaul
Copy link
Owner

@RandyGaul RandyGaul commented Dec 17, 2018

There is a little bit of testing here: https://github.com/RandyGaul/cute_headers/tree/master/test_cute_utf

If you like, you can add more tests in whatever manner you think makes sense. I would be more than happy to incorporate them if you write any down!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.