Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xml escape #260

Merged
merged 4 commits into from
Apr 29, 2024
Merged

Xml escape #260

merged 4 commits into from
Apr 29, 2024

Conversation

bbbgan
Copy link
Collaborator

@bbbgan bbbgan commented Apr 28, 2024

Support escape and unescape.
During serialization, the marco XML_ESCAPE_UNICODE control the attribute delimiter, and the macro XML_ESCAPE_UNICODE control if escape the unicode.

example:

  std::string str = R"(
  <text_t description="&quot;&lt;'&#x5c0f;&#24378;'&gt;&quot;">
    <ID ID'msg='{"msg&apos;reply": "it&apos;s ok"}'>&amp;&lt;&gt;</ID>
    <DisplayName>&#x5c0f;&#24378;</DisplayName>
  </text_t>
  )";
  using text_attr_t =
      iguana::xml_attr_t<text_t, std::map<std::string_view, std::string>>;
  auto validator = [](const text_attr_t& text) {
    auto v = text.value();
    auto attr = text.attr();
    assert(attr["description"] == R"("<'小强'>")");
    assert(v.ID.value() == R"(&<>)");
    assert(v.ID.attr()["ID'msg"] == R"({"msg'reply": "it's ok"})");
    assert(v.DisplayName == "小强");
  };
  text_attr_t text;
  iguana::from_xml(text, str);
  validator(text);
  std::string ss;
  iguana::to_xml<true>(text, ss);
  std::cout << ss << std::endl;

@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2024

Codecov Report

Attention: Patch coverage is 47.05882% with 36 lines in your changes are missing coverage. Please review.

Project coverage is 44.98%. Comparing base (fb6e6d5) to head (639fa70).

❗ Current head 639fa70 differs from pull request most recent head 4cc6cfb. Consider uploading reports for the commit 4cc6cfb to get more accurate results

Files Patch % Lines
example/xml_example.cpp 0.00% 16 Missing ⚠️
iguana/util.hpp 0.00% 16 Missing ⚠️
iguana/xml_util.hpp 0.00% 3 Missing ⚠️
iguana/xml_reader.hpp 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #260      +/-   ##
==========================================
- Coverage   45.02%   44.98%   -0.04%     
==========================================
  Files          46       46              
  Lines        5628     5644      +16     
==========================================
+ Hits         2534     2539       +5     
- Misses       3094     3105      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bbbgan bbbgan force-pushed the xml_escape branch 3 times, most recently from 639fa70 to fddd9dd Compare April 29, 2024 05:42
example/xml_example.cpp Outdated Show resolved Hide resolved
Copy link
Owner

@qicosmos qicosmos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bbbgan bbbgan merged commit d38797a into qicosmos:master Apr 29, 2024
19 of 20 checks passed
@bbbgan bbbgan deleted the xml_escape branch April 30, 2024 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants