mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-09-09 23:47:07 +00:00
Make script numeric matchers match negative numbers as well
This commit is contained in:
@@ -3,10 +3,22 @@
|
||||
MenuMatcherScriptInt::MenuMatcherScriptInt()
|
||||
= default;
|
||||
|
||||
MatcherResult<SimpleParserValue> MenuMatcherScriptInt::CanMatch(ILexer<SimpleParserValue>*lexer, const unsigned tokenOffset)
|
||||
MatcherResult<SimpleParserValue> MenuMatcherScriptInt::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
const auto& token = lexer->GetToken(tokenOffset);
|
||||
|
||||
if (token.m_type == SimpleParserValueType::CHARACTER)
|
||||
{
|
||||
if (token.CharacterValue() != '-')
|
||||
return MatcherResult<SimpleParserValue>::NoMatch();
|
||||
|
||||
const auto& nextToken = lexer->GetToken(tokenOffset + 1);
|
||||
if (nextToken.m_type != SimpleParserValueType::INTEGER)
|
||||
return MatcherResult<SimpleParserValue>::NoMatch();
|
||||
|
||||
return MatcherResult<SimpleParserValue>::Match(2);
|
||||
}
|
||||
|
||||
if (token.m_type == SimpleParserValueType::INTEGER)
|
||||
return MatcherResult<SimpleParserValue>::Match(1);
|
||||
|
||||
@@ -20,7 +32,7 @@ MatcherResult<SimpleParserValue> MenuMatcherScriptInt::CanMatch(ILexer<SimplePar
|
||||
|
||||
char* endPtr;
|
||||
// The return result does not matter here
|
||||
const auto _ = strtol(&stringValue[0], &endPtr, 10);
|
||||
const auto _ = strtol(stringValue.data(), &endPtr, 10);
|
||||
|
||||
if (endPtr != &stringValue[stringValue.size() - 1])
|
||||
return MatcherResult<SimpleParserValue>::NoMatch();
|
||||
|
||||
@@ -7,6 +7,18 @@ MatcherResult<SimpleParserValue> MenuMatcherScriptNumeric::CanMatch(ILexer<Simpl
|
||||
{
|
||||
const auto& token = lexer->GetToken(tokenOffset);
|
||||
|
||||
if (token.m_type == SimpleParserValueType::CHARACTER)
|
||||
{
|
||||
if (token.CharacterValue() != '-')
|
||||
return MatcherResult<SimpleParserValue>::NoMatch();
|
||||
|
||||
const auto& nextToken = lexer->GetToken(tokenOffset + 1);
|
||||
if (nextToken.m_type != SimpleParserValueType::FLOATING_POINT && nextToken.m_type != SimpleParserValueType::INTEGER)
|
||||
return MatcherResult<SimpleParserValue>::NoMatch();
|
||||
|
||||
return MatcherResult<SimpleParserValue>::Match(2);
|
||||
}
|
||||
|
||||
if (token.m_type == SimpleParserValueType::FLOATING_POINT || token.m_type == SimpleParserValueType::INTEGER)
|
||||
return MatcherResult<SimpleParserValue>::Match(1);
|
||||
|
||||
@@ -20,7 +32,7 @@ MatcherResult<SimpleParserValue> MenuMatcherScriptNumeric::CanMatch(ILexer<Simpl
|
||||
|
||||
char* endPtr;
|
||||
// The return result does not matter here
|
||||
const auto _ = strtod(&stringValue[0], &endPtr);
|
||||
const auto _ = strtod(stringValue.data(), &endPtr);
|
||||
|
||||
if(endPtr != &stringValue[stringValue.size()])
|
||||
return MatcherResult<SimpleParserValue>::NoMatch();
|
||||
|
||||
Reference in New Issue
Block a user