private void SetVarCommand (string line) {
var regSetVar = new Regex (@"^:setvar\s+(?<name>[\w_-]+)(?:\s+(?<value>[^\s]+))?", RegexOptions.IgnoreCase);
MatchCollection matchSetVar = regSetVar.Matches (line);
if (1 != matchSetVar.Count) {
throw new SqlCmdSetVarSyntaxException (line);
}
Match m = matchSetVar [0];
Group variableGroup = m.Groups ["name"];
Debug.Assert (variableGroup.Success);
Group valueGroup = m.Groups ["value"];
if (valueGroup.Success) {
// Strip double quotations from beginning
string value = valueGroup.Value;
if (value.StartsWith("\""))
{
value = value.Substring(1);
}
// Strip double quotations from end
if (value.EndsWith("\""))
{
value = value.Substring(0, value.Length - 1);
}
Environment.Variables [variableGroup.Value] = value;
} else {
Environment.Variables.Remove (variableGroup.Value);
}
}