⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 axmlite.cpp

📁 研读AxCrypt对加解密的处理方法
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                TCHAR* pEnd = _tcsechr( ++xml, chXMLTagOpen, chXMLEscape );
                if( pEnd == NULL ) 
                {
                    if( pi->erorr_occur == false ) 
                    {
                        pi->erorr_occur = true;
                        pi->error_pointer = xml;
                        pi->error_code = PIE_NOT_CLOSED;
                        pi->error_string.assign(name).append(" must be closed with </").append(name).append(">");
//                        pi->error_string.Format(_T("%s must be closed with </%s>"), name );
                    }
                    // error cos not exist CloseTag </TAG>
                    return NULL;
                }
                
                bool trim = pi->trim_value;
                TCHAR escape = pi->escape_value;
                //_SetString( xml, pEnd, &value, trim, chXMLEscape );
                _SetString( xml, pEnd, &value, trim, escape );

                xml = pEnd;
                // TEXTVALUE reference
                if( pi->entity_value && pi->entitys )
                    value = pi->entitys->Ref2Entity(value.c_str());
            }

            // generate child nodes
            while( xml && *xml )
            {
                LPXNode node = new XNode;
                node->parent = this;
                
                xml = node->Load( xml,pi );
                if (!node->name.empty()) {
                    childs.push_back( node );
                } else {
                    delete node;
                }

                // open/close tag <TAG ..> ... </TAG>
                //                             ^- current pointer
                // CloseTag case
                if( xml && *xml && *(xml+1) && *xml == chXMLTagOpen && *(xml+1) == chXMLTagPre )
                {
                    // </Close>
                    xml+=2; // C
                    
                    if( xml = _tcsskip( xml ) )
                    {
                        std::string closename;
                        TCHAR* pEnd = _tcspbrk( xml, " >" );
                        if( pEnd == NULL ) 
                        {
                            if( pi->erorr_occur == false ) 
                            {
                                pi->erorr_occur = true;
                                pi->error_pointer = xml;
                                pi->error_code = PIE_NOT_CLOSED;
                                pi->error_string.assign("it must be closed with </").append(name);
//                                pi->error_string.Format(_T("it must be closed with </%s>"), name );
                            }
                            // error
                            return NULL;
                        }
                        _SetString( xml, pEnd, &closename );
                        if( closename == this->name )
                        {
                            // wel-formed open/close
                            xml = pEnd+1;
                            // return '>' or ' ' after pointer
                            return xml;
                        }
                        else
                        {
                            xml = pEnd+1;
                            // not welformed open/close
                            if( pi->erorr_occur == false ) 
                            {
                                pi->erorr_occur = true;
                                pi->error_pointer = xml;
                                pi->error_code = PIE_NOT_NESTED;
                                pi->error_string.assign("'<").append(name).append("> ... </").append(closename).append(">' is not wel-formed.");
//                                pi->error_string.Format(_T("'<%s> ... </%s>' is not wel-formed."), name, closename );
                            }
                            return NULL;
                        }
                    }
                }
                else    // Alone child Tag Loaded
                        // else 秦具窍绰瘤 富酒具窍绰瘤 狼缴埃促.
                {
                    
                    //if( xml && this->value.IsEmpty() && *xml !=chXMLTagOpen )
                    if( xml && XIsEmptyString( value.c_str() ) && *xml !=chXMLTagOpen )
                    {
                        // Text Value 
                        TCHAR* pEnd = _tcsechr( xml, chXMLTagOpen, chXMLEscape );
                        if( pEnd == NULL ) 
                        {
                            // error cos not exist CloseTag </TAG>
                            if( pi->erorr_occur == false )  
                            {
                                pi->erorr_occur = true;
                                pi->error_pointer = xml;
                                pi->error_code = PIE_NOT_CLOSED;
                                pi->error_string.assign("it must be closed with </").append(name).append(">");
//                                pi->error_string.Format(_T("it must be closed with </%s>"), name );
                            }
                            return NULL;
                        }
                        
                        bool trim = pi->trim_value;
                        TCHAR escape = pi->escape_value;
                        //_SetString( xml, pEnd, &value, trim, chXMLEscape );
                        _SetString( xml, pEnd, &value, trim, escape );

                        xml = pEnd;
                        //TEXTVALUE
                        if( pi->entity_value && pi->entitys )
                            value = pi->entitys->Ref2Entity(value.c_str());
                    }
                }
            }
        }
    }

    return xml;
}

//========================================================
// Name   : GetXML
// Desc   : convert plain xml text from parsed xml attirbute
// Param  :
// Return : converted plain string
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
std::string _tagXMLAttr::GetXML( LPDISP_OPT opt /*= &optDefault*/ )
{
    std::string os;
    os.assign(name).append("=").push_back(opt->value_quotation_mark);
    os.append((opt->reference_value && opt->entitys) ? opt->entitys->Entity2Ref(value.c_str()) : value.c_str());
    os.push_back(opt->value_quotation_mark);
    os.append(" ");
    return os;
/*
    std::ostringstream os;
    //os << (LPCTSTR)name << "='" << (LPCTSTR)value << "' ";
    
    os << (LPCTSTR)name << "=" << (char)opt->value_quotation_mark 
        << (LPCTSTR)(opt->reference_value&&opt->entitys?opt->entitys->Entity2Ref(value):value) 
        << (char)opt->value_quotation_mark << " ";
    return os.str().c_str();
*/
}

