refactor: remove usage of locale dependent std::isspace #14585

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:no-locale-surprises-please changing 6 files +25 −13
  1. practicalswift commented at 5:00 PM on October 26, 2018: contributor

    Don't rely on locale dependent function std::isspace in base_blob<BITS>::SetHex(...) (uint256), DecodeBase58(...), ParseMoney(...) and ParseHex(...).

    Rationale:

    $ uname -s
    Darwin
    $ cat poc.cpp
    #include <iostream>
    #include <locale>
    
    int main(void) {
        setlocale(LC_ALL, "");
        std::cout << std::isspace(133) << ' ' << std::isspace(154) << ' ' << std::isspace(160);
        std::cout << '\n';
    }
    $ clang++ -o poc poc.cpp
    $ ./poc
    1 0 1
    $ LC_ALL=en_US ./poc
    1 0 1
    $ LC_ALL=C ./poc
    0 0 0
    $ LC_ALL=ru_RU.KOI8-R ./poc # an "interesting" locale
    0 1 0
    
  2. practicalswift force-pushed on Oct 26, 2018
  3. DrahtBot commented at 5:17 PM on October 26, 2018: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->Reviewers, this pull request conflicts with the following ones:

    • #14555 (Move util files to directory by jimpo)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. DrahtBot cross-referenced this on Oct 26, 2018 from issue Move util files to directory by jimpo
  5. practicalswift force-pushed on Oct 26, 2018
  6. practicalswift force-pushed on Oct 26, 2018
  7. Don't rely on locale dependent functions in base_blob<BITS>::SetHex(...) (uint256), DecodeBase58(...), ParseMoney(...) and ParseHex(...) 15db77f4dd
  8. practicalswift force-pushed on Oct 26, 2018
  9. sipa commented at 5:52 PM on October 26, 2018: member

    utACK 15db77f4dd7f1a7963398f1576580b577a1697bc

  10. MarcoFalke commented at 8:01 PM on October 26, 2018: member

    utACK 15db77f

  11. fanquake added the label Refactoring on Oct 26, 2018
  12. in src/utilstrencodings.h:85 in 15db77f4dd
      80 | + * same result as std::isspace.
      81 | + *
      82 | + * @param[in] c     character to test
      83 | + * @return          true if the argument is a whitespace character; otherwise false
      84 | + */
      85 | +constexpr inline bool IsSpace(char c) noexcept {
    


    Empact commented at 4:48 PM on October 27, 2018:
  13. in src/utilstrencodings.h:80 in 15db77f4dd
      75 | + * Tests if the given character is a whitespace character. The whitespace characters
      76 | + * are: space, form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal
      77 | + * tab ('\t'), and vertical tab ('\v').
      78 | + *
      79 | + * This function is locale independent. Under the C locale this function gives the
      80 | + * same result as std::isspace.
    


    Empact commented at 4:50 PM on October 27, 2018:

    nit: Could be more clear: ", giving the same result as std::isspace does under the C locale."

  14. Empact commented at 4:51 PM on October 27, 2018: member

    Could include a test comparing its output to std::isspace

  15. Empact commented at 4:51 PM on October 27, 2018: member

    utACK 15db77f

  16. fanquake renamed this:
    Don't rely on locale dependent functions in base_blob<BITS>::SetHex(...) (uint256), DecodeBase58(...), ParseMoney(...) and ParseHex(...)
    refactor: remove usage of locale dependent std::isspace
    on Oct 28, 2018
  17. fanquake commented at 2:40 AM on October 28, 2018: member

    ACK 15db77f

    Tested the same poc, other interesting locales:

    LC_ALL=it_IT.ISO8859-15 ./poc
    0 0 1
    LC_ALL=uk_UA.KOI8-U ./poc
    0 1 0
    LC_ALL=hu_HU.ISO8859-2 ./poc
    0 0 1
    
  18. pull[bot] referenced this in commit f1e2f2a859 on Oct 28, 2018
  19. MarcoFalke merged this on Oct 28, 2018
  20. MarcoFalke closed this on Oct 28, 2018

  21. bitcoin deleted a comment on Nov 21, 2018
  22. practicalswift cross-referenced this on Jan 20, 2020 from issue check std::to_string usage by fanquake
  23. practicalswift deleted the branch on Apr 10, 2021
  24. Munkybooty referenced this in commit aa0b72952d on Jul 22, 2021
  25. Munkybooty referenced this in commit 811dc19d3f on Jul 22, 2021
  26. Munkybooty referenced this in commit 3dfc8bc418 on Jul 23, 2021
  27. Munkybooty referenced this in commit a3245db8a7 on Jul 23, 2021
  28. PastaPastaPasta referenced this in commit cdd53d489e on Aug 16, 2021
  29. vijaydasmp referenced this in commit ed879057b1 on Sep 8, 2021
  30. vijaydasmp referenced this in commit 20b2940170 on Sep 8, 2021
  31. vijaydasmp referenced this in commit 75cfa2afdc on Sep 8, 2021
  32. vijaydasmp referenced this in commit aca7b80fc4 on Sep 9, 2021
  33. vijaydasmp referenced this in commit c97bb0e63b on Sep 9, 2021
  34. vijaydasmp referenced this in commit 208bb4989d on Sep 9, 2021
  35. dzutto referenced this in commit 6bb5dfe2d9 on Sep 9, 2021
  36. UdjinM6 referenced this in commit be2bd03370 on Sep 9, 2021
  37. gades referenced this in commit 81c628e4ed on May 9, 2022
  38. bitcoin locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:54 UTC