Conversation
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
Contributor
|
BTW, regarding string efficiency problem, you can do: match encode(&string) {
Cow::Owned(changed) => changed,
Cow::Borrowed(_) => string,
} |
kornelski
approved these changes
Dec 24, 2021
This avoids an unnecessary copy if you already have an owned String.
Contributor
Author
Oh, that's clever, thank you! I updated it to use that instead :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Element::on_end_tagEndTag(name,set_name,before,after,remove)EndTag::set_name_strfunction to make sure it uses the proper encoding. Usingset_namewould require blindly assuming that the rewriter always used UTF8.This API can be slightly more efficient once Allow passing
StringtoEncoding::encodehsivonen/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.Fixes #85