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 ' restituisce il nome del modello Friend Function ModelTemplate(sLine As String) As String Dim Model As String = Regex.Match(sLine, "\s* (Compo)\s*\/\s*(.*?\b)\s*$").Groups(2).Value If Not String.IsNullOrEmpty(Model) Then Return Model Else Model = Regex.Match(sLine, "\s*(Compo)\s*\\\s*(.*?\b)\s*$").Groups(2).Value End If If Not String.IsNullOrEmpty(Model) Then Return Model Else Return sLine End If End Function ' dato il direttorio restituisce il nome del file Friend Function SubStractDirFromPath(sLine As String, sLastDir As String) As String Dim Model As String = Regex.Match(sLine, "\s*(" & sLastDir & ")\s*\/\s*(.*?\b)\s*$").Groups(2).Value If Not String.IsNullOrEmpty(Model) Then Return Model Else Model = Regex.Match(sLine, "\s*(" & sLastDir & ")\s*\\\s*(.*?\b)\s*$").Groups(2).Value End If If Not String.IsNullOrEmpty(Model) Then Return Model Else Return sLine 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*(.*?)\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*(.*?)\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 ' estrae da una riga lua il contenuto scommentato Friend Function RemoveCommentLUA(sLine As String) As String If sLine.Contains("--") Then sLine = Regex.Match(sLine, "\s*(.*?)\s*--.*$").Groups(1).Value Return sLine End Function Friend Function GetNameParamInFileTempl(sLine As String) As String If sLine.Contains("%") Then sLine = Regex.Match(sLine, "\s*\%*\s*(.*?)\s*\%.*$").Groups(1).Value : Return sLine Return String.Empty End Function End Module