diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2014-11-23 03:00:00 +0300 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:16:51 +0300 |
commit | f08f4dcc3c02464c17753b3feafcfe5243b9e236 (patch) | |
tree | b0e1b15bc5368d92dff422e8ec0818564a2b00b8 /CPP/7zip/UI/FileManager/SplitUtils.cpp | |
parent | 83f8ddcc5b2161e1e3c49666265257fca8aeb12c (diff) |
9.349.34
Diffstat (limited to 'CPP/7zip/UI/FileManager/SplitUtils.cpp')
-rw-r--r--[-rwxr-xr-x] | CPP/7zip/UI/FileManager/SplitUtils.cpp | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/CPP/7zip/UI/FileManager/SplitUtils.cpp b/CPP/7zip/UI/FileManager/SplitUtils.cpp index 8bae0573..b0172a9f 100755..100644 --- a/CPP/7zip/UI/FileManager/SplitUtils.cpp +++ b/CPP/7zip/UI/FileManager/SplitUtils.cpp @@ -2,85 +2,86 @@ #include "StdAfx.h" -#include "Common/StringToInt.h" +#include "../../../Common/StringToInt.h" #include "SplitUtils.h" -#include "StringUtils.h" bool ParseVolumeSizes(const UString &s, CRecordVector<UInt64> &values) { values.Clear(); - UStringVector destStrings; - SplitString(s, destStrings); bool prevIsNumber = false; - for (int i = 0; i < destStrings.Size(); i++) + for (unsigned i = 0; i < s.Len();) { - UString subString = destStrings[i]; - subString.MakeUpper(); - if (subString.IsEmpty()) - return false; - if (subString == L"-") + wchar_t c = s[i++]; + if (c == L' ') + continue; + if (c == L'-') return true; if (prevIsNumber) { - wchar_t c = subString[0]; - UInt64 &value = values.Back(); prevIsNumber = false; - switch(c) + unsigned numBits = 0; + switch (MyCharLower_Ascii(c)) + { + case 'b': continue; + case 'k': numBits = 10; break; + case 'm': numBits = 20; break; + case 'g': numBits = 30; break; + case 't': numBits = 40; break; + } + if (numBits != 0) { - case L'B': - continue; - case L'K': - value <<= 10; - continue; - case L'M': - value <<= 20; - continue; - case L'G': - value <<= 30; - continue; + UInt64 &val = values.Back(); + if (val >= ((UInt64)1 << (64 - numBits))) + return false; + val <<= numBits; + + for (; i < s.Len(); i++) + if (s[i] == L' ') + break; + continue; } } - const wchar_t *start = subString; + i--; + const wchar_t *start = s.Ptr(i); const wchar_t *end; - UInt64 value = ConvertStringToUInt64(start, &end); + UInt64 val = ConvertStringToUInt64(start, &end); if (start == end) return false; - if (value == 0) + if (val == 0) return false; - values.Add(value); + values.Add(val); prevIsNumber = true; - UString rem = subString.Mid((int)(end - start)); - if (!rem.IsEmpty()) - destStrings.Insert(i + 1, rem); + i += (unsigned)(end - start); } return true; } -void AddVolumeItems(NWindows::NControl::CComboBox &volumeCombo) +void AddVolumeItems(NWindows::NControl::CComboBox &combo) { - volumeCombo.AddString(TEXT("10M")); - volumeCombo.AddString(TEXT("650M - CD")); - volumeCombo.AddString(TEXT("700M - CD")); - volumeCombo.AddString(TEXT("4480M - DVD")); - volumeCombo.AddString(TEXT("1457664 - 3.5\" floppy")); + combo.AddString(TEXT("10M")); + combo.AddString(TEXT("650M - CD")); + combo.AddString(TEXT("700M - CD")); + combo.AddString(TEXT("4092M - FAT")); + combo.AddString(TEXT("4480M - DVD")); // 4489 MiB limit + combo.AddString(TEXT("8128M - DVD DL")); // 8147 MiB limit + combo.AddString(TEXT("23040M - BD")); // 23866 MiB limit + combo.AddString(TEXT("1457664 - 3.5\" floppy")); } -UInt64 GetNumberOfVolumes(UInt64 size, CRecordVector<UInt64> &volSizes) +UInt64 GetNumberOfVolumes(UInt64 size, const CRecordVector<UInt64> &volSizes) { if (size == 0 || volSizes.Size() == 0) return 1; - UInt64 numVolumes = 0; - for (int i = 0; i < volSizes.Size(); i++) + FOR_VECTOR (i, volSizes) { UInt64 volSize = volSizes[i]; - numVolumes++; if (volSize >= size) - return numVolumes; + return i + 1; size -= volSize; } UInt64 volSize = volSizes.Back(); if (volSize == 0) return (UInt64)(Int64)-1; - return numVolumes + (size - 1) / volSize + 1; + return volSizes.Size() + (size - 1) / volSize + 1; } |