-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInputInterpreter.cs
45 lines (37 loc) · 1.37 KB
/
InputInterpreter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.Text;
using Community.PowerToys.Run.Plugin.DeepLTranslator.Enums;
using Community.PowerToys.Run.Plugin.DeepLTranslator.Job;
using Community.PowerToys.Run.Plugin.DeepLTranslator.Models;
using Wox.Plugin;
namespace Community.PowerToys.Run.Plugin.DeepLTranslator
{
public class InputInterpreter
{
public static (LangCodeEnums.Code, string) Parse(Query query)
{
var splited = SplitSearch(query);
if (splited.Length == 2)
{
string targetLangCode = splited[0];
string text = splited[1];
if (!string.IsNullOrEmpty(targetLangCode) && !string.IsNullOrEmpty(text))
{
var target = LangCodeEnums.Parse(targetLangCode);
return (target, text);
}
}
return (LangCodeEnums.Code.UNK, string.Empty);
}
private static string[] SplitSearch(Query query)
{
int secondSearchStartIndex = query.Search.IndexOf(' ');
return new string[]
{
query.Search.Substring(0, secondSearchStartIndex),
query.Search.Substring(secondSearchStartIndex, query.Search.Length - secondSearchStartIndex),
};
}
}
}