michael@0: // 7zMethodID.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #include "7zMethodID.h" michael@0: michael@0: namespace NArchive { michael@0: namespace N7z { michael@0: michael@0: static wchar_t GetHex(Byte value) michael@0: { michael@0: return (value < 10) ? ('0' + value) : ('A' + (value - 10)); michael@0: } michael@0: michael@0: static bool HexCharToInt(wchar_t value, Byte &result) michael@0: { michael@0: if (value >= '0' && value <= '9') michael@0: result = value - '0'; michael@0: else if (value >= 'a' && value <= 'f') michael@0: result = 10 + value - 'a'; michael@0: else if (value >= 'A' && value <= 'F') michael@0: result = 10 + value - 'A'; michael@0: else michael@0: return false; michael@0: return true; michael@0: } michael@0: michael@0: static bool TwoHexCharsToInt(wchar_t valueHigh, wchar_t valueLow, Byte &result) michael@0: { michael@0: Byte resultHigh, resultLow; michael@0: if (!HexCharToInt(valueHigh, resultHigh)) michael@0: return false; michael@0: if (!HexCharToInt(valueLow, resultLow)) michael@0: return false; michael@0: result = (resultHigh << 4) + resultLow; michael@0: return true; michael@0: } michael@0: michael@0: UString CMethodID::ConvertToString() const michael@0: { michael@0: UString result; michael@0: for (int i = 0; i < IDSize; i++) michael@0: { michael@0: Byte b = ID[i]; michael@0: result += GetHex(b >> 4); michael@0: result += GetHex(b & 0xF); michael@0: } michael@0: return result; michael@0: } michael@0: michael@0: bool CMethodID::ConvertFromString(const UString &srcString) michael@0: { michael@0: int length = srcString.Length(); michael@0: if ((length & 1) != 0 || (length >> 1) > kMethodIDSize) michael@0: return false; michael@0: IDSize = length / 2; michael@0: UInt32 i; michael@0: for(i = 0; i < IDSize; i++) michael@0: if (!TwoHexCharsToInt(srcString[i * 2], srcString[i * 2 + 1], ID[i])) michael@0: return false; michael@0: for(; i < kMethodIDSize; i++) michael@0: ID[i] = 0; michael@0: return true; michael@0: } michael@0: michael@0: bool operator==(const CMethodID &a1, const CMethodID &a2) michael@0: { michael@0: if (a1.IDSize != a2.IDSize) michael@0: return false; michael@0: for (UInt32 i = 0; i < a1.IDSize; i++) michael@0: if (a1.ID[i] != a2.ID[i]) michael@0: return false; michael@0: return true; michael@0: } michael@0: michael@0: }}