Giter VIP home page Giter VIP logo

Comments (3)

Flamefire avatar Flamefire commented on July 26, 2024

Intrestingly the C++11 codecvt from GCC behaves differently: It does not consume any input and returns ok: https://godbolt.org/z/nASHeL

However https://en.cppreference.com/w/cpp/locale/codecvt/out mentions:

When performing N:M conversions, this function may return std::codecvt_base::partial after consuming all source characters (from_next == from_end). This means that another internal character is needed to complete the conversion (e.g. when converting UTF-16 to UTF-8, if the last character in the source buffer is a high surrogate).

But this is a "may".

from locale.

dimztimz avatar dimztimz commented on July 26, 2024

Intrestingly the C++11 codecvt from GCC behaves differently: It does not consume any input and returns ok: https://godbolt.org/z/nASHeL

The GCC codecvt's have some active bugs, don't take them as reference.

Regarding this bug, if the UTF-16 string ends with leading surrogate, partial should be returned, and if it ends with unpaired trailing surrogate, error should be returned. You would be more helpful if you post code that reproduces the bug.

from locale.

Flamefire avatar Flamefire commented on July 26, 2024

From my test suite (slightly adapted):

            char buf[4] = {};
            char* const to = buf;
            char* const to_end = buf + 4;
            char* to_next = to;
            const char16_t* err_utf = u"\xD800"; // Trailing UTF-16 surrogate
            std::mbstate_t mb = std::mbstate_t();
            const char16_t* from = err_utf;
            const char16_t* from_end = from + 1;
            const char16_t* from_next = from;
            cvt_type::result res = cvt.out(mb, from, from_end, from_next, to, to_end, to_next);

FWIW: The above OP contains a full explanation what happens where. Follow that to verify that indeed partial is not returned because the state is not checked.

from locale.

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.