コード例 #1
0
ファイル: uuid-generic.cpp プロジェクト: miguelinux/vbox
RTDECL(int)  RTUuidFromUtf16(PRTUUID pUuid, PCRTUTF16 pwszString)
{
    bool fHaveBraces;

    /*
     * Validate parameters.
     */
    AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
    AssertPtrReturn(pwszString, VERR_INVALID_PARAMETER);

    fHaveBraces = pwszString[0] == '{';
    pwszString += fHaveBraces;

#define MY_CHECK(expr) do { if (RT_UNLIKELY(!(expr))) return VERR_INVALID_UUID_FORMAT; } while (0)
#define MY_ISXDIGIT(ch) (!((ch) & 0xff00) && g_au8Digits[(ch) & 0xff] != 0xff)
    MY_CHECK(MY_ISXDIGIT(pwszString[ 0]));
    MY_CHECK(MY_ISXDIGIT(pwszString[ 1]));
    MY_CHECK(MY_ISXDIGIT(pwszString[ 2]));
    MY_CHECK(MY_ISXDIGIT(pwszString[ 3]));
    MY_CHECK(MY_ISXDIGIT(pwszString[ 4]));
    MY_CHECK(MY_ISXDIGIT(pwszString[ 5]));
    MY_CHECK(MY_ISXDIGIT(pwszString[ 6]));
    MY_CHECK(MY_ISXDIGIT(pwszString[ 7]));
    MY_CHECK(pwszString[ 8] == '-');
    MY_CHECK(MY_ISXDIGIT(pwszString[ 9]));
    MY_CHECK(MY_ISXDIGIT(pwszString[10]));
    MY_CHECK(MY_ISXDIGIT(pwszString[11]));
    MY_CHECK(MY_ISXDIGIT(pwszString[12]));
    MY_CHECK(pwszString[13] == '-');
    MY_CHECK(MY_ISXDIGIT(pwszString[14]));
    MY_CHECK(MY_ISXDIGIT(pwszString[15]));
    MY_CHECK(MY_ISXDIGIT(pwszString[16]));
    MY_CHECK(MY_ISXDIGIT(pwszString[17]));
    MY_CHECK(pwszString[18] == '-');
    MY_CHECK(MY_ISXDIGIT(pwszString[19]));
    MY_CHECK(MY_ISXDIGIT(pwszString[20]));
    MY_CHECK(MY_ISXDIGIT(pwszString[21]));
    MY_CHECK(MY_ISXDIGIT(pwszString[22]));
    MY_CHECK(pwszString[23] == '-');
    MY_CHECK(MY_ISXDIGIT(pwszString[24]));
    MY_CHECK(MY_ISXDIGIT(pwszString[25]));
    MY_CHECK(MY_ISXDIGIT(pwszString[26]));
    MY_CHECK(MY_ISXDIGIT(pwszString[27]));
    MY_CHECK(MY_ISXDIGIT(pwszString[28]));
    MY_CHECK(MY_ISXDIGIT(pwszString[29]));
    MY_CHECK(MY_ISXDIGIT(pwszString[30]));
    MY_CHECK(MY_ISXDIGIT(pwszString[31]));
    MY_CHECK(MY_ISXDIGIT(pwszString[32]));
    MY_CHECK(MY_ISXDIGIT(pwszString[33]));
    MY_CHECK(MY_ISXDIGIT(pwszString[34]));
    MY_CHECK(MY_ISXDIGIT(pwszString[35]));
    if (fHaveBraces)
        MY_CHECK(pwszString[36] == '}');
    MY_CHECK(!pwszString[36 + fHaveBraces]);
#undef MY_ISXDIGIT
#undef MY_CHECK

    /*
     * Inverse of RTUuidToUtf8 (see above).
     */
#define MY_TONUM(ch) (g_au8Digits[(ch) & 0xff])
    pUuid->Gen.u32TimeLow = RT_LE2H_U32((uint32_t)MY_TONUM(pwszString[ 0]) << 28
                          | (uint32_t)MY_TONUM(pwszString[ 1]) << 24
                          | (uint32_t)MY_TONUM(pwszString[ 2]) << 20
                          | (uint32_t)MY_TONUM(pwszString[ 3]) << 16
                          | (uint32_t)MY_TONUM(pwszString[ 4]) << 12
                          | (uint32_t)MY_TONUM(pwszString[ 5]) <<  8
                          | (uint32_t)MY_TONUM(pwszString[ 6]) <<  4
                          | (uint32_t)MY_TONUM(pwszString[ 7]));
    pUuid->Gen.u16TimeMid = RT_LE2H_U16((uint16_t)MY_TONUM(pwszString[ 9]) << 12
                          | (uint16_t)MY_TONUM(pwszString[10]) << 8
                          | (uint16_t)MY_TONUM(pwszString[11]) << 4
                          | (uint16_t)MY_TONUM(pwszString[12]));
    pUuid->Gen.u16TimeHiAndVersion = RT_LE2H_U16(
                            (uint16_t)MY_TONUM(pwszString[14]) << 12
                          | (uint16_t)MY_TONUM(pwszString[15]) << 8
                          | (uint16_t)MY_TONUM(pwszString[16]) << 4
                          | (uint16_t)MY_TONUM(pwszString[17]));
    pUuid->Gen.u8ClockSeqHiAndReserved =
                            (uint16_t)MY_TONUM(pwszString[19]) << 4
                          | (uint16_t)MY_TONUM(pwszString[20]);
    pUuid->Gen.u8ClockSeqLow =
                            (uint16_t)MY_TONUM(pwszString[21]) << 4
                          | (uint16_t)MY_TONUM(pwszString[22]);
    pUuid->Gen.au8Node[0] = (uint8_t)MY_TONUM(pwszString[24]) << 4
                          | (uint8_t)MY_TONUM(pwszString[25]);
    pUuid->Gen.au8Node[1] = (uint8_t)MY_TONUM(pwszString[26]) << 4
                          | (uint8_t)MY_TONUM(pwszString[27]);
    pUuid->Gen.au8Node[2] = (uint8_t)MY_TONUM(pwszString[28]) << 4
                          | (uint8_t)MY_TONUM(pwszString[29]);
    pUuid->Gen.au8Node[3] = (uint8_t)MY_TONUM(pwszString[30]) << 4
                          | (uint8_t)MY_TONUM(pwszString[31]);
    pUuid->Gen.au8Node[4] = (uint8_t)MY_TONUM(pwszString[32]) << 4
                          | (uint8_t)MY_TONUM(pwszString[33]);
    pUuid->Gen.au8Node[5] = (uint8_t)MY_TONUM(pwszString[34]) << 4
                          | (uint8_t)MY_TONUM(pwszString[35]);
#undef MY_TONUM
    return VINF_SUCCESS;
}
コード例 #2
0
void CStringMgr::Reload(void)
{
	m_mapString.clear();

    auto strPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(STR_RES);
    
	unsigned long uSize = 0;
	unsigned char *pData = CCFileUtils::sharedFileUtils()->getFileData(strPath.c_str(), "r", &uSize);

	MY_CHECK(pData, "fopen %s failed", strPath.c_str());
	
	bool bCommentFlag = false;
	char szLine[MAX_STRING];
	unsigned char *pPos = pData;
	
	GetLineFromData(szLine, sizeof(szLine), pPos, pData, uSize);
	
	while (GetLineFromData(szLine, sizeof(szLine), pPos, pData, uSize)) {
		char cFirst = szLine[0];

		switch (cFirst) {
		case 0:
		case '\r':
		case '\n':
		case ';':
			continue;
			break;
		case '/':
			switch (szLine[1]) {
			case '/':	continue; break;
			case '*':	bCommentFlag = true; break;
			default:	break;
			}
			break;
		case '*':
			if (szLine[1] == '/') {
				bCommentFlag = false;
			}
			break;
		default:
			break;
		}

		if (bCommentFlag) {
			continue;
		}

		char *pPos = strstr(szLine, "=");
		if (pPos) {
			*pPos = 0;

			std::string strValue = pPos + 1;
			ReplaceStdString(strValue, "\n", "");
			ReplaceStdString(strValue, "\r", "");
			MyTrim(szLine);
			
			ReplaceStdString(strValue, "\\n", "\n");

			std::string strIndex = szLine;
			MY_ASSERT(m_mapString.find(strIndex) == m_mapString.end(), "警告: %s 含有两项以上 Index 为 %s 的数据",
					  strPath.c_str(), strIndex.c_str());
			m_mapString.insert(make_pair(strIndex, strValue));
		}
	}

	delete[] pData;
}