📄 string_test.cpp
字号:
CHXString* pStr = GetStringObj(info[1]); unsigned int field; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } else if (!UTParamUtil::GetUInt(info[3], field)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); ret = false; } else { CHXString got = pStr->NthField(*((const char*)info[2]), (ULONG32)field); const char* expected = (const char*)info[4]; if (strcmp(got, expected) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, expected)); ret = false; } } return ret;}bool HLXStringTest::HandleResetNthFieldStateCmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr = GetStringObj(info[1]); // XXXSAB: Should we have a way to set this NthFieldState thing to garbage??? if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } else { if (pStr == m_pA) m_ANthFieldState = 0; else if (pStr == m_pB) m_BNthFieldState = 0; } return ret;}bool HLXStringTest::HandleGetNthFieldCmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr = GetStringObj(info[1]); unsigned int field; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } else if (!UTParamUtil::GetUInt(info[3], field)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); ret = false; } else { UINT64& state = (pStr == m_pA) ? m_ANthFieldState : m_BNthFieldState; CHXString got = pStr->GetNthField(*((const char*)info[2]), (ULONG32)field, state); const char* expected = (const char*)info[4]; if (strcmp(got, expected) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, expected)); ret = false; } } return ret;}bool HLXStringTest::HandleSpanIncludingCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else { CHXString got = pStr->SpanIncluding((const char*)info[2]); if (strcmp(got, (const char*)info[3]) == 0) ret = true; else DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, (const char*)info[3])); } return ret;}bool HLXStringTest::HandleSpanExcludingCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else { CHXString got = pStr->SpanExcluding((const char*)info[2]); if (strcmp(got, (const char*)info[3]) == 0) ret = true; else DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, (const char*)info[3])); } return ret;}bool HLXStringTest::HandleMakeUpperCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else { ret = true; pStr->MakeUpper(); } return ret;}bool HLXStringTest::HandleMakeLowerCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else { ret = true; pStr->MakeLower(); } return ret;}bool HLXStringTest::HandleTrimRightCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else { ret = true; pStr->TrimRight(); } return ret;}bool HLXStringTest::HandleTrimLeftCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else { ret = true; pStr->TrimLeft(); } return ret;}bool HLXStringTest::HandleFind1Cmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int expected; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[3], expected)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { INT32 got = pStr->Find(*((const char*)info[2])); if (got == expected) ret = true; else DPRINTF(D_ERROR, ("Got %ld expected %ld\n", (long)got, (long)expected)); } return ret;}bool HLXStringTest::HandleFind2Cmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int expected; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[3], expected)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { INT32 got = pStr->Find((const char*)info[2]); if (got == expected) ret = true; else DPRINTF(D_ERROR, ("Got %ld expected %ld\n", (long)got, (long)expected)); } return ret;}bool HLXStringTest::HandleReverseFindCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int expected; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[3], expected)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { INT32 got = pStr->ReverseFind(*((const char*)info[2])); if (got == expected) ret = true; else DPRINTF(D_ERROR, ("Got %ld expected %ld\n", (long)got, (long)expected)); } return ret;}bool HLXStringTest::HandleFindAndReplaceCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); bool expected, bReplaceAll; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetBool(info[4], bReplaceAll) || !UTParamUtil::GetBool(info[5], expected)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { bool got = pStr->FindAndReplace((const char*)info[2], (const char*)info[3], bReplaceAll) ? true : false; if (got == expected) ret = true; else DPRINTF(D_ERROR, ("Got %s expected %s\n", got ? "TRUE" : "FALSE", expected ? "TRUE" : "FALSE")); } return ret;}namespace{ inline bool GetCharStar (const char* strRep, const char*& value) { value = strRep; return true; } inline bool GetPtr (const char* strRep, void*& value) { unsigned long iValue; bool ret = UTParamUtil::GetULong(strRep, iValue); if (ret) value = (void*)iValue; return ret; } template <class T> bool HandleFormat (CHXString& str, const UTVector<UTString>& info, bool (*GetValue)(const char* strRep, T& retValue)) { const char* fmt = (const char*)info[2]; T* values = new T[info.Nelements() - 3]; int beginData = 3; int endData = info.Nelements(); int infoIdx = beginData; int valIdx = 0; for (; infoIdx < endData; ++infoIdx, ++valIdx) { if (!GetValue(info[infoIdx], values[valIdx])) { DPRINTF(D_ERROR, ("Failed to convert arg \"%s\"\n", (const char*)info[infoIdx])); return false; } } switch (valIdx) { case 1: str.Format(fmt, values[0]); break; case 2: str.Format(fmt, values[0], values[1]); break; case 3: str.Format(fmt, values[0], values[1], values[2]); break; case 4: str.Format(fmt, values[0], values[1], values[2], values[3]); break; case 5: str.Format(fmt, values[0], values[1], values[2], values[3], values[4]); break; case 6: str.Format(fmt, values[0], values[1], values[2], values[3], values[4], values[5]); break; case 7: str.Format(fmt, values[0], values[1], values[2], values[3], values[4], values[5], values[6]); break; case 8: str.Format(fmt, values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]); break; case 9: str.Format(fmt, values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8]); break; case 10: str.Format(fmt, values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9]); break; default: DPRINTF(D_ERROR, ("Unsupported num of data values (%d)\n", valIdx)); return false; break; } delete [] values; return true; }};bool HLXStringTest::HandleFormatIntCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else ret = HandleFormat<int>(*pStr, info, UTParamUtil::GetInt); return ret;}bool HLXStringTest::HandleFormatLongCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else ret = HandleFormat<long int>(*pStr, info, UTParamUtil::GetLong); return ret;}bool HLXStringTest::HandleFormatUIntCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else ret = HandleFormat<unsigned int>(*pStr, info, UTParamUtil::GetUInt); return ret;}bool HLXStringTest::HandleFormatULongCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else ret = HandleFormat<unsigned long int>(*pStr, info, UTParamUtil::GetULong); return ret;}bool HLXStringTest::HandleFormatCharCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -