Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / other-licenses / 7zstub / src / 7zip / Archive / 7z / 7zMethodID.cpp
bloba7b1296e9fd3cb71e7baec45e7b36c08488de8fc
1 // 7zMethodID.cpp
3 #include "StdAfx.h"
5 #include "7zMethodID.h"
7 namespace NArchive {
8 namespace N7z {
10 static wchar_t GetHex(Byte value)
12 return (value < 10) ? ('0' + value) : ('A' + (value - 10));
15 static bool HexCharToInt(wchar_t value, Byte &result)
17 if (value >= '0' && value <= '9')
18 result = value - '0';
19 else if (value >= 'a' && value <= 'f')
20 result = 10 + value - 'a';
21 else if (value >= 'A' && value <= 'F')
22 result = 10 + value - 'A';
23 else
24 return false;
25 return true;
28 static bool TwoHexCharsToInt(wchar_t valueHigh, wchar_t valueLow, Byte &result)
30 Byte resultHigh, resultLow;
31 if (!HexCharToInt(valueHigh, resultHigh))
32 return false;
33 if (!HexCharToInt(valueLow, resultLow))
34 return false;
35 result = (resultHigh << 4) + resultLow;
36 return true;
39 UString CMethodID::ConvertToString() const
41 UString result;
42 for (int i = 0; i < IDSize; i++)
44 Byte b = ID[i];
45 result += GetHex(b >> 4);
46 result += GetHex(b & 0xF);
48 return result;
51 bool CMethodID::ConvertFromString(const UString &srcString)
53 int length = srcString.Length();
54 if ((length & 1) != 0 || (length >> 1) > kMethodIDSize)
55 return false;
56 IDSize = length / 2;
57 UInt32 i;
58 for(i = 0; i < IDSize; i++)
59 if (!TwoHexCharsToInt(srcString[i * 2], srcString[i * 2 + 1], ID[i]))
60 return false;
61 for(; i < kMethodIDSize; i++)
62 ID[i] = 0;
63 return true;
66 bool operator==(const CMethodID &a1, const CMethodID &a2)
68 if (a1.IDSize != a2.IDSize)
69 return false;
70 for (UInt32 i = 0; i < a1.IDSize; i++)
71 if (a1.ID[i] != a2.ID[i])
72 return false;
73 return true;