Ejemplo n.º 1
0
/*
 * Converts the specified (sub-)string into a Variant value.
 */
CComVariant CMELCommand::MakeVariantNotArray(const CAtlString& strText)
{
	CComVariant variant(strText);
	if (strText.SpanExcluding(L"0123456789.-+e").IsEmpty()) {
		if (strText.Find(L".") < 0) {
			variant.ChangeType(VT_I4);
		} else {
			variant.ChangeType(VT_R8);
		}
	}
	return variant;
}
Ejemplo n.º 2
0
/*
 * Converts the specified (reply) string into a Variant value.
 * If the string contains tab characters ('\t), the string is
 * considered to contain an array of values.
 */
CComVariant CMELCommand::MakeVariant(const CAtlString& strText)
{
	int tabCount = 0;
	int tabPos = 0;
	while (tabPos < strText.GetLength()) {
		tabPos = strText.Find(L'\t', tabPos);
		if (tabPos < 0)
			break;
		++tabCount;
		++tabPos;
	}
	if (!tabCount) {
		return MakeVariantNotArray(strText);
	}
	CComSafeArray<VARIANT> safeArray;
	safeArray.Create(tabCount + 1);
	int curPos = 0;
	int index = 0;
	tabPos = strText.Find(L'\t');
	for (;;) {
		CAtlString strElement;
		if (tabPos > curPos) {
			strElement = strText.Mid(curPos, tabPos - curPos).Trim();
		}
		safeArray[index++] = MakeVariantNotArray(strElement);
		curPos = tabPos + 1;
		if (curPos == strText.GetLength()) {
			safeArray[index] = CComVariant(L"");
			break;
		}
		tabPos = strText.Find(L'\t', curPos);
		if (tabPos < 0) {
			safeArray[index] = MakeVariant(strText.Mid(curPos).Trim());
			break;
		}
	}
	return CComVariant(safeArray);
}