Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-12

WideString and TRegexpr

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

Has anybody with experience of WideStrings tried compiling the "new" Regexpr unit to support them?

I'm in a position where I could very much benefit from using these, but I think that I'm only seeing patterns match for characters <= #$00ff and even then am not seeing the match strings returned.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 6 lines
Has anybody with experience of WideStrings tried compiling the "new" Regexpr unit to support them? I'm in a position where I could very much benefit from using these, but I think that I'm only seeing patterns match for characters <= #$00ff and even then am not seeing the match strings returned.

This appears to be an endianness issue: on a little-endian system (including x86) the Match[] entries only contain the LS byte of a widechar and on a big-endian system (incluing PPC) they only contain the MS byte. Practical result is that things look OK on x86 until the match contains a value > #$00ff.

I'm putting test data together for various CPUs and will raise a bug.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 9 lines
On Thu, Dec 1, 2011 at 7:48 PM, Mark Morgan Lloyd wrote: > Has anybody with experience of WideStrings tried compiling the "new" Regexpr > unit to support them? Which "new" Regexpr? The one in packages/regexpr or another one? I always thought that the one I added was focused on utf-8, although I only used it for ASCII so far.

The Sorokin one. I've been using it for years for ASCII, but it has an internal flag to use widestring:

// ======== Define options for TRegExpr engine
{.$DEFINE UniCode} // Unicode support
..
type
  {$IFDEF UniCode}
  PRegExprChar = PWideChar;
  RegExprString = WideString;
  REChar = WideChar;
  {$ELSE}
  PRegExprChar = PChar;
  RegExprString = AnsiString; //###0.952 was string
  REChar = Char;
  {$ENDIF}

It almost works: Exec() is OK (at least with trunk, I might have seen a problem with a version a few weeks old) but Match[] isn't.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Felipe Monteiro de Carvalho
to Mark Morgan Lloyd

I have no idea about your question, but it might be interresting for you to know, just in case you already don't, the wiki page about the new Regexpr in FPC: http://wiki.lazarus.freepascal.org/Regexpr

It almost works: Exec() is OK (at least with trunk, I might have seen a problem with a version a few weeks old) but Match[] isn't.

That code does not change so often: Last commit in regexpr.pas 3 months ago:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/regexpr/src/

Felipe Monteiro de Carvalho

Reply by email

Frank Church
to Felipe Monteiro de Carvalho

On 3 December 2011 16:29, Felipe Monteiro de Carvalho <

Show quoted text 20 lines
wrote: I have no idea about your question, but it might be interresting for you to know, just in case you already don't, the wiki page about the new Regexpr in FPC: http://wiki.lazarus.freepascal.org/Regexpr > It almost works: Exec() is OK (at least with trunk, I might have seen a problem with a version a few weeks old) but Match[] isn't. That code does not change so often: Last commit in regexpr.pas 3 months ago: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/regexpr/src/ -- Felipe Monteiro de Carvalho _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

I think the wiki entry should contain some more info about the Sorokin regexpr and a link to http://regexpstudio.com/.

There isn't much info about regular expressions on the wiki itself

Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Mark Morgan Lloyd
to Felipe Monteiro de Carvalho: I have no idea about your question, but it might be interresting for you to know, just in…
Felipe Monteiro de Carvalho wrote 9 lines
I have no idea about your question, but it might be interresting for you to know, just in case you already don't, the wiki page about the new Regexpr in FPC: http://wiki.lazarus.freepascal.org/Regexpr > It almost works: Exec() is OK (at least with trunk, I might have seen a problem with a version a few weeks old) but Match[] isn't. That code does not change so often: Last commit in regexpr.pas 3 months ago: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/regexpr/src/

Almost certainly an endianness issue, since ARM behaves the same as x86 (and SPARC behaves the same as PPC).

Reported as issue 0020806. I'm not able to test using a recent Delphi, or on a 64-bit CPU.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Felipe Monteiro de Carvalho
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
Reported as issue 0020806. I'm not able to test using a recent Delphi, or on a 64-bit CPU.
I think you could report directly to sorokin too. If he fixes it, then
we can merge the fix here.

regexpr is a nearly unchanged copy from sorokin, except for the alignment patch which I have sent to sorokin.

Felipe Monteiro de Carvalho

Reply by email

Ludo Brands
to Felipe Monteiro de Carvalho
Show quoted text 10 lines
> Reported as issue 0020806. I'm not able to test using a recent Delphi, > or on a 64-bit CPU. I think you could report directly to sorokin too. If he fixes it, then we can merge the fix here. regexpr is a nearly unchanged copy from sorokin, except for the alignment patch which I have sent to sorokin.

Patch attached to issue. A case of a calling move() with number of chars instead of bytes.

Ludo

Reply by email

Mark Morgan Lloyd
to Ludo Brands
Ludo Brands wrote 12 lines
>> Reported as issue 0020806. I'm not able to test using a > recent Delphi, >> or on a 64-bit CPU. > I think you could report directly to sorokin too. If he fixes > it, then we can merge the fix here. > > regexpr is a nearly unchanged copy from sorokin, except for > the alignment patch which I have sent to sorokin. > Patch attached to issue. A case of a calling move() with number of chars instead of bytes.

OK on SPARC, x86, PPC and ARM (all Linux).

Thanks Ludo and well spotted- I was expecting something horribly computer scienceish :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email