mirror of
https://github.com/chylex/Query.git
synced 2025-08-16 23:31:42 +02:00
AppCalc
AppConv
AppMeme
AppWindows
Base
Utils
Base.csproj
Command.cs
CommandEventArgs.cs
CommandException.cs
IApp.cs
MatchConfidence.cs
Calculator
Query
.gitignore
Directory.Build.props
Query.sln
icon.ico
37 lines
920 B
C#
37 lines
920 B
C#
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using Base.Utils;
|
|
|
|
namespace Base;
|
|
|
|
public sealed class Command(string text) {
|
|
private static readonly Regex RegexBalancedBrackets = new (RegexUtils.Balance(@"\[", @"\]"), RegexOptions.Compiled);
|
|
private static readonly Regex RegexBalancedParentheses = new (RegexUtils.Balance(@"\(", @"\)"), RegexOptions.Compiled);
|
|
|
|
public string Text { get; } = text;
|
|
|
|
public string? PotentialAppName {
|
|
get {
|
|
int firstSpace = Text.IndexOf(' ');
|
|
|
|
if (firstSpace == -1) {
|
|
return null;
|
|
}
|
|
|
|
string firstToken = Text[..firstSpace];
|
|
|
|
if (!firstToken.All(char.IsLetter)) {
|
|
return null;
|
|
}
|
|
|
|
return firstToken;
|
|
}
|
|
}
|
|
|
|
public bool IsSingleToken => !Text.Contains(' ');
|
|
|
|
public Command ReplaceBrackets(MatchEvaluator evaluator) {
|
|
return new Command(RegexBalancedParentheses.Replace(RegexBalancedBrackets.Replace(Text, evaluator), evaluator));
|
|
}
|
|
}
|