Skip to content

Commit

Permalink
Prefer char::REPLACEMENT_CHARACTER over literal char or U+FFFD (#4793)
Browse files Browse the repository at this point in the history
Follow-up to #4786
  • Loading branch information
sffc committed Apr 10, 2024
1 parent 3412e3b commit aa39be9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions documents/process/style_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ Often in internationalization, we deal with code points from other scripts. It i
- If directly rendering the characters could cause confusion due to the bidi algorithm
- If the test cares more about the code point values than the characters they represent

Special case: if dealing with the Unicode replacement character U+FFFD, it is suggested to use [char::REPLACEMENT_CHARACTER](https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.REPLACEMENT_CHARACTER) instead of either a literal code point or the escape syntax.

### Render invisible characters in docs but escape them in code :: suggested

There are several types of invisible code points in Unicode, including whitespace, zero-width characters, and bidi marks. The policy surrounding these characters is:
Expand Down
2 changes: 1 addition & 1 deletion ffi/capi/src/utf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Writeable for PotentiallyInvalidUtf8<'_> {
);

out.push_str(valid);
out.push('�');
out.push(char::REPLACEMENT_CHARACTER);

// If there's more, we can use `write_to`
if let Some(error_len) = e.error_len() {
Expand Down

0 comments on commit aa39be9

Please sign in to comment.