Add removing duplicate tokens to input_parser

This commit is contained in:
Vasily
2019-05-25 18:49:42 +02:00
committed by username223
parent bc060bec96
commit b4cf5d3cb7
3 changed files with 167 additions and 4 deletions
+44 -3
View File
@@ -225,7 +225,7 @@ std::vector<Token>
}
std::vector<Token>
removeDuplicateNewSequences( const std::vector<Token>& tokens )
removeDuplicateNewSequences( const std::vector<Token>& tokens ) noexcept
{
std::vector<Token> approvedTokens = {};
@@ -253,7 +253,48 @@ std::vector<Token>
return approvedTokens;
}
std::vector<Token> removeIncorrectTokens( const std::vector<Token>& tokens )
std::vector<Token>
removeTokenInSameSequence( const std::vector<Token>& tokens,
const Token tokenToRemove ) noexcept
{
return removeDuplicateNewSequences( tokens );
std::vector<Token> approvedTokens = {};
bool tokenInSequence = false;
for ( const auto& token : tokens )
{
if ( token == Token::TOKEN_NEW_SEQUENCE )
{
tokenInSequence = false;
}
if ( tokenInSequence && ( token == tokenToRemove ) )
{
continue;
}
if ( token == tokenToRemove )
{
tokenInSequence = true;
}
approvedTokens.push_back( token );
}
return approvedTokens;
}
std::vector<Token>
removeIncorrectTokens( const std::vector<Token>& tokens ) noexcept
{
const auto spacesRemoved = removeDuplicateNewSequences( tokens );
const auto ctrlRemoved
= removeTokenInSameSequence( spacesRemoved, Token::MODIFIER_CTRL );
const auto altRemoved
= removeTokenInSameSequence( ctrlRemoved, Token::MODIFIER_ALT );
const auto shiftRemoved
= removeTokenInSameSequence( altRemoved, Token::MODIFIER_SHIFT );
const auto altgrRemoved
= removeTokenInSameSequence( shiftRemoved, Token::MODIFIER_ALTGR );
const auto superRemoved
= removeTokenInSameSequence( altgrRemoved, Token::MODIFIER_SUPER );
return superRemoved;
}
+2 -1
View File
@@ -90,4 +90,5 @@ enum class Token
std::vector<Token>
ParseKeyboardInputsToTokens( const std::string inputs ) noexcept;
std::vector<Token> removeIncorrectTokens( const std::vector<Token>& tokens );
std::vector<Token>
removeIncorrectTokens( const std::vector<Token>& tokens ) noexcept;