//========================================================
// Name   : GetXML
// Desc   : convert plain xml text from parsed xml node
// Param  :
// Return : converted plain string
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
std::string _tagXMLNode::GetXML( LPDISP_OPT opt /*= &optDefault*/ )
{
    std::string os;

    os = "";

    // tab
    if (opt && opt->newline) {
        if (opt && opt->newline) {
            os += "\r\n";
        }
        for (int i = 0 ; i < opt->tab_base ; i++) {
            os += '\t';
        }
    }

    // <TAG
    os += "<";
    os += name;

    // <TAG Attr1="Val1" 
    if (!attrs.empty()) {
        os += ' ';
    }
    for (size_t i = 0 ; i < attrs.size(); i++) {
        os += attrs[i]->GetXML(opt);
    }
    
    if (childs.empty() && value.empty()) {
        // <TAG Attr1="Val1"/> alone tag 
        os += "/>";
    } else {
        // <TAG Attr1="Val1"> and get child
        os += ">";
        if (opt && opt->newline && !childs.empty()) {
            opt->tab_base++;
        }

        for (size_t i = 0 ; i < childs.size(); i++) {
            os += childs[i]->GetXML(opt);
        }
        
        // Text Value
        if (!XIsEmptyString(value.c_str())) {
            if (opt && opt->newline && !childs.empty()) {
                if (opt && opt->newline) {
                    os += "\r\n";
                }
                for (int i = 0; i < opt->tab_base; i++) {
                    os += '\t';
                }
            }
            os += (opt->reference_value && opt->entitys) ? opt->entitys->Entity2Ref(value.c_str()) : value;
//            os << (LPCTSTR)(opt->reference_value&&opt->entitys?opt->entitys->Entity2Ref(value):value);
        }

        // </TAG> CloseTag
        if (opt && opt->newline && !childs.empty()) {
            os += "\r\n";
            for (int i = 0 ; i < opt->tab_base-1 ; i++) {
                os += '\t';
            }
        }
        os += "</";
        os += name;
        os += ">";

        if (opt && opt->newline) {
            if (!childs.empty()) {
                opt->tab_base--;
            }
        }
    }
    
    return os;
}

//========================================================
// Name   : GetAttr
// Desc   : get attribute with attribute name
// Param  :
// Return : 
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
LPXAttr _tagXMLNode::GetAttr( LPCTSTR attrname ) {
    for (size_t i = 0 ; i < attrs.size(); i++ ) {
        LPXAttr attr = attrs[i];
        if (attr) {
            if (attr->name == attrname) {
                return attr;
            }
        }
    }
    return NULL;
}

//========================================================
// Name   : GetAttrs
// Desc   : find attributes with attribute name, return its list
// Param  :
// Return : 
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
XAttrs _tagXMLNode::GetAttrs(LPCTSTR name)
{
    XAttrs attrs;
    for (size_t i = 0 ; i < attrs.size(); i++) {
        LPXAttr attr = attrs[i];
        if (attr) {
            if (attr->name == name) {
                attrs.push_back(attr);
            }
        }
    }
    return attrs;
}

//========================================================
// Name   : GetAttrValue
// Desc   : get attribute with attribute name, return its value
// Param  :
// Return : 
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
LPCTSTR _tagXMLNode::GetAttrValue(LPCTSTR attrname) {
    XAttr *attr = GetAttr(attrname);
    return attr ? attr->value.c_str() : NULL;
}

XNodes _tagXMLNode::GetChilds() {
    return childs;
}

//========================================================
// Name   : GetChilds
// Desc   : Find childs with name and return childs list
// Param  :
// Return : 
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
XNodes _tagXMLNode::GetChilds(LPCTSTR name) {
    XNodes nodes;
    for (size_t i = 0 ; i < childs.size(); i++) {
        LPXNode node = childs[i];
        if (node) {
            if(node->name == name) {
                nodes.push_back(node);
            }
        }
    }
    return nodes;   
}

//========================================================
// Name   : GetChild
// Desc   : get child node with index
// Param  :
// Return : NULL return if no child.
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
XNode *_tagXMLNode::GetChild(size_t i) {
    if (i >= 0 && i < childs.size()) {
        return childs[i];
    }
    return NULL;
}

//========================================================
// Name   : GetChildCount
// Desc   : get child node count
// Param  :
// Return : 0 return if no child
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-12-26
//========================================================
size_t _tagXMLNode::GetChildCount()
{
    return childs.size();
}

//========================================================
// Name   : GetChild
// Desc   : Find child with name and return child
// Param  :
// Return : NULL return if no child.
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
LPXNode _tagXMLNode::GetChild(LPCTSTR name) {
    for (size_t i = 0 ; i < childs.size(); i++ ) {
        LPXNode node = childs[i];
        if (node) {
            if (node->name == name) {
                return node;
            }
        }
    }
    return NULL;
}

//========================================================
// Name   : GetChildValue
// Desc   : Find child with name and return child's value
// Param  :
// Return : NULL return if no child.
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
LPCTSTR _tagXMLNode::GetChildValue( LPCTSTR name )
{
    LPXNode node = GetChild(name);
    return (node != NULL) ? node->value.c_str() : NULL;
}

LPXAttr _tagXMLNode::GetChildAttr( LPCTSTR name, LPCTSTR attrname )
{
    LPXNode node = GetChild(name);
    return node ? node->GetAttr(attrname) : NULL;
}

LPCTSTR _tagXMLNode::GetChildAttrValue( LPCTSTR name, LPCTSTR attrname )
{
    LPXAttr attr = GetChildAttr( name, attrname );
    return attr ? attr->value.c_str() : NULL;
}


//========================================================
// Name   : GetChildIterator
// Desc   : get child nodes iterator
// Param  :
// Return : NULL return if no childs.
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
XNodes::iterator _tagXMLNode::GetChildIterator( LPXNode node )
{
    XNodes::iterator it = childs.begin();
    for( ; it != childs.end() ; ++(it) )
    {
        if( *it == node )
            return it;
    }
    return NULL;
}

//========================================================
// Name   : AppendChild

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -