Advertisement
Linda-chan

AJPapps - Parse templates [Extract]

Jul 26th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '====================================================================
  2. Private Function GetMatches(ByRef Data As WORK_DATA) As Boolean
  3.   Dim RE As New RegExp
  4.  
  5.   On Error Resume Next
  6.  
  7.   RE.Global = True
  8.   RE.IgnoreCase = True
  9.   RE.MultiLine = True
  10.  
  11.   RE.Pattern = "(/\*@ )(.*?)( @\*/ )(.*?)( /\*@\*/)"
  12.   Set Data.Matches = RE.Execute(Data.Text)
  13.  
  14.   If Err.Number <> 0 Then
  15.     ajpErr.ErrorDisplay Err, vbCritical, , "Не удалось распарсить текст файла."
  16.     GetMatches = False
  17.   Else
  18.     GetMatches = True
  19.   End If
  20. End Function
  21.  
  22. '====================================================================
  23. Private Function ModifyText(ByRef Data As WORK_DATA) As Boolean
  24.   Dim TMP As Long
  25.   Dim NewValue As BStr
  26.   Dim OldText As BStr
  27.  
  28.   OldText = Data.Text
  29.  
  30.   For TMP = Data.Matches.Count - 1 To 0 Step -1
  31.     NewValue = Data.Matches(TMP).SubMatches(0) & _
  32.                Data.Matches(TMP).SubMatches(1) & _
  33.                Data.Matches(TMP).SubMatches(2) & _
  34.                ApplyVariable(Data.Matches(TMP).SubMatches(1), Data) & _
  35.                Data.Matches(TMP).SubMatches(4)
  36.    
  37.     'MsgBox "*** Before:" & CRLFCRLF & _
  38.            Mid(Data.Text, Data.Matches(TMP).FirstIndex + 1, Data.Matches(TMP).Length) & CRLFCRLF & _
  39.            "*** After:" & CRLFCRLF & _
  40.            NewValue
  41.    
  42.     Data.Text = Left(Data.Text, Data.Matches(TMP).FirstIndex) & NewValue & _
  43.                 Mid(Data.Text, Data.Matches(TMP).FirstIndex + Data.Matches(TMP).Length + 1)
  44.   Next TMP
  45.  
  46.   Data.TextWasModified = CBool(Data.Text <> OldText)
  47.   ModifyText = True
  48. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement