question about char/wchar/mb utils - Mailing list pgsql-hackers

From Fabien COELHO
Subject question about char/wchar/mb utils
Date
Msg-id Pine.LNX.4.58.0403101248060.32532@sablons.cri.ensmp.fr
Whole thread Raw
Responses Re: question about char/wchar/mb utils
List pgsql-hackers
Hello hackers,

I'm working on a very small patch to add syntax error localisation on the
client side in psql, as it seems to be the place. Something like:

ERROR:  syntax error at character 12345
QUERY: ... WHERE foo IS NUL AND ...
QUERY:                  ^

My current issue is how to build the query excerpt to be displayed.
I'm in the "psql/common.c" file.

The query is a char*, and I guess it is in the client encoding, so that
one character is not one byte.

My first idea was to transform the char into a wchar and then work
directly and simply on the wchar string (to fix tabs and so) ...

However, although I have found a function to build the wchar string
(pg_mb2wchar), I haven't found the reverse (yet) :-(, that is to convert
my wchar extract to a char string compatible with the client encoding.

Is there such a function somewhere? It seems that wchar is a one-way
type, once you're there you're stuck with it:-(

If not, what are the other options?

The issue is to be able to work on a constant width string without having
to care about different mb encodings, otherwise the code is going to be a
little bit tricky... I guess I can do it, but the reverse conversion
function looked more appealing to me;-)

Or am still I off my shoes? (translator: a cote de mes pompes;-);

Thanks, for any advice on this point or others,

have a nice day,

-- 
Fabien Coelho - coelho@cri.ensmp.fr


pgsql-hackers by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Re: [PATCHES] log_line_info
Next
From: Matthew Kirkwood
Date:
Subject: Re: Scalable postgresql using sys_epoll