|
'
' Arguments class: application arguments interpreter
'
' Authors: R. LOPES
' Contributors: Hastarin, E. Marcon (VB version)
' Created: 25 October 2002
'
' Version: 1.0
'/
Imports System
Imports System.Collections.Specialized
Imports System.Text.RegularExpressions
Namespace CommandLine.Utility
Public Class Arguments
Inherits StringDictionary
Dim lastName As String = Nothing
Dim trimChars As Char() = {Chr(34), Chr(39)}
Public nameValueRegex As New Regex("^([/-]|--){1}(?<name>\w+)([:=])?(?<value>.+)?$", RegexOptions.Compiled)
Sub New(ByVal args As String())
' Constructor
' Valid parameters forms:
' {-,/,--}param{ ,=,:}((",')value(",'))
' Examples: -param1 value1 --param2 /param3:"Test-:-work" /param4=happy -param5 '--=nice=--'
Dim arg As String
Dim match As Match
For Each arg In args
match = nameValueRegex.Match(arg)
If match.Success Then
lastName = match.Groups("name").Value
Add(lastName, match.Groups("value").Value.Trim(trimChars))
Else
' Found a value (for the last parameter found (space separator))
If Not (lastName Is Nothing) Then
' Matched a name, optionally with inline value
Me.Item(lastName) = arg.Trim(trimChars)
End If
End If
Next arg
End Sub
End Class
End Namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.