diff options
author | 2023-05-04 02:41:16 +1000 | |
---|---|---|
committer | 2023-05-04 02:41:16 +1000 | |
commit | a504bde3a7462b54fafd5cfc2f52e58d0f3218e1 (patch) | |
tree | 8b3108d572b1a0873a6cdbb4e8af1f17179545c3 /3rdparty/lzma/CPP/Common/CommandLineParser.cpp | |
parent | befb9bf4a8cfdb2b693a32e32535b5eac522c5d8 (diff) |
3rdparty/lzma: Updated to LZMA SDK version 22.01
Diffstat (limited to '3rdparty/lzma/CPP/Common/CommandLineParser.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/Common/CommandLineParser.cpp | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/3rdparty/lzma/CPP/Common/CommandLineParser.cpp b/3rdparty/lzma/CPP/Common/CommandLineParser.cpp index 1c7f26547c8..465e0fde853 100644 --- a/3rdparty/lzma/CPP/Common/CommandLineParser.cpp +++ b/3rdparty/lzma/CPP/Common/CommandLineParser.cpp @@ -4,20 +4,6 @@ #include "CommandLineParser.h" -static bool IsString1PrefixedByString2_NoCase(const wchar_t *u, const char *a) -{ - for (;;) - { - char c = *a; - if (c == 0) - return true; - if ((unsigned char)MyCharLower_Ascii(c) != MyCharLower_Ascii(*u)) - return false; - a++; - u++; - } -} - namespace NCommandLineParser { bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) @@ -44,7 +30,7 @@ bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2) void SplitCommandLine(const UString &s, UStringVector &parts) { - UString sTemp = s; + UString sTemp (s); sTemp.Trim(); parts.Clear(); for (;;) @@ -59,18 +45,17 @@ void SplitCommandLine(const UString &s, UStringVector &parts) } -static const char *kStopSwitchParsing = "--"; +static const char * const kStopSwitchParsing = "--"; static bool inline IsItSwitchChar(wchar_t c) { return (c == '-'); } -CParser::CParser(unsigned numSwitches): - _numSwitches(numSwitches), - _switches(0) +CParser::CParser(): + _switches(NULL), + StopSwitchIndex(-1) { - _switches = new CSwitchResult[numSwitches]; } CParser::~CParser() @@ -81,7 +66,7 @@ CParser::~CParser() // if (s) contains switch then function updates switch structures // out: true, if (s) is a switch -bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) +bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms, unsigned numSwitches) { if (s.IsEmpty() || !IsItSwitchChar(s[0])) return false; @@ -90,16 +75,16 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) unsigned switchIndex = 0; int maxLen = -1; - for (unsigned i = 0; i < _numSwitches; i++) + for (unsigned i = 0; i < numSwitches; i++) { - const char *key = switchForms[i].Key; + const char * const key = switchForms[i].Key; unsigned switchLen = MyStringLen(key); if ((int)switchLen <= maxLen || pos + switchLen > s.Len()) continue; - if (IsString1PrefixedByString2_NoCase((const wchar_t *)s + pos, key)) + if (IsString1PrefixedByString2_NoCase_Ascii((const wchar_t *)s + pos, key)) { switchIndex = i; - maxLen = switchLen; + maxLen = (int)switchLen; } } @@ -109,7 +94,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) return false; } - pos += maxLen; + pos += (unsigned)maxLen; CSwitchResult &sw = _switches[switchIndex]; const CSwitchForm &form = switchForms[switchIndex]; @@ -122,7 +107,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) sw.ThereIs = true; - int rem = s.Len() - pos; + const unsigned rem = s.Len() - pos; if (rem < form.MinLen) { ErrorMessage = "Too short switch:"; @@ -161,8 +146,10 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) break; case NSwitchType::kString: - sw.PostStrings.Add((const wchar_t *)s + pos); + { + sw.PostStrings.Add(s.Ptr(pos)); return true; + } } if (pos != s.Len()) @@ -173,23 +160,30 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) return true; } -bool CParser::ParseStrings(const CSwitchForm *switchForms, const UStringVector &commandStrings) + +bool CParser::ParseStrings(const CSwitchForm *switchForms, unsigned numSwitches, const UStringVector &commandStrings) { + StopSwitchIndex = -1; + ErrorMessage.Empty(); ErrorLine.Empty(); - bool stopSwitch = false; + NonSwitchStrings.Clear(); + delete []_switches; + _switches = NULL; + _switches = new CSwitchResult[numSwitches]; + FOR_VECTOR (i, commandStrings) { const UString &s = commandStrings[i]; - if (!stopSwitch) + if (StopSwitchIndex < 0) { if (s.IsEqualTo(kStopSwitchParsing)) { - stopSwitch = true; + StopSwitchIndex = (int)NonSwitchStrings.Size(); continue; } if (!s.IsEmpty() && IsItSwitchChar(s[0])) { - if (ParseString(s, switchForms)) + if (ParseString(s, switchForms, numSwitches)) continue; ErrorLine = s; return false; |