mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-20 09:49:46 +02:00
Configuration
Core
Controls
Handling
Other
Utils
BrowserCache.cs
BrowserUtils.cs
CommandLineArgsParser.cs
HardwareAcceleration.cs
NativeMethods.cs
WindowState.cs
FormBrowser.Designer.cs
FormBrowser.cs
FormBrowser.resx
FormNotification.Designer.cs
FormNotification.cs
TrayIcon.Designer.cs
TrayIcon.cs
Libraries
Migration
Plugins
Properties
Resources
Updates
.gitignore
LICENSE.md
Program.cs
README.md
TweetDck.csproj
TweetDck.sln
_postbuild.bat
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace TweetDck.Core.Utils{
|
|
static class CommandLineArgsParser{
|
|
private static Regex splitRegex;
|
|
|
|
private static Regex SplitRegex{
|
|
get{
|
|
return splitRegex ?? (splitRegex = new Regex(@"([^=\s]+(?:=(?:""[^""]*?""|[^ ]*))?)", RegexOptions.Compiled));
|
|
}
|
|
}
|
|
|
|
public static int AddToDictionary(string args, IDictionary<string, string> dictionary){
|
|
if (string.IsNullOrWhiteSpace(args)){
|
|
return 0;
|
|
}
|
|
|
|
int count = 0;
|
|
|
|
foreach(Match match in SplitRegex.Matches(args)){
|
|
string matchValue = match.Value;
|
|
|
|
int indexEquals = matchValue.IndexOf('=');
|
|
string key, value;
|
|
|
|
if (indexEquals == -1){
|
|
key = matchValue.TrimStart('-');
|
|
value = "1";
|
|
}
|
|
else{
|
|
key = matchValue.Substring(0, indexEquals).TrimStart('-');
|
|
value = matchValue.Substring(indexEquals+1).Trim('"');
|
|
}
|
|
|
|
if (key != string.Empty){
|
|
dictionary[key] = value;
|
|
++count;
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
}
|
|
}
|