Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Open Source > Development Lib > Programming Language/Scripting Language &&
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
13 Star 69 Fork 22

johnsonyl/cpps

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
Tags (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
master
Branches (1)
Tags (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
Tags (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
cpps
/
libs
/
xml
/
xml.hpp
cpps
/
libs
/
xml
/
xml.hpp
xml.hpp 18.21 KB
Copy Edit Raw Blame History
johnsonyl authored 2021年02月18日 14:08 +08:00 . 2021年02月18日 更新
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
#pragma once
#include "cpps/cpps.h"
#include "rapidxml_adapter.hpp"
#include "rapidxml_adapter_print.hpp"
#include <iostream>
namespace cpps
{
class xml_attribute
{
friend class xml_node;
public:
xml_attribute()
{
attribute_ = std::make_shared<rapidxml_adapter::xml_attribute<char>>();
}
void create(cpps_value name, cpps_value value)
{
if (cpps_isstring(name))
{
std::string* str = cpps_get_string(name);
set_name(*str);
}
if (cpps_isstring(value))
{
std::string* str = cpps_get_string(value);
set_value(*str);
}
}
std::string name()
{
return attribute_->name();
}
std::string value()
{
return attribute_->value();
}
void set_name(std::string name)
{
attribute_->name(name);
}
void set_value(std::string value)
{
attribute_->value(value);
}
private:
std::shared_ptr<rapidxml_adapter::xml_attribute<char>> attribute_;
};
class xml_node
{
public:
xml_node()
{
node_ = std::make_shared<rapidxml_adapter::xml_node<char>>(rapidxml::node_element);
}
void create(cpps_value name, cpps_value value, cpps_value type_name)
{
if (cpps_isstring(name))
{
std::string* str = cpps_get_string(name);
set_name(*str);
}
if (cpps_isstring(value))
{
std::string* str = cpps_get_string(value);
set_value(*str);
}
if (cpps_isstring(type_name))
{
std::string* str = cpps_get_string(value);
set_type(*str);
}
}
std::string to_string()
{
std::stringstream ss;
ss << node_;
return ss.str();
}
std::string type()
{
switch (node_->type())
{
case rapidxml::node_document:
return "document";
case rapidxml::node_element:
return "element";
case rapidxml::node_data:
return "data";
case rapidxml::node_cdata:
return "cdata";
case rapidxml::node_comment:
return "comment";
case rapidxml::node_declaration:
return "declaration";
case rapidxml::node_doctype:
return "doctype";
case rapidxml::node_pi:
return "pi";
default:
return "none";
}
return "none";
}
std::string name()
{
return node_->name();
}
std::string value()
{
return node_->value();
}
xml_node* first_node(C* c, cpps_value name)
{
std::string node_name;
if (cpps_isstring(name))
{
node_name = *cpps_get_string(name);
}
xml_node* ret = nullptr;
std::shared_ptr<rapidxml_adapter::xml_node<char>> temp_node = node_->first_node(node_name);
if (temp_node)
{
cpps::object::create_with_classvar<xml_node>(c, &ret);
ret->node_ = temp_node;
}
return ret;
}
xml_node* last_node(C* c, cpps_value name)
{
std::string node_name;
if (cpps_isstring(name))
{
node_name = *cpps_get_string(name);
}
xml_node* ret = nullptr;
std::shared_ptr<rapidxml_adapter::xml_node<char>> temp_node = node_->last_node(node_name);
if (temp_node)
{
cpps::object::create_with_classvar<xml_node>(c, &ret);
ret->node_ = temp_node;
}
return ret;
}
xml_node* previous_node(C* c, xml_node* current, cpps_value name)
{
if (current == nullptr)
{
return last_node(c, name);
}
if (current->node_->parent() != node_)
{
cpps::error(c, "xml_node::previous_node current node must be self's child");
}
std::string node_name;
if (cpps_isstring(name))
{
node_name = *cpps_get_string(name);
}
xml_node* ret = nullptr;
std::shared_ptr<rapidxml_adapter::xml_node<char>> temp_node = node_->previous_node(current->node_, node_name);
if (temp_node)
{
cpps::object::create_with_classvar<xml_node>(c, &ret);
ret->node_ = temp_node;
}
return ret;
}
xml_node* next_node(C* c, xml_node* current, cpps_value name)
{
if (current == nullptr)
{
return first_node(c, name);
}
if (current->node_->parent() != node_)
{
cpps::error(c, "xml_node::next_node current node must be self's child");
}
std::string node_name;
if (cpps_isstring(name))
{
node_name = *cpps_get_string(name);
}
xml_node* ret = nullptr;
std::shared_ptr<rapidxml_adapter::xml_node<char>> temp_node = node_->next_node(current->node_, node_name);
if (temp_node)
{
cpps::object::create_with_classvar<xml_node>(c, &ret);
ret->node_ = temp_node;
}
return ret;
}
xml_attribute* first_attribute(C* c, cpps_value name)
{
std::string attribute_name;
if (cpps_isstring(name))
{
attribute_name = *cpps_get_string(name);
}
xml_attribute* ret = nullptr;
std::shared_ptr<rapidxml_adapter::xml_attribute<char>> temp_attribute = node_->first_attribute(attribute_name);
if (temp_attribute)
{
cpps::object::create_with_classvar<xml_attribute>(c, &ret);
ret->attribute_ = temp_attribute;
}
return ret;
}
xml_attribute* last_attribute(C* c, cpps_value name)
{
std::string attribute_name;
if (cpps_isstring(name))
{
attribute_name = *cpps_get_string(name);
}
xml_attribute* ret = nullptr;
std::shared_ptr<rapidxml_adapter::xml_attribute<char>> temp_attribute = node_->last_attribute(attribute_name);
if (temp_attribute)
{
cpps::object::create_with_classvar<xml_attribute>(c, &ret);
ret->attribute_ = temp_attribute;
}
return ret;
}
xml_attribute* previous_attribute(C* c, xml_attribute* current, cpps_value name)
{
if (current == nullptr)
{
return last_attribute(c, name);
}
if (current->attribute_->parent() != node_)
{
cpps::error(c, "xml_node::previous_attribute current attribute must be self's child");
}
std::string attribute_name;
if (cpps_isstring(name))
{
attribute_name = *cpps_get_string(name);
}
xml_attribute* ret = nullptr;
std::shared_ptr<rapidxml_adapter::xml_attribute<char>> temp_attribute = node_->previous_attribute(current->attribute_, attribute_name);
if (temp_attribute)
{
cpps::object::create_with_classvar<xml_attribute>(c, &ret);
ret->attribute_ = temp_attribute;
}
return ret;
}
xml_attribute* next_attribute(C* c, xml_attribute* current, cpps_value name)
{
if (current == nullptr)
{
return first_attribute(c, name);
}
if (current->attribute_->parent() != node_)
{
cpps::error(c, "xml_node::next_attribute current attribute must be self's child");
}
std::string attribute_name;
if (cpps_isstring(name))
{
attribute_name = *cpps_get_string(name);
}
xml_attribute* ret = nullptr;
std::shared_ptr<rapidxml_adapter::xml_attribute<char>> temp_attribute = node_->next_attribute(current->attribute_, attribute_name);
if (temp_attribute)
{
cpps::object::create_with_classvar<xml_attribute>(c, &ret);
ret->attribute_ = temp_attribute;
}
return ret;
}
cpps_value children(C* c, cpps_value name)
{
std::string node_name;
if (cpps_isstring(name))
{
node_name = *cpps_get_string(name);
}
return xml_node::children_to_cpps_value(c, node_name);
}
cpps_value attributes(C* c, cpps_value name)
{
std::string attribute_name;
if (cpps_isstring(name))
{
attribute_name = *cpps_get_string(name);
}
return xml_node::attributes_to_cpps_value(c, attribute_name);
}
void set_type(std::string type_name)
{
static const std::map<std::string, rapidxml::node_type> node_type_by_name = {
{"document", rapidxml::node_document},
{"element", rapidxml::node_element},
{"data", rapidxml::node_data},
{"cdata", rapidxml::node_cdata},
{"comment", rapidxml::node_comment},
{"declaration", rapidxml::node_declaration},
{"doctype", rapidxml::node_doctype},
{"pi", rapidxml::node_pi},
};
auto iter = node_type_by_name.find(type_name);
if (iter != node_type_by_name.end())
{
node_->type(iter->second);
}
}
void set_name(std::string name)
{
node_->name(name);
}
void set_value(std::string value)
{
node_->value(value);
}
void prepend_node(C* c, xml_node* node)
{
if (node == nullptr)
{
cpps::error(c, "xml_node::prepend_node new node is nil");
}
if (node->node_->parent())
{
cpps::error(c, "xml_node::prepend_node new node must not have parent");
}
if (node->node_->type() == rapidxml::node_document)
{
cpps::error(c, "xml_node::prepend_node new node must not be a document node");
}
node_->prepend_node(node->node_);
}
void append_node(C* c, xml_node* node)
{
if (node == nullptr)
{
cpps::error(c, "xml_node::append_node new node is nil");
}
if (node->node_->parent())
{
cpps::error(c, "xml_node::append_node new node must not have parent");
}
if (node->node_->type() == rapidxml::node_document)
{
cpps::error(c, "xml_node::append_node new node must not be a document node");
}
node_->append_node(node->node_);
}
void insert_node(C* c, xml_node* where, xml_node* node)
{
if (where == nullptr)
{
append_node(c, node);
}
if (where->node_->parent() != node_)
{
cpps::error(c, "xml_node::insert_node where node must be self's child");
}
if (node == nullptr)
{
cpps::error(c, "xml_node::insert_node new node is nil");
}
if (node->node_->parent())
{
cpps::error(c, "xml_node::insert_node new node must not have parent");
}
if (node->node_->type() == rapidxml::node_document)
{
cpps::error(c, "xml_node::insert_node new node must not be a document node");
}
node_->insert_node(where->node_, node->node_);
}
void remove_first_node(C* c)
{
if (!node_->first_node())
{
cpps::error(c, "xml_node::remove_first_node has no child to remove");
}
node_->remove_first_node();
}
void remove_last_node(C* c)
{
if (!node_->first_node())
{
cpps::error(c, "xml_node::remove_last_node has no child to remove");
}
node_->remove_last_node();
}
void remove_node(C* c, xml_node* node)
{
if (node == nullptr)
{
cpps::error(c, "xml_node::remove_node node is nil");
}
if (node->node_->parent() != node_)
{
cpps::error(c, "xml_node::insert_node node must be self's child");
}
node_->remove_node(node->node_);
}
void remove_all_nodes()
{
node_->remove_all_nodes();
}
void prepend_attribute(C* c, xml_attribute* attribute)
{
if (attribute == nullptr)
{
cpps::error(c, "xml_node::prepend_attribute new attribute is nil");
}
if (attribute->attribute_->parent())
{
cpps::error(c, "xml_node::prepend_attribute new attribute must not have parent");
}
node_->prepend_attribute(attribute->attribute_);
}
void append_attribute(C* c, xml_attribute* attribute)
{
if (attribute == nullptr)
{
cpps::error(c, "xml_node::append_attribute new attribute is nil");
}
if (attribute->attribute_->parent())
{
cpps::error(c, "xml_node::append_attribute new attribute must not have parent");
}
node_->append_attribute(attribute->attribute_);
}
void insert_attribute(C* c, xml_attribute* where, xml_attribute* attribute)
{
if (where == nullptr)
{
append_attribute(c, attribute);
}
if (where->attribute_->parent() != node_)
{
cpps::error(c, "xml_node::insert_attribute where attribute must be self's child");
}
if (attribute == nullptr)
{
cpps::error(c, "xml_node::insert_attribute new attribute is nil");
}
if (attribute->attribute_->parent())
{
cpps::error(c, "xml_node::insert_attribute new attribute must not have parent");
}
node_->insert_attribute(where->attribute_, attribute->attribute_);
}
void remove_first_attribute(C* c)
{
if (!node_->first_attribute())
{
cpps::error(c, "xml_node::remove_first_attribute has no attribute to remove");
}
node_->remove_first_attribute();
}
void remove_last_attribute(C* c)
{
if (!node_->first_attribute())
{
cpps::error(c, "xml_node::remove_last_attribute has no attribute to remove");
}
node_->remove_last_attribute();
}
void remove_attribute(C* c, xml_attribute* attribute)
{
if (attribute == nullptr)
{
cpps::error(c, "xml_node::remove_attribute attribute is nil");
}
if (attribute->attribute_->parent() != node_)
{
cpps::error(c, "xml_node::remove_attribute attribute must be self's child");
}
node_->remove_attribute(attribute->attribute_);
}
void remove_all_attributes()
{
node_->remove_all_attributes();
}
private:
cpps_value children_to_cpps_value(C* c, const std::string& name = std::string())
{
cpps_vector* ret_vec;
cpps_value ret;
newclass<cpps_vector>(c, &ret_vec,&ret);
for(auto child : node_->children(name))
{
xml_node* ret_node;
cpps_value node_value;
newclass<xml_node>(c, &ret_node,&node_value);
ret_node->node_ = child;
ret_vec->push_back(node_value);
}
return ret;
}
cpps_value attributes_to_cpps_value(C* c, const std::string &name = std::string())
{
cpps_vector* ret_vec;
cpps_value ret;
newclass<cpps_vector>(c, &ret_vec,&ret);
for(auto attr : node_->attributes(name))
{
xml_attribute* ret_attr;
cpps_value attr_value;
newclass<xml_attribute>(c, &ret_attr,&attr_value);
ret_attr->attribute_ = attr;
ret_vec->push_back(attr_value);
}
return ret;
}
protected:
std::shared_ptr<rapidxml_adapter::xml_node<char>> node_;
};
class xml_document : public xml_node
{
public:
xml_document()
{
node_ = std::make_shared<rapidxml_adapter::xml_document<char>>();
}
void parse( std::string str)
{
std::shared_ptr<rapidxml_adapter::xml_document<char>> doc_ = std::static_pointer_cast<rapidxml_adapter::xml_document<char>>(node_);
doc_->parse<rapidxml::parse_no_string_terminators>(str);
}
void clear()
{
std::shared_ptr<rapidxml_adapter::xml_document<char>> doc_ = std::static_pointer_cast<rapidxml_adapter::xml_document<char>>(node_);
doc_->clear();
}
};
void xml_check(C* c, bool expr, cpps_value info)
{
std::string info_str;
if (cpps_isstring(info))
{
info_str = *cpps_get_string(info);
}
if (!expr)
{
cpps::error(c, "xml_check fail [%s]!!!", info_str.c_str());
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

CPPS是一种轻量级的嵌入式脚本语言,其语法类似于C++。它具有当前主流语言的许多特性,包括协程、面向对象、lambda、闭包、泛型变量、自定义模块支持、GC垃圾收集和跨平台。CPPS将程序解释为字节码,通过内置语法解析在虚拟机中运行
Cancel

Releases (3)

All

The Open Source Evaluation Index is derived from the OSS Compass evaluation system, which evaluates projects around the following three dimensions

1. Open source ecosystem

  • Productivity: To evaluate the ability of open-source projects to output software artifacts and open-source value.
  • Innovation: Used to evaluate the degree of diversity of open source software and its ecosystem.
  • Robustness: Used to evaluate the ability of open-source projects to resist internal and external interference and self recover in the face of changing development environments.

2. Collaboration, People, Software

  • Collaboration: represents the degree and depth of collaboration in open source development behavior.
  • Observe the influence of core personnel in open source projects, and examine the evaluations of users and developers on open source projects from a third-party perspective.
  • Software: Evaluate the value of products exported from open-source projects and their ultimate destination. It is also a concrete manifestation of "open source software", one of the oldest mainstream directions in open source evaluation.

3. Evaluation model

    Based on the dimensions of "open source ecosystem" and "collaboration, people, and software", identify quantifiable indicators directly or indirectly related to this goal, quantitatively evaluate the health and ecology of open source projects, and ultimately form an open source evaluation index.

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cppscript/cpps.git
git@gitee.com:cppscript/cpps.git
cppscript
cpps
cpps
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /