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

Add a C API for on_end_tag #121

Merged
merged 3 commits into from
Dec 24, 2021
Merged

Add a C API for on_end_tag #121

merged 3 commits into from
Dec 24, 2021

Conversation

jyn514
Copy link
Contributor

@jyn514 jyn514 commented Dec 23, 2021

  • Expose Element::on_end_tag
  • Expose all the methods of EndTag (name, set_name, before, after, remove)
  • Add a new EndTag::set_name_str function to make sure it uses the proper encoding. Using
    set_name would require blindly assuming that the rewriter always used UTF8.
    This API can be slightly more efficient once Allow passing String to Encoding::encode hsivonen/encoding_rs#77 is merged, but I'm not sure how long it will take, so it might be better to just merge this as-is and make a breaking change eventually.
  • Add a test to ensure all the new API works correctly

Fixes #85

This makes the error checking less verbose, and also prints a much better
error if a check fails.
This does several things:
- Expose `Element::on_end_tag`
- Expose all the methods of `EndTag` (`name`, `set_name`, `before`, `after`, `remove`)
- Add a new `EndTag::set_name_str` function to make sure it uses the proper encoding. Using
    `set_name` would require blindly assuming that the rewriter always used UTF8.
- Add a test to ensure all the new API works correctly
@jyn514 jyn514 requested a review from a team as a code owner December 23, 2021 21:34
@kornelski
Copy link
Contributor

BTW, regarding string efficiency problem, you can do:

match encode(&string) {
   Cow::Owned(changed) => changed,
   Cow::Borrowed(_) => string,
}

This avoids an unnecessary copy if you already have an owned String.
@jyn514
Copy link
Contributor Author

jyn514 commented Dec 24, 2021

BTW, regarding string efficiency problem, you can do:

Oh, that's clever, thank you! I updated it to use that instead :)

@kornelski kornelski merged commit 2b2fb69 into master Dec 24, 2021
@kornelski kornelski deleted the jnelson/on_end_tag-c-api branch December 24, 2021 17:48
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.

Emit events for closing elements
2 participants