Пример #1
0
int GetNumberParameter( const CStaticString &strParam, int nDefault )
{
  int nTotal = 0;
	if( strParam.GetLength() )
	{
		LPCTSTR p = strParam.GetData();
		LPCTSTR pEnd = strParam.GetEndPointer();
		while( p < pEnd && isspace( *p ))
		{
			p++;
		}
  
		TCHAR cSign = *p;
		if( cSign == _T('-') || cSign == _T('+') )
			p++;

		while( p < pEnd && isdigit( *p) )
		{
			nTotal = 10 * nTotal + (*p - _T('0') );     /* accumulate digit */
			p++;
		}

		if( cSign == _T('-') )
			nTotal = -nTotal;
	}
	else
	{
		nTotal = nDefault;
	}
	
	return nTotal;
}
BYTE DecodeCharset( const CStaticString &strCharSet )
{
	for( UINT u = 0; u < countof( g_arrCharSet ); u++ )
	{
		if( !_tcsnicmp( g_arrCharSet[ u ].m_pcszName, strCharSet.GetData(), strCharSet.GetLength() ) )
		{
			return g_arrCharSet[ u ].m_cCharSet;
		}
	}

	TRACE( _T("Unknown characters set\n") );
	return DEFAULT_CHARSET;
}
CHTMLParse::Align GetAlignmentFromString( const CStaticString &str, CHTMLParse::Align algDefault )
{
	if( str.GetLength() )
	{
		for( int n = 0; n < countof( g_arrAligns ); n++ )
		{
			if( !_tcsnicmp( g_arrAligns[ n ].m_str.GetData(), str.GetData(), str.GetLength() ) )
			{
				return g_arrAligns[ n].m_alg;
			}
		}
	}
	return algDefault;
}
Пример #4
0
bool ExtractStyle( LPCTSTR pcszStyle, UINT uLength, Style &style, CStaticString &strValue )
{
	LPTSTR pcszStyleEnd = _tcschr( pcszStyle, _T(':') );
	if( pcszStyleEnd )
	{
		CStaticString strStyleName( pcszStyle, pcszStyleEnd - pcszStyle );
		strStyleName.TrimBoth();
		TRACE( _T("Style Name: %s\n"), (LPCTSTR)CSimpleString( strStyleName, strStyleName.GetLength() ) );
		Style *pStyle = g_mapStyle.Lookup( strStyleName );
		if( pStyle )
		{
			style = *pStyle;
			pcszStyleEnd++;
			strValue.Set( pcszStyleEnd, uLength - ( pcszStyleEnd - pcszStyle ) );
			strValue.TrimBoth();
			TRACE( _T("Style Value: %s\n"), (LPCTSTR)CSimpleString( strValue, strValue.GetLength() ) );
			return true;
		}
	}
	return false;
}
Пример #5
0
void ParseStyles( const CStaticString &strStyle, CStyles &styles )
{
	if( g_mapStyle.GetSize() == 0 )
	{
		for( UINT n = 0; n < countof( g_tokens ); n++ )
		{
			g_mapStyle.SetAt( g_tokens[n].m_strName, g_tokens[n].m_style );
		}
	}

	Style style;
	CStaticString strValue;

	LPCTSTR pcszStart = strStyle;
	LPCTSTR pcszCurrent = strStyle;
	UINT uLength = strStyle.GetLength();
	while( pcszCurrent && uLength )
	{
		if( *pcszCurrent == _T(';') )
		{
			if( ExtractStyle( pcszStart, pcszCurrent - pcszStart, style, strValue ) )
			{
				CStylePair &sp = styles.Add();
				sp.m_strValue = strValue;
				sp.m_style = style;
			}
			pcszStart = pcszCurrent + 1;
		}
		pcszCurrent++;
		uLength--;
	}

	if( ExtractStyle( pcszStart, pcszCurrent - pcszStart, style, strValue ) )
	{
		CStylePair &sp = styles.Add();
		sp.m_strValue = strValue;
		sp.m_style = style;
	}


	
}
COLORREF GetColourFromString( const CStaticString &strColour, COLORREF crDefault)
//
//	Return the colour from the string passed.
//
//	Does a quick lookup to see if the string is oe of the standard colours
//	if not it simple assumes the colour is in hex.
{
	if( !strColour.GetLength() )
		return crDefault;	// black

	LPCTSTR pcszColour = strColour.GetData();

	if( *pcszColour == '#' )
	{
		pcszColour++;

		//
		//	This bit of code adapted from the mozilla source for the same purpose.
		const int nLength = strColour.GetLength() - 1;
		int nBytesPerColour = min( nLength / 3, 2 );
		int rgb[3] = { 0, 0, 0 };
		for( int nColour = 0; nColour < 3; nColour++ )
		{
			int val = 0;
			for( int nByte = 0; nByte < nBytesPerColour; nByte++ )
			{
				int c = 0;
				if( *pcszColour )
				{
					c = tolower( (TCHAR) *pcszColour );
					if( (c >= '0') && (c <= '9'))
					{
						c = c - '0';
					}
					else if( (c >= 'a') && ( c <= 'f') )
					{
						c = c - 'a' + 10;
					}
					else
					{
						c = 0;
					}
					val = (val << 4) + c;
					pcszColour++;
				}
			}
			rgb[ nColour ] = val;
		}

		return RGB( rgb[0], rgb[1], rgb[2] );
	}

	COLORREF *pcr = g_mapColour.Lookup( strColour );
	if( pcr )
	{
		return *pcr;
	}

	if( *pcszColour  )
	{
		//
		//	It's safe to use _tcstoul because the assumption that the data originally passed to us is zero terminated.
		//	That way even if the colour is *the* last item in the file _tcstoul will properly terminate!
		TCHAR *endptr;
		return _tcstoul( pcszColour, &endptr, 16 );
	}
	return crDefault;
}