5 #include "ParseProperties.h"
7 #include "Common/StringToInt.h"
8 #include "Common/MyCom.h"
10 HRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)
12 if (prop.vt == VT_UI4)
16 resValue = prop.ulVal;
18 else if (prop.vt == VT_EMPTY)
22 const wchar_t *start = name;
24 UInt64 v = ConvertStringToUInt64(start, &end);
25 if (end - start != name.Length())
35 static const int kLogarithmicSizeLimit = 32;
36 static const wchar_t kByteSymbol = L'B';
37 static const wchar_t kKiloByteSymbol = L'K';
38 static const wchar_t kMegaByteSymbol = L'M';
40 HRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)
42 UString srcString = srcStringSpec;
43 srcString.MakeUpper();
45 const wchar_t *start = srcString;
47 UInt64 number = ConvertStringToUInt64(start, &end);
48 int numDigits = (int)(end - start);
49 if (numDigits == 0 || srcString.Length() > numDigits + 1)
51 if (srcString.Length() == numDigits)
53 if (number >= kLogarithmicSizeLimit)
55 dicSize = (UInt32)1 << (int)number;
58 switch (srcString[numDigits])
61 if (number >= ((UInt64)1 << kLogarithmicSizeLimit))
63 dicSize = (UInt32)number;
66 if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))
68 dicSize = (UInt32)(number << 10);
71 if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))
73 dicSize = (UInt32)(number << 20);
81 HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)
85 if (prop.vt == VT_UI4)
87 UInt32 logDicSize = prop.ulVal;
90 resValue = (UInt32)1 << logDicSize;
93 if (prop.vt == VT_BSTR)
94 return ParsePropDictionaryValue(prop.bstrVal, resValue);
97 return ParsePropDictionaryValue(name, resValue);
100 bool StringToBool(const UString &s, bool &res)
102 if (s.IsEmpty() || s.CompareNoCase(L"ON") == 0)
107 if (s.CompareNoCase(L"OFF") == 0)
115 HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)
124 dest = (value.ulVal != 0);
128 return StringToBool(value.bstrVal, dest) ? S_OK : E_INVALIDARG;
133 int ParseStringToUInt32(const UString &srcString, UInt32 &number)
135 const wchar_t *start = srcString;
137 UInt64 number64 = ConvertStringToUInt64(start, &end);
138 if (number64 > 0xFFFFFFFF)
143 number = (UInt32)number64;
144 return (int)(end - start);
147 HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)
154 numThreads = prop.ulVal;
159 RINOK(SetBoolProperty(val, prop));
160 numThreads = (val ? defaultNumThreads : 1);
168 int index = ParseStringToUInt32(name, number);
169 if (index != name.Length())