Code Monkey home page Code Monkey logo

Comments (4)

lopopolo avatar lopopolo commented on May 30, 2024 1

The CharIndices iterator is also used by:

  • ByteSlice::to_lowercase_into
  • ByteSlice::to_uppercase_into

They are not impacted by this bug, but I think adding a comment like this would be a good idea:

            // This branch coaleces invalid UTF-8 bytes and legitimate
            // occurrences of the Unicode replacement character. This is
            // acceptable since the replacement character does not lowercase
            // into a different character
            if ch == '\u{FFFD}' {

from bstr.

BurntSushi avatar BurntSushi commented on May 30, 2024

The current implementation of Debug will always output the replacement character as three byte escapes. Is this intended?

I would say probably not. It's a good point. I think something like your approach would work well: check if the bytes correspond to the UTF-8 encoding of the replacement codepoint, and if so, escape it like any other codepoint. Otherwise, right the raw bytes.

from bstr.

lopopolo avatar lopopolo commented on May 30, 2024

As an aside, I now know that \uFFFD is the replacement character after diving through the bstr source, but there is a core::char::REPLACEMENT_CHARACTER constant that I think would be nicer to use instead. I'm not sure if using it has MSRV implications.

from bstr.

BurntSushi avatar BurntSushi commented on May 30, 2024

@lopopolo Yeah, using the constant is probably the better thing to do. If you work with Unicode and UTF-8 as much as I do, then \uFFFD just becomes as natural as breathing! Hah. But yeah, a named constant would be clearer. It would be fine to use, since that constant was introduced in Rust 1.9. bstr's MSRV is much higher than that.

from bstr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.