mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08:00
WIP variables
This commit is contained in:
parent
42edb20b07
commit
52615c6f52
@ -52,12 +52,12 @@ namespace Wox.Infrastructure
|
|||||||
var fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
|
var fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
|
||||||
|
|
||||||
var queryWithoutCase = opt.IgnoreCase ? query.ToLower() : query;
|
var queryWithoutCase = opt.IgnoreCase ? query.ToLower() : query;
|
||||||
|
|
||||||
|
var separatedqueryStrings = queryWithoutCase.Split(' ');
|
||||||
|
int currentSeparatedQueryStringIndex = 0;
|
||||||
|
var currentSeparatedQueryString = separatedqueryStrings[currentSeparatedQueryStringIndex];
|
||||||
|
|
||||||
int currentQueryToCompareIndex = 0;
|
var queryIndex = 0;
|
||||||
var queryToCompareSeparated = queryWithoutCase.Split(' ');
|
|
||||||
var currentQueryToCompare = queryToCompareSeparated[currentQueryToCompareIndex];
|
|
||||||
|
|
||||||
var patternIndex = 0;
|
|
||||||
var firstMatchIndex = -1;
|
var firstMatchIndex = -1;
|
||||||
var firstMatchIndexInWord = -1;
|
var firstMatchIndexInWord = -1;
|
||||||
var lastMatchIndex = 0;
|
var lastMatchIndex = 0;
|
||||||
@ -70,14 +70,14 @@ namespace Wox.Infrastructure
|
|||||||
for (var index = 0; index < fullStringToCompareWithoutCase.Length; index++)
|
for (var index = 0; index < fullStringToCompareWithoutCase.Length; index++)
|
||||||
{
|
{
|
||||||
var ch = stringToCompare[index];
|
var ch = stringToCompare[index];
|
||||||
if (fullStringToCompareWithoutCase[index] == currentQueryToCompare[patternIndex])
|
if (fullStringToCompareWithoutCase[index] == currentSeparatedQueryString[queryIndex])
|
||||||
{
|
{
|
||||||
if (firstMatchIndex < 0)
|
if (firstMatchIndex < 0)
|
||||||
{ // first matched char will become the start of the compared string
|
{ // first matched char will become the start of the compared string
|
||||||
firstMatchIndex = index;
|
firstMatchIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patternIndex == 0)
|
if (queryIndex == 0)
|
||||||
{ // first letter of current word
|
{ // first letter of current word
|
||||||
isFullWordMatched = true;
|
isFullWordMatched = true;
|
||||||
firstMatchIndexInWord = index;
|
firstMatchIndexInWord = index;
|
||||||
@ -85,12 +85,12 @@ namespace Wox.Infrastructure
|
|||||||
else if (!isFullWordMatched)
|
else if (!isFullWordMatched)
|
||||||
{ // we want to verify that there is not a better match if this is not a full word
|
{ // we want to verify that there is not a better match if this is not a full word
|
||||||
// in order to do so we need to verify all previous chars are part of the pattern
|
// in order to do so we need to verify all previous chars are part of the pattern
|
||||||
int startIndexToVerify = index - patternIndex;
|
int startIndexToVerify = index - queryIndex;
|
||||||
bool allMatch = true;
|
bool allMatch = true;
|
||||||
for (int indexToCheck = 0; indexToCheck < patternIndex; indexToCheck++)
|
for (int indexToCheck = 0; indexToCheck < queryIndex; indexToCheck++)
|
||||||
{
|
{
|
||||||
if (fullStringToCompareWithoutCase[startIndexToVerify + indexToCheck] !=
|
if (fullStringToCompareWithoutCase[startIndexToVerify + indexToCheck] !=
|
||||||
currentQueryToCompare[indexToCheck])
|
currentSeparatedQueryString[indexToCheck])
|
||||||
{
|
{
|
||||||
allMatch = false;
|
allMatch = false;
|
||||||
}
|
}
|
||||||
@ -99,13 +99,13 @@ namespace Wox.Infrastructure
|
|||||||
if (allMatch)
|
if (allMatch)
|
||||||
{ // update to this as a full word
|
{ // update to this as a full word
|
||||||
isFullWordMatched = true;
|
isFullWordMatched = true;
|
||||||
if (currentQueryToCompareIndex == 0)
|
if (currentSeparatedQueryStringIndex == 0)
|
||||||
{ // first word so we need to update start index
|
{ // first word so we need to update start index
|
||||||
firstMatchIndex = startIndexToVerify;
|
firstMatchIndex = startIndexToVerify;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexList.RemoveAll(x => x >= firstMatchIndexInWord);
|
indexList.RemoveAll(x => x >= firstMatchIndexInWord);
|
||||||
for (int indexToCheck = 0; indexToCheck < patternIndex; indexToCheck++)
|
for (int indexToCheck = 0; indexToCheck < queryIndex; indexToCheck++)
|
||||||
{ // update the index list
|
{ // update the index list
|
||||||
indexList.Add(startIndexToVerify + indexToCheck);
|
indexList.Add(startIndexToVerify + indexToCheck);
|
||||||
}
|
}
|
||||||
@ -115,18 +115,22 @@ namespace Wox.Infrastructure
|
|||||||
lastMatchIndex = index + 1;
|
lastMatchIndex = index + 1;
|
||||||
indexList.Add(index);
|
indexList.Add(index);
|
||||||
|
|
||||||
|
queryIndex++;
|
||||||
|
|
||||||
// increase the pattern matched index and check if everything was matched
|
// increase the pattern matched index and check if everything was matched
|
||||||
if (++patternIndex == currentQueryToCompare.Length)
|
if (queryIndex == currentSeparatedQueryString.Length)
|
||||||
{
|
{
|
||||||
if (++currentQueryToCompareIndex >= queryToCompareSeparated.Length)
|
currentSeparatedQueryStringIndex++;
|
||||||
|
|
||||||
|
if (currentSeparatedQueryStringIndex >= separatedqueryStrings.Length)
|
||||||
{ // moved over all the words
|
{ // moved over all the words
|
||||||
allMatched = true;
|
allMatched = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise move to the next word
|
// otherwise move to the next word
|
||||||
currentQueryToCompare = queryToCompareSeparated[currentQueryToCompareIndex];
|
currentSeparatedQueryString = separatedqueryStrings[currentSeparatedQueryStringIndex];
|
||||||
patternIndex = 0;
|
queryIndex = 0;
|
||||||
if (!isFullWordMatched)
|
if (!isFullWordMatched)
|
||||||
{ // if any of the words was not fully matched all are not fully matched
|
{ // if any of the words was not fully matched all are not fully matched
|
||||||
allWordsFullyMatched = false;
|
allWordsFullyMatched = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user