예제 #1
0
/** Recursive clear function - searches recursively for a proper node
*  and finally clears the string map.
*
* \param[in] pNodePtr - pointer to a node to be processed
* \param[in] pszName - name of the property to search for in the given node
*/
void ini_cfg::clear(const tchar_t* pszName)
{
	if(pszName == NULL || pszName[0] == _t('*'))
		m_pMainNode->clear();
	else
	{
		tstring_t strSection;
		tstring_t strAttr;
		if(!parse_property_name(pszName, strSection, strAttr))
			THROW(_t("Invalid name"), 0, 0, 0);

		ini_storage::iterator iterSection = m_pMainNode->find(strSection);
		if(iterSection != m_pMainNode->end())
		{
			attr_storage& rAttrs = (*iterSection).second;
			std::pair<attr_storage::iterator, attr_storage::iterator> pairRange;

			if(strAttr == _t("*"))
			{
				pairRange.first = rAttrs.begin();
				pairRange.second = rAttrs.end();
			}
			else
				pairRange = (*iterSection).second.equal_range(strAttr);
			rAttrs.erase(pairRange.first, pairRange.second);
		}
	}
}
예제 #2
0
/** Function starts a search operation. Given the name of the property
*  to be searched for(ie. "ch/program/startup"), funtion searches for
*  itAttr and returns a handle that can be used by subsequent calls to the
*  find_next(). Free the handle using find_close() after finish.
*
* \param[in] pszName - name of the property to search for(in the form of
*						"ch/program/startup"
* \return Handle to the search (NULL if not found).
*/
ptr_t ini_cfg::find(const tchar_t* pszName)
{
	if(pszName == NULL || pszName[0] == _t('*'))
	{
		INIFINDHANDLE* pHandle = new INIFINDHANDLE;
		pHandle->bOnlyAttributes = false;
		pHandle->bSection = true;
		pHandle->itSection = m_pMainNode->begin();
		pHandle->itSectionEnd = m_pMainNode->end();

		return pHandle;
	}
	else
	{
		// parse the path
		tstring_t strSection;
		tstring_t strAttr;
		if(!parse_property_name(pszName, strSection, strAttr))
			return NULL;

		ini_storage::iterator iterSection = m_pMainNode->find(strSection);
		if(iterSection == m_pMainNode->end())
			return NULL;

		std::pair<attr_storage::iterator, attr_storage::iterator> pairRange;
		if(strAttr == _t("*"))
		{
			pairRange.first = (*iterSection).second.begin();
			pairRange.second = (*iterSection).second.end();
		}
		else
			pairRange = (*iterSection).second.equal_range(strAttr);
		if(pairRange.first != (*iterSection).second.end() && pairRange.first != pairRange.second)
		{
			INIFINDHANDLE* pHandle = new INIFINDHANDLE;
			pHandle->bSection = false;
			pHandle->bOnlyAttributes = true;
			pHandle->itAttr = pairRange.first;
			pHandle->itAttrEnd = pairRange.second;

			return pHandle;
		}
	}

	return NULL;
}
예제 #3
0
/** Sets the specified value in the given key name. Value can be either added to
*  the current ones (multi-string support) or replace them completely.
*
* \param[in] pszName - key name for which the string should be set at
* \param[in] pszValue - value to set
* \param[in] a - action to take while setting
*/
void ini_cfg::set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a)
{
	// parse the path
	tstring_t strSection;
	tstring_t strAttr;
	if(!parse_property_name(pszName, strSection, strAttr))
		THROW(_t("Property not found"), 0, 0, 0);

	if(strAttr == _t("*"))
		THROW(_t("Wildcards not available in set_value mode"), 0, 0, 0);

	// search
	ini_storage::iterator iterSection = m_pMainNode->find(strSection.c_str());
	if(iterSection == m_pMainNode->end())
	{
		std::pair<ini_storage::iterator, bool> pairSection = m_pMainNode->insert(ini_storage::value_type(strSection, attr_storage()));
		iterSection = pairSection.first;
		if(iterSection == m_pMainNode->end())
			THROW(_t("Problem with creating section"), 0, 0, 0);
	}

	attr_storage& rAttrs = (*iterSection).second;

	// clear if we're replacing
	switch(a)
	{
	case config_base::action_replace:
		{
			std::pair<attr_storage::iterator, attr_storage::iterator> pairRange = (*iterSection).second.equal_range(strAttr);
			rAttrs.erase(pairRange.first, pairRange.second);
			// do not break here - we are about to insert the data
		}
	case config_base::action_add:
		{
			rAttrs.insert(attr_storage::value_type(strAttr, pszValue ? pszValue : tstring_t(_t(""))));
			break;
		}
	default:
		assert(false);
	}
}
예제 #4
0
bool LVCssDeclaration::parse( const char * &decl )
{
    #define MAX_DECL_SIZE 512
    int buf[MAX_DECL_SIZE];
    int buf_pos = 0;

    if ( !decl )
        return false;

    skip_spaces( decl );
    if (*decl!='{')
        return false;
    decl++;
    while (*decl && *decl!='}') {
        skip_spaces( decl );
        css_decl_code prop_code = parse_property_name( decl );
        skip_spaces( decl );
        lString8 strValue;
        if (prop_code != cssd_unknown)
        {
            // parsed ok
            int n = -1;
            switch ( prop_code )
            {
            case cssd_display:
                n = parse_name( decl, css_d_names, -1 );
                break;
            case cssd_white_space:
                n = parse_name( decl, css_ws_names, -1 );
                break;
            case cssd_text_align:
                n = parse_name( decl, css_ta_names, -1 );
                break;
            case cssd_text_align_last:
                n = parse_name( decl, css_ta_names, -1 );
                break;
            case cssd_text_decoration:
                n = parse_name( decl, css_td_names, -1 );
                break;
            case cssd_hyphenate:
            case cssd_hyphenate2:
            case cssd_hyphenate3:
            case cssd_hyphenate4:
            	prop_code = cssd_hyphenate;
                n = parse_name( decl, css_hyph_names, -1 );
                if ( n==-1 )
                    n = parse_name( decl, css_hyph_names2, -1 );
                if ( n==-1 )
                    n = parse_name( decl, css_hyph_names3, -1 );
                break;
            case cssd_page_break_before:
                n = parse_name( decl, css_pb_names, -1 );
                break;
            case cssd_page_break_inside:
                n = parse_name( decl, css_pb_names, -1 );
                break;
            case cssd_page_break_after:
                n = parse_name( decl, css_pb_names, -1 );
                break;
            case cssd_list_style_type:
                n = parse_name( decl, css_lst_names, -1 );
                break;
            case cssd_list_style_position:
                n = parse_name( decl, css_lsp_names, -1 );
                break;
            case cssd_vertical_align:
                n = parse_name( decl, css_va_names, -1 );
                break;
            case cssd_font_family:
                {
                    lString8Collection list;
                    int processed = splitPropertyValueList( decl, list );
                    decl += processed;
                       n = -1;
                    if (list.length())
                    {
                        for (int i=list.length()-1; i>=0; i--)
                        {
                            const char * name = list[i].c_str();
                            int nn = parse_name( name, css_ff_names, -1 );
                            if (n==-1 && nn!=-1)
                            {
                                n = nn;
                            }
                            if (nn!=-1)
                            {
                                // remove family name from font list
                                list.erase( i, 1 );
                            }
                        }
                        strValue = joinPropertyValueList( list );
                    }
                }
                break;
            case cssd_font_style:
                n = parse_name( decl, css_fs_names, -1 );
                break;
            case cssd_font_weight:
                n = parse_name( decl, css_fw_names, -1 );
                break;
            case cssd_text_indent:
                {
                    // read length
                    css_length_t len;
                    bool negative = false;
                    if ( *decl == '-' ) {
                        decl++;
                        negative = true;
                    }
                    if ( parse_number_value( decl, len ) )
                    {
                        // read optional "hanging" flag
                        skip_spaces( decl );
                        int attr = parse_name( decl, css_ti_attribute_names, -1 );
                        if ( attr==0 || negative ) {
                            len.value = -len.value;
                        }
                        // save result
                        buf[ buf_pos++ ] = prop_code;
                        buf[ buf_pos++ ] = len.type;
                        buf[ buf_pos++ ] = len.value;
                    }
                }
                break;
            case cssd_line_height:
            case cssd_letter_spacing:
            case cssd_font_size:
            case cssd_width:
            case cssd_height:
            case cssd_margin_left:
            case cssd_margin_right:
            case cssd_margin_top:
            case cssd_margin_bottom:
            case cssd_padding_left:
            case cssd_padding_right:
            case cssd_padding_top:
            case cssd_padding_bottom:
                {
                    css_length_t len;
                    if ( parse_number_value( decl, len ) )
                    {
                        buf[ buf_pos++ ] = prop_code;
                        buf[ buf_pos++ ] = len.type;
                        buf[ buf_pos++ ] = len.value;
                    }
                }
                break;
            case cssd_margin:
            case cssd_padding:
		{
		    css_length_t len[4];
		    int i;
		    for (i = 0; i < 4; ++i)
			if (!parse_number_value( decl, len[i]))
			    break;
		    if (i)
		    {
			switch (i)
			{
			    case 1: len[1] = len[0]; /* fall through */
			    case 2: len[2] = len[0]; /* fall through */
			    case 3: len[3] = len[1];
			}
			buf[ buf_pos++ ] = prop_code;
			for (i = 0; i < 4; ++i)
			{
			    buf[ buf_pos++ ] = len[i].type;
			    buf[ buf_pos++ ] = len[i].value;
			}
		    }
		}
		break;
            case cssd_color:
            case cssd_background_color:
            {
                css_length_t len;
                if ( parse_color_value( decl, len ) )
                {
                    buf[ buf_pos++ ] = prop_code;
                    buf[ buf_pos++ ] = len.type;
                    buf[ buf_pos++ ] = len.value;
                }
            }
            break;
            case cssd_stop:
            case cssd_unknown:
            default:
                break;
            }
            if ( n!= -1)
            {
                // add enum property
                buf[buf_pos++] = prop_code;
                buf[buf_pos++] = n;
            }
            if (!strValue.empty())
            {
                // add string property
                if (prop_code==cssd_font_family)
                {
                    // font names
                    buf[buf_pos++] = cssd_font_names;
                    buf[buf_pos++] = strValue.length();
                    for (int i=0; i < strValue.length(); i++)
                        buf[buf_pos++] = strValue[i];
                }
            }
        }
        else
        {
            // error: unknown property?
        }
        next_property( decl );
    }

    // store parsed result
    if (buf_pos)
    {
        buf[buf_pos++] = cssd_stop; // add end marker
        _data = new int[buf_pos];
        for (int i=0; i<buf_pos; i++)
            _data[i] = buf[i];
    }

    // skip }
    skip_spaces( decl );
    if (*decl == '}')
    {
        decl++;
        return true;
    }
    return false;
}