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

Implement Display and Debug for CStr #547

Merged
merged 1 commit into from
Nov 17, 2021
Merged

Conversation

mbartlett21
Copy link

@mbartlett21 mbartlett21 commented Nov 10, 2021

This only prints ASCII characters and escapes the rest for Display and Debug.

(Fixes part of #534)

@ojeda
Copy link
Member

ojeda commented Nov 15, 2021

Thanks a lot for contributing!

A few comments:

  • Please squash the commits and sign them (in the Signed-off-by: sense) to show you agree with the Developer's Certificate of Origin (see Documentation/process/submitting-patches.rst).
  • I love what you did here (it is a great example of how to use pattern matching), but I don't think we need to parse UTF-8 in the kernel (at least for the usual logging). Printing ASCII printable characters and escaping the rest should be enough. Note that eventually we might get to remove all Unicode-related facilities.
  • As it is right now, it prints characters such as 0 as-it-is, rather than escaping them.

@mbartlett21
Copy link
Author

@ojeda

I have squashed and signed the commits.

With the utf8 parsing, I think I might instead see if I can get it in the standard library (it already has utf16 parsing)

@ojeda
Copy link
Member

ojeda commented Nov 16, 2021

I have squashed and signed the commits.

Thanks! It looks good to me (both the code and the commit). Could you please add a doc with an example (which would double as test)?

With the utf8 parsing, I think I might instead see if I can get it in the standard library (it already has utf16 parsing)

That would be great, yeah! Please let me know if you open the issue upstream, I would like to follow it.

Signed-off-by: Morgan Bartlett <mjmouse9999@gmail.com>
@mbartlett21
Copy link
Author

mbartlett21 commented Nov 17, 2021

That would be great, yeah! Please let me know if you open the issue upstream, I would like to follow it.

@ojeda
It seems that Rust already had a way to decode utf8 to chars, but it was deprecated and removed in favour of utilising core::str::from_utf8 and its error type.

Previous tracking issue: rust-lang/rust#33906
Example use of core::str::from_utf8: https://doc.rust-lang.org/std/str/struct.Utf8Error.html#examples

@ojeda ojeda merged commit f8a2c63 into Rust-for-Linux:rust Nov 17, 2021
@ojeda
Copy link
Member

ojeda commented Nov 17, 2021

Thanks!

@mbartlett21 mbartlett21 deleted the patch-1 branch February 1, 2023 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants