Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > sprintf for utf8 formated characters

Reply
Thread Tools

sprintf for utf8 formated characters

 
 
Mandragon03@gmail.com
Guest
Posts: n/a
 
      04-14-2008
Anyone know if the standard sprintf supports utf8 characters that
extend beyond the normal ascii characters?

Thanks!
 
Reply With Quote
 
 
 
 
Mandragon03@gmail.com
Guest
Posts: n/a
 
      04-15-2008
On Apr 14, 2:39 pm, Michal Nazarewicz <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      04-15-2008
On 15 avr, 23:02, (E-Mail Removed) wrote:
> On Apr 14, 2:39 pm, Michal Nazarewicz <(E-Mail Removed)> 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:(E-Mail Removed)
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
given char* utf8, how to read unicode line by line, and output utf8 gry C++ 2 03-13-2012 04:32 AM
Convert UNIX formated text files to DOS formated? walterbyrd Python 13 05-13-2009 02:32 PM
UTF8 characters not appearing correctly in email subject line Andee Weir Java 10 08-13-2007 09:02 PM
strings - reading utf8 characters such as japanese. how? stefoid Java 14 07-06-2006 12:10 PM
how to convert characters to upper case in utf8 env. csanjith@gmail.com C Programming 3 03-17-2006 02:23 AM



Advertisments