g_regex_new(): Decomposing PCRE regex compile errors


I am interested to decompose PCRE regex compile errors.

Let me explain by example:
Try to compile this regular _expression_ "asdf[" via g_regex_new(), I will receive this error:
Error while compiling regular _expression_ asdf[ at char 5: missing terminating ] for character class
(My locale is some kind of English... British/American/Hongkonger -- LANG=en_HK.UTF-8)

I am interested to decompose this error message into the char (5) and error message (missing terminating ] for character class).

Why?  I have a GUI where user can enter text that is treated as a regular _expression_.
If compile fails, I want to report error to user, but current format is too long.
Specifically, if I could extract the char number, I could point to a specific character in the GUI.
At the moment, I am hacking apart English text, but this is not i18n-friendly.

When I look into git/glib/glib/gregex.c : g_regex_new(), I see this code:
    translate_compile_error (&errcode, &errmsg);

It adds 100 (one hundred) to the PCRE error code and formats a message.

To decompose, what do you recommend?
Two ideas:
(1) Extend (subclass) GError to include additional info -- is this possible?
(2) Create second version of g_regex_new with special return value with decomposed error message

Please advise.  After I read your advice, if necessary, I will create a patch and submit via Bugzilla.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]