Skip to content

_compareCommandNames should use locale-aware string comparisons #6953

Closed

Description

@jtippet

_compareCommandNames operates on strings that are presented to the end-user, so it should sort like a human, not by codepoint. I'm not sure whether this project prefers CompareStringEx or lstrcmp or some CRT routine.

Activity

  1. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Jul 16, 2020
  2. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Jul 16, 2020
  3. DHowett commented on Jul 16, 2020

    @DHowett
    Member

    If there's some STL wstring locale-sensitive compare, I'd index towards that one. Thanks for pointing this out!

  4. added
    Area-UserInterfaceIssues pertaining to the user interface of the Console or Terminal
    Help WantedWe encourage anyone to jump in on these.
    Issue-BugIt either shouldn't be doing this or needs an investigation.
    on Jul 17, 2020
  5. ghost removed
    Needs-Tag-FixDoesn't match tag requirements
    on Jul 17, 2020
  6. removed
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Jul 17, 2020
  7. Don-Vito commented on Oct 15, 2020

    @Don-Vito
    Contributor

    Dustin L. Howett (@DHowett) - is something like this STL enough?

    static bool _compareCommandNames(const Command& lhs, const Command& rhs)
    {
            const auto& f = std::use_facet<std::collate<wchar_t>>(std::locale());
            const auto lhsName = lhs.Name();
            const auto rhsName = rhs.Name();
            return f.compare(lhsName.data(), lhsName.data() + lhsName.size(), rhsName.data(), rhsName.data() + rhsName.size()) < 0;            
    }
    

    I am just confused what locale should we use.. just written commands in 3 languages and now wondering what should happen 😄

  8. PankajBhojwani commented on Oct 16, 2020

    @PankajBhojwani
    Contributor

    Based on what I see here, Don-Vito 's way seems the way to go, would you mind making a PR with the change?

  9. Don-Vito commented on Oct 16, 2020

    @Don-Vito
    Contributor

    PankajBhojwani - I can absolutely create a PR, but I am not sure what locale should be used. Is std::locale() good enough?

  10. PankajBhojwani commented on Oct 20, 2020

    @PankajBhojwani
    Contributor

    I think std::locale("") obtains the native locale (source), so that might be what we want actually. Will look into it more and let you know!

  11. PankajBhojwani commented on Oct 22, 2020

    @PankajBhojwani
    Contributor

    Don-Vito at this point I want to say it probably is a fine implementation for now, and to go ahead and make the PR for it if you'd like! We can handle potential issues in post

  12. Don-Vito commented on Oct 22, 2020

    @Don-Vito
    Contributor

    PankajBhojwani - great! I am creating one.

  13. ghost added
    In-PRThis issue has a related PR
    on Oct 22, 2020
  14. Don-Vito commented on Oct 23, 2020

    @Don-Vito
    Contributor

    PankajBhojwani - made it work by explicitly invoking winapi's GetUserDefaultLocaleName. Still need to cleanup the code but please take a look.

  15. ghost removed
    In-PRThis issue has a related PR
    on Nov 18, 2020
  16. zadjii-msft commented on Nov 19, 2020

    @zadjii-msft
    Member

    After some additional thought, we're going to try and solve this with #7039 instead. Thanks for all the investigation everyone!

  17. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-LocalizationArea-UserInterfaceIssues pertaining to the user interface of the Console or TerminalHelp WantedWe encourage anyone to jump in on these.Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsProduct-TerminalThe new Windows Terminal.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions