BOOL CBCGPTagManager::ParseColor (const CString& strItem, CBCGPColor& value)
{
	CBCGPTagManager tm (strItem);

	CStringArray sa;

	CString strA, strR, strG, strB;

	tm.ExcludeTag (s_A, strA);
	strA.TrimLeft ();
	strA.TrimRight ();
	tm.ExcludeTag (s_R, strR);
	strR.TrimLeft ();
	strR.TrimRight ();
	tm.ExcludeTag (s_G, strG);
	strG.TrimLeft ();
	strG.TrimRight ();
	tm.ExcludeTag (s_B, strB);
	strB.TrimLeft ();
	strB.TrimRight ();

	if (strR.IsEmpty () || strG.IsEmpty () || strB.IsEmpty ())
	{
		if (!ParseString (strItem, _T(","), sa, TRUE, FALSE))
		{
			strR = tm.GetBuffer ();
			strR.TrimLeft ();
			strR.TrimRight ();

			sa.Add (strR);
		}
	}
	else
	{
		sa.Add (strR);
		sa.Add (strG);
		sa.Add (strB);

		if (!strA.IsEmpty ())
		{
			sa.Add (strA);
		}
	}

	if (sa.GetSize () > 0)
	{
		const int count = (int) sa.GetSize ();
		if (count >= 3)
		{
			value.r = bcg_clamp((double)_ttol(sa[0]) / 255.0, 0.0, 1.0);
			value.g = bcg_clamp((double)_ttol(sa[1]) / 255.0, 0.0, 1.0);
			value.b = bcg_clamp((double)_ttol(sa[2]) / 255.0, 0.0, 1.0);
			value.a = count == 4 ? bcg_clamp((double)_ttol(sa[3]) / 255.0, 0.0, 1.0) : 1.0;

			return TRUE;
		}
	}

	return FALSE;
}
BOOL CBCGPTagManager::ParsePoint (const CString& strItem, CPoint& value)
{
	CBCGPTagManager tm (strItem);

	CStringArray sa;

	CString strX, strY;

	tm.ExcludeTag (s_X, strX);
	strX.TrimLeft ();
	strX.TrimRight ();
	tm.ExcludeTag (s_Y, strY);
	strY.TrimLeft ();
	strY.TrimRight ();

	if (strX.IsEmpty () || strY.IsEmpty ())
	{
		if (!ParseString (tm.GetBuffer (), _T(","), sa, TRUE, FALSE))
		{
			return FALSE;
		}
	}
	else
	{
		sa.Add (strX);
		sa.Add (strY);
	}

	if (sa.GetSize () == 2)
	{
		value.x = _ttol(sa[0]);
		value.y = _ttol(sa[1]);
		return TRUE;
	}

	return FALSE;
}
BOOL CBCGPTagManager::ParseSize (const CString& strItem, CSize& value)
{
	CBCGPTagManager tm (strItem);
	CStringArray sa;

	CString strW, strH;

	tm.ExcludeTag (s_Width, strW);
	strW.TrimLeft ();
	strW.TrimRight ();
	tm.ExcludeTag (s_Height, strH);
	strH.TrimLeft ();
	strH.TrimRight ();

	if (strW.IsEmpty () || strH.IsEmpty ())
	{
		if (!ParseString (tm.GetBuffer (), _T(","), sa, TRUE, FALSE))
		{
			return FALSE;
		}
	}
	else
	{
		sa.Add (strW);
		sa.Add (strH);
	}

	if (sa.GetSize () == 2)
	{
		value.cx = _ttol(sa[0]);
		value.cy = _ttol(sa[1]);
		return TRUE;
	}

	return FALSE;
}
BOOL CBCGPTagManager::ParseRect (const CString& strItem, CRect& value)
{
	CBCGPTagManager tm (strItem);

	CString str1;
	CString str2;

	tm.ExcludeTag (s_Offset, str1);
	str1.TrimLeft ();
	str1.TrimRight ();
	tm.ExcludeTag (s_Size, str2);
	str2.TrimLeft ();
	str2.TrimRight ();

	CPoint pt (0, 0);
	CSize  sz (0, 0);

	if (ParsePoint (str1, pt) && ParseSize (str2, sz))
	{
		value = CRect (pt, sz);
		return TRUE;
	}

	tm.SetBuffer (strItem);
	tm.ExcludeTag (s_LT, str1);
	str1.TrimLeft ();
	str1.TrimRight ();
	tm.ExcludeTag (s_RB, str2);
	str2.TrimLeft ();
	str2.TrimRight ();

	CPoint pt2 (0, 0);
	if (ParsePoint (str1, pt) && ParsePoint (str2, pt2))
	{
		value = CRect (pt, pt2);
		return TRUE;
	}

	CStringArray sa;

	CString strL, strT, strR, strB;

	tm.SetBuffer (strItem);

	tm.ExcludeTag (s_Left, strL);
	strL.TrimLeft ();
	strL.TrimRight ();
	tm.ExcludeTag (s_Top, strT);
	strT.TrimLeft ();
	strT.TrimRight ();
	tm.ExcludeTag (s_Right, strR);
	strR.TrimLeft ();
	strR.TrimRight ();
	tm.ExcludeTag (s_Bottom, strB);
	strB.TrimLeft ();
	strB.TrimRight ();

	if (strL.IsEmpty () || strT.IsEmpty () || strR.IsEmpty () || strB.IsEmpty ())
	{
		if (!ParseString (tm.GetBuffer (), _T(","), sa, TRUE, FALSE))
		{
			return FALSE;
		}
	}
	else
	{
		sa.Add (strL);
		sa.Add (strT);
		sa.Add (strR);
		sa.Add (strB);
	}

	if (sa.GetSize () == 4)
	{
		value.left   = _ttol(sa[0]);
		value.top    = _ttol(sa[1]);
		value.right  = _ttol(sa[2]);
		value.bottom = _ttol(sa[3]);
		return TRUE;
	}

	return FALSE;
}
BOOL CBCGPTagManager::ParseColor (const CString& strItem, COLORREF& value)
{
	CBCGPTagManager tm (strItem);

	CStringArray sa;

	CString strA, strR, strG, strB;

	tm.ExcludeTag (s_A, strA);
	strA.TrimLeft ();
	strA.TrimRight ();
	tm.ExcludeTag (s_R, strR);
	strR.TrimLeft ();
	strR.TrimRight ();
	tm.ExcludeTag (s_G, strG);
	strG.TrimLeft ();
	strG.TrimRight ();
	tm.ExcludeTag (s_B, strB);
	strB.TrimLeft ();
	strB.TrimRight ();

	if (strR.IsEmpty () || strG.IsEmpty () || strB.IsEmpty ())
	{
		if (!ParseString (strItem, _T(","), sa, TRUE, FALSE))
		{
			strR = tm.GetBuffer ();
			strR.TrimLeft ();
			strR.TrimRight ();

			sa.Add (strR);
		}
	}
	else
	{
		sa.Add (strR);
		sa.Add (strG);
		sa.Add (strB);

		if (!strA.IsEmpty ())
		{
			sa.Add (strA);
		}
	}

	if (sa.GetSize () > 0)
	{
		const int count = (int) sa.GetSize ();
		if (count == 3)
		{
			value = AddaptColor (RGB((BYTE)_ttol(sa[0]), (BYTE)_ttol(sa[1]), (BYTE)_ttol(sa[2])),
				m_clrBase, m_clrTarget);
			return TRUE;
		}
		else if (count == 4)
		{
			value = RGB((BYTE)_ttol(sa[0]), (BYTE)_ttol(sa[1]), (BYTE)_ttol(sa[2])) | (((DWORD)(BYTE)(_ttol(sa[3]))) << 24);
			return TRUE;
		}
		else if (count == 1)
		{
			value = (COLORREF)_ttol(sa[0]);
			return TRUE;
		}
	}

	return FALSE;
}