comp.lang.ada
 help / color / mirror / Atom feed
* gnat_regpat and unexpected handling of alnum and unicode needed
@ 2019-02-17 11:24 19.krause.70
  2019-02-17 12:50 ` Simon Wright
  2019-02-17 13:09 ` 19.krause.70
  0 siblings, 2 replies; 5+ messages in thread
From: 19.krause.70 @ 2019-02-17 11:24 UTC (permalink / raw)


Hello All,

I was strugeling about a behavior in gnat-repat which is different from the behavior of egrep for example and different from the behavior I expect.

The expression [[:alnum:]] matches the underscore in gnat_regpat but not in egrep. It feels much more natural to don't match the underscore like egrep does. And I think it is more posix compliant.

Question is why?

Now I could simply use [[:alpha:][0-9]]+ instead but then I got to my second question: How do I handle unicode strings with gnat_regpat, because [[:alpha:]] seems to match only ascii a-zA-Z. Some sample code (Safe as utf-8 text, compiled with -gnatW8):

with Ada.Text_IO;
with Gnat.Regpat;

procedure gnat_regpat_test is
    test1 : constant String := "foo_bar";
    test2 : constant String := "fööbär";
    regexp1 : constant String := "^[[:alnum:]]+$";
    regexp2 : constant String := "^[[:alpha:][0-9]]+$";
begin
    if Gnat.Regpat.Match(Expression => regexp1, Data => test1) then
        Ada.Text_IO.Put_Line(test1 & " Matched regexp1 " & regexp1 & "!");
    else
        Ada.Text_IO.Put_Line(test1 & " doesn't Match regexp1 " & regexp1);
    end if;
    if Gnat.Regpat.Match(Expression => regexp2, Data => test1) then
        Ada.Text_IO.Put_Line(test1 & " Matched regexp2 " & regexp2 & "!");
    else
        Ada.Text_IO.Put_Line(test1 & " doesn't Match regexp2 " & regexp2);
    end if;
    if Gnat.Regpat.Match(Expression => regexp1, Data => test2) then
        Ada.Text_IO.Put_Line(test2 & " Matched regexp1 " & regexp1 & "!");
    else
        Ada.Text_IO.Put_Line(test2 & " doesn't Match regexp1 " & regexp1);
    end if;    
    if Gnat.Regpat.Match(Expression => regexp2, Data => test2) then
        Ada.Text_IO.Put_Line(test2 & " Matched regexp2 " & regexp2 & "!");
    else
        Ada.Text_IO.Put_Line(test2 & " doesn't Match regexp2 " & regexp2);
    end if;    
end gnat_regpat_test;

Best Regards,

Hubert

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-17 13:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-17 11:24 gnat_regpat and unexpected handling of alnum and unicode needed 19.krause.70
2019-02-17 12:50 ` Simon Wright
2019-02-17 13:15   ` 19.krause.70
2019-02-17 13:21   ` 19.krause.70
2019-02-17 13:09 ` 19.krause.70

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox