tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: print encoded string on stdout
On Mon, 12 Jan 2009, Hubert Feyrer wrote:
>
> Am 12.01.2009 um Mo, 12. 01 2009, 21:06 schrieb Iain Hibbert:
> > I am given a data buffer (const, not nul terminated) claiming to contain
> > an encoded text string and I know the language & encoding (likely "en" &
> > "UTF-8" but no guarantee) and I want to safely display this string on
> > stdout.
> >
> > I'm frankly lost in a maze of twisty manpages (and, although there was
> > some massive citrus update recently I've not caught up yet), probably I
> > need mbstowcs() and a wprintf() but I'm typically ignorant ASCII user.
> >
> > How do I do this, is there any simple example I could look at?
>
> Just printf it, and hope that the displaying terminal will do the work for
> you?
> :-)
In essence that is what my initial hack does, though I filtered with
isprint():
static void
print_string(sdp_data_t *data)
{
char buffer[50];
sdp_data_t str;
int n;
if (!sdp_get_str(data, &str))
return;
if (encoding != NULL)
printf("(%s) ", encoding);
for (n = 0; n < sizeof(buffer) && str.next + n < str.end; n++)
buffer[n] = (isprint(str.next[n]) ? str.next[n] : '.');
printf("\"%.*s\"\n", n, buffer);
}
I was just hoping for something a little more flexible as I suppose that
won't work with japanese for instance?
iain
Home |
Main Index |
Thread Index |
Old Index