Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-101014

QAnyStringView should auto-detect ASCII in 8-bit constexpr inputs

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.4
    • None
    • None
    • 5
    • eaabd0c5450ad849e24878d38dd05d5b23d7eec3
    • Team B Foundation Sprint 53

    Description

      Currently, as per Qt policy, const char* are treated as being encoded in UTF-8. But most such strings are actually US-ASCII, and therefore valid Latin-1. QAnyStringView, which can contain both, should scan the string at construction time for any 8th-bit character, and having found none, adjust the UTF-8 tag to Latin1. This should be a compile-time check only, no runtime code, so it naturally only applies when some form of string literal is being passed.

      Acceptance criteria: The following tests (and others, with constexpr input) pass:

      static_assert(QAnyStringView("Hello, World").isLatin1());
      static_assert(QAnyStringView(u8"Hello, World").isLatin1());
      static_assert(QAnyStringView::fromArray("Hello, World").isLatin1());
      static_assert(QAnyStringView::fromArray(u8"Hello, World").isLatin1());
      

      (isLatin1()) is private API atm; we could make the test a friend of QAnyStringView or use

      any.visit([](auto view) { return std::is_same_v<decltype(view), QLatin1String>; })
      

      )

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            oyheskes Øystein Heskestad
            mmutz Marc Mutz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes