Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   sprintf for utf8 formated characters (http://www.velocityreviews.com/forums/t610048-sprintf-for-utf8-formated-characters.html)

Mandragon03@gmail.com 04-14-2008 08:32 PM

sprintf for utf8 formated characters
 
Anyone know if the standard sprintf supports utf8 characters that
extend beyond the normal ascii characters?

Thanks!

Mandragon03@gmail.com 04-15-2008 09:02 PM

Re: sprintf for utf8 formated characters
 
On Apr 14, 2:39 pm, Michal Nazarewicz <min...@tlen.pl> wrote:
> Mandrago...@gmail.com writes:
> > Anyone know if the standard sprintf supports utf8 characters that
> > extend beyond the normal ascii characters?

>
> That depends on what you mean by "support". If you do thing like:
>
> sprintf(buf, "%s", some_string);
>
> (but never do that unless you are sure buf has enough space) or
> something along the lines of:
>
> sprintf(buf, format, arg1, arg2 /* ... */);
>
> (of course be sure format is valid and buf has enough space) and all
> strings are UTF-8 encoded you'll get UTF-8 encoded string in the end.
> This is guaranteed because UTF-8 is designed in such a way that NUL
> bytes never occur in sequences encoding other characters.
>
> --
> Best regards, _ _
> .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
> ..o | Computer Science, Michal "mina86" Nazarewicz (o o)
> ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--


Thanks for the reply.

What is still left unanswered is whether I can put utf-8 strings (ie
they have characters that take up to 4 bytes of space) and sprint f
that into a string without screwing up the byts of data. So something
like this:

unsigned int myVar= 0xDB0;

convertMyVarToUTF8(myVar);

char buff[512];

sprintf( buff, "Long string with %u", myVar);

is there a legitimate UTF-8 string in buff at this point?

Thanks!

Mandragon


James Kanze 04-15-2008 10:48 PM

Re: sprintf for utf8 formated characters
 
On 15 avr, 23:02, Mandrago...@gmail.com wrote:
> On Apr 14, 2:39 pm, Michal Nazarewicz <min...@tlen.pl> wrote:


[...]
> What is still left unanswered is whether I can put utf-8 strings (ie
> they have characters that take up to 4 bytes of space) and sprint f
> that into a string without screwing up the byts of data. So something
> like this:


> unsigned int myVar= 0xDB0;


> convertMyVarToUTF8(myVar);


> char buff[512];


> sprintf( buff, "Long string with %u", myVar);


> is there a legitimate UTF-8 string in buff at this point?


If the native encoding of narrow character strings is ASCII, or
an encoding which uses ASCII for its lower 128 code points, yes.
Because "%u" will only generated characters in the range
[0-9a-f], and all of those characters have the same encoding in
ASCII and in UTF-8.

However, I suspect that the function convertMyVarToUTF8 is
supposed to do something. But I don't see what, and I don't see
what it could do which would affect the results here.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


All times are GMT. The time now is 04:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.