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; }
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; }