00784e5477
- migliorie varie a lettura/scrittura.
95 lines
4.3 KiB
VB.net
95 lines
4.3 KiB
VB.net
Imports System.Text.RegularExpressions
|
|
|
|
Module RegexFunction
|
|
' restituisce vero se trova il capitoletto [Graphic parameters]
|
|
Friend Function IsGraphicParametersTitle(sLine As String) As Boolean
|
|
Return Regex.Match(sLine, "\s*--\s*(\[Graphic parameters\])\s*$").Groups(1).Value = "[Graphic parameters]"
|
|
End Function
|
|
|
|
' restituisce quello che segue l'uguale assegnata una parola chiave tra i due trattini e 'uguale
|
|
Friend Function ParamLine(sLine As String, sKey As String) As String
|
|
Return Regex.Match(sLine, "\s*--\s*(" & sKey & ")\s*=\s*(.*)\s*$").Groups(2).Value
|
|
End Function
|
|
|
|
' toglie il commento da una riga (conservando i metacomandi)
|
|
Friend Function RemoveComment(sLine As String) As String
|
|
sLine = sLine.Replace(DDF_METADATA, "§")
|
|
If sLine.Contains("#"c) Then sLine = Regex.Match(sLine, "\s*(.*?)\s*#.*$").Groups(1).Value
|
|
sLine = sLine.Replace("§", DDF_METADATA)
|
|
Return sLine
|
|
End Function
|
|
|
|
' restituisce quello che segue l'uguale assegnata la parola chiave Err
|
|
Friend Function ErrDraw(sLine As String) As Integer
|
|
Dim sErrMsg As String = Regex.Match(sLine, "\s*(Err)\s*=\s*(.*?\b)\s*$").Groups(2).Value
|
|
' se il valore è numerico allora lo restituisco
|
|
If IsNumeric(sErrMsg) Then
|
|
Return CInt(sErrMsg)
|
|
Else
|
|
' altrimenti restituisco il valore zero (non errore)
|
|
Return 0
|
|
End If
|
|
End Function
|
|
|
|
Friend Function ParamExpression(sLine As String) As String
|
|
Return Regex.Match(sLine, " \s*\(*\s*(.*?\b)\s*\).*$").Groups(1).Value
|
|
End Function
|
|
|
|
' Cerca la stringa con 3 trattini
|
|
Friend Function Search3Hyphens(sLine As String) As Boolean
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return False
|
|
Return Regex.Match(sTmp, "\s*(---).*$").Groups(1).Value = "---"
|
|
End Function
|
|
|
|
' Cerca la stringa con 3 puntini
|
|
Friend Function Search3Dots(sLine As String) As Boolean
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return False
|
|
Return Regex.Match(sTmp, "\s*(...).*$").Groups(1).Value = "..."
|
|
End Function
|
|
|
|
' Cerca la chiave che precede i due punti
|
|
Friend Function SearchKey(sLine As String, sKey As String) As Boolean
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return False
|
|
Return Regex.Match(sTmp, "\s*(" & sKey & ")\s*:.*$").Groups(1).Value = sKey
|
|
End Function
|
|
|
|
' Restituisce la chiave che precede i due punti (elimina gli spazi prima della chiave)
|
|
Friend Function GetKey(sLine As String) As String
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return ""
|
|
Return Regex.Match(RemoveComment(sLine), "\s*(.*?\b)\s*:.*").Groups(1).Value
|
|
End Function
|
|
|
|
' Restituisce il valore associato alla chiave ( key: value)
|
|
Friend Function GetValueWithKey(sLine As String, sKey As String) As String
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return ""
|
|
Return Regex.Match(sTmp, "\s*-*\s*" & sKey & "\s*:\s*(.*?\b)\s*$").Groups(1).Value
|
|
End Function
|
|
|
|
' Restituisce il valore associato ad una chiave non specificata ( unknown_key: value)
|
|
Friend Function GetValueWithoutKey(sLine As String) As String
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) Then Return ""
|
|
Return Regex.Match(sTmp, "\s*:\s*(.*?\b)\s*$").Groups(1).Value
|
|
End Function
|
|
|
|
' Cerca il nome che precede i due punti (tutti i caratteri dall'inizio della stringa)
|
|
Friend Function SearchName(sLine As String, sName As String) As Boolean
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) OrElse Char.IsWhiteSpace(sTmp, 0) Then Return False
|
|
Return Regex.Match(sTmp, "\s*(" & sName & ")\s*:.*$").Groups(1).Value = sName
|
|
End Function
|
|
|
|
' Restituisce il nome che precede i due punti (tutti i caratteri dall'inizio della stringa)
|
|
Friend Function GetName(sLine As String) As String
|
|
Dim sTmp As String = RemoveComment(sLine)
|
|
If String.IsNullOrWhiteSpace(sTmp) OrElse Char.IsWhiteSpace(sTmp, 0) Then Return ""
|
|
Return Regex.Match(RemoveComment(sLine), "\s*(.*?\b)\s*:.*").Groups(1).Value
|
|
End Function
|
|
|
|
End Module
|