[Gambas-user] gb.pcre behaviour with Gambas3

Ron ron at ...1740...
Sat Feb 16 20:53:58 CET 2013


Hi,

I noticed that the behavior of the gb.pcre component has changed in
Gambas3 compared to Gambas2.

This use to work:

PRIVATE FUNCTION GetData(sRaw AS String) AS String[]

  DIM rReg AS NEW Regexp
  DIM aMatches AS NEW String[]
  DIM sTmp AS String

  sTmp = sRaw
  rReg.Compile("\x03\x03(\\w+)\r\n")
  rReg.Exec(sTmp)

  DO WHILE rReg.Text <> ""
    aMatches.Add(rReg.Text)
    sTmp = Mid(sTmp, rReg.Offset + 2)
    rReg.Exec(sTmp)
  LOOP

  RETURN aMatches

END

But it doesn't anymore because in Gambas3 when a pattern isn't found
rReg.Text is NULL instead of empty like in Gambas2.
So it errors out because you cannot check a NULL object like this.

It this done by design or a bug?

I change the code to whe one below, which is cleaner, but without
knowing the above it may brake converted programs.

Private Function GetData(sRaw As String) As String[]

  Dim rReg As New Regexp
  Dim aMatches As New String[]
  Dim iCnt As Integer

  rReg.Compile("\x03\x03(\\w+)\r\n")
  rReg.Exec(sRaw)

  For iCnt = 0 To rReg.SubMatches.Count - 1
    aMatches.Add(rReg.SubMatches[iCnt].Text)
  Next

  Return aMatches

End

Regards,
Ron.




More information about the User mailing list