Modernize util/strencodings and util/string: `string_view` and `optional` #25001

pull MarcoFalke wants to merge 11 commits into bitcoin:master from MarcoFalke:2204-span-stuff-🐘 changing 22 files +209 −253
  1. MarcoFalke commented at 12:17 PM on April 27, 2022: member

    Make use of std::string_view and std::optional in the util/{strencodings, string} files.

    This avoids many temporary string/vector objects being created, while making the interface easier to read. Changes include:

    • Make all input arguments in functions in util/strencodings and util/string take std::string_view instead of std::string.
    • Add RemovePrefixView and TrimStringView which also return std::string_view objects (the corresponding RemovePrefix and TrimString keep returning an std::string, as that's needed in many call sites still).
    • Stop returning std::string from DecodeBase32 and DecodeBase64, but return vectors. Base32/64 are fundamentally algorithms for encoding bytes as strings; returning std::string from those (especially doing it conditionally based on the input arguments/types) is just bizarre.
    • Stop taking a bool* pf_invalid output argument pointer in DecodeBase32 and DecodeBase64; return an std::optional instead.
    • Make DecodeBase32 and DecodeBase64 more efficient by doing the conversion from characters to integer symbols on-the-fly rather than through a temporary vector.
  2. Make ParseHex use string_view c1d165a8c2
  3. Make IsHex use string_view 40062997f2
  4. Make IsHexNumber use string_view 963bc9b576
  5. Make SanitizeString use string_view d648b5120b
  6. Reject incorrect base64 in HTTP auth
    In addition, to make sure that no call site ignores the invalid
    decoding status, make the pf_invalid argument mandatory.
    a4377a0843
  7. Make DecodeBase{32,64} always return vector, not string
    Base32/base64 are mechanisms for encoding binary data. That they'd
    decode to a string is just bizarre. The fact that they'd do that
    based on the type of input arguments even more so.
    a65931e3ce
  8. Make DecodeBase{32,64} return optional instead of taking bool* 78f3ac51b7
  9. Generalize ConvertBits to permit transforming the input 1a72d62152
  10. Make DecodeBase{32,64} take string_view arguments 8ffbd1412d
  11. Use std::string_view throughout util strencodings/string e7d2fbda63
  12. scripted-diff: Rename ValidAsCString to ContainsNoNUL
    -BEGIN VERIFY SCRIPT-
     sed -i 's,ValidAsCString,ContainsNoNUL,g' $(git grep -l ValidAsCString)
    -END VERIFY SCRIPT-
    fa7078d84f
  13. MarcoFalke commented at 12:17 PM on April 27, 2022: member

    Disclaimer: The description and most commits are stolen from #24764 (comment)

  14. MarcoFalke commented at 12:19 PM on April 27, 2022: member

    Previous review: #24764#pullrequestreview-937752519

    re-ACK fa7078d84fc2858a466bc1a85404f821df682538 only change is rebase and adding a scripted-diff 🍲

    <details><summary>Show signature</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    re-ACK fa7078d84fc2858a466bc1a85404f821df682538 only change is rebase and adding a scripted-diff 🍲
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUjYUQv/TURxeLbk3gryj4kDPgdoqT5a/1EOIBJ7kAM9bT/jzpxuqM9ZNOGSlIxu
    DmmVgwGwMxvxE0fd7WjxOrdYTSTIQfMwlPAJpSR3JCTHvh/xI1ew1Xmjq1iRTgcY
    6ma3XMavD9X54VbpH2tlMRj3F/Vhb5MHAQiJUU3v3vImst8BL+HfwB3fsXkYlsPe
    F5auWj58clyrtGRed5HnL4UDKLmLg95S/9jSUFh/6sIgxw7QNWbXhnNxtBDjuOLw
    EDpZd9NmhDBqmq6dx9wPQMEoYMDjeICXLciMzoUU6WI+Y7UuK5kdHrF+Y6/Jogqc
    Q9CLGkBOxUOACc+i115Q+SKykiibphLYvIrbSxv8etjbB4XFQNvJKL96UCUP9pa5
    h4vy/k9V2hspW9KRoazJevv90rb3m7sKG7yqRr4IurWcfTWW+oPv3Wff9uXbd4oQ
    AfQg2ql9wCHcC+3T/1o9GDJOkSf1xCDUCD/wReekhr8JuLiJhVvg9bUkUuPwOUa0
    Ddfn99lR
    =dVEV
    -----END PGP SIGNATURE-----
    

    </details>

  15. DrahtBot added the label GUI on Apr 27, 2022
  16. DrahtBot added the label P2P on Apr 27, 2022
  17. DrahtBot added the label RPC/REST/ZMQ on Apr 27, 2022
  18. DrahtBot added the label Utils/log/libs on Apr 27, 2022
  19. laanwj removed the label GUI on Apr 27, 2022
  20. laanwj removed the label RPC/REST/ZMQ on Apr 27, 2022
  21. laanwj removed the label P2P on Apr 27, 2022
  22. laanwj added the label Refactoring on Apr 27, 2022
  23. martinus commented at 1:34 PM on April 27, 2022: contributor

    Code review ACK fa7078d84fc2858a466bc1a85404f821df682538, found no issue

  24. laanwj commented at 2:39 PM on April 27, 2022: member

    Code review ACK fa7078d84fc2858a466bc1a85404f821df682538

  25. fanquake requested review from laanwj on Apr 27, 2022
  26. sipa commented at 2:43 PM on April 27, 2022: member

    utACK fa7078d84fc2858a466bc1a85404f821df682538 (as far as the commit that isn't mine goes)

  27. laanwj referenced this in commit 132d5f8c2f on Apr 27, 2022
  28. fanquake closed this on Apr 27, 2022

  29. MarcoFalke deleted the branch on Apr 27, 2022
  30. sidhujag referenced this in commit 96c6c84796 on Apr 29, 2022
  31. MarcoFalke referenced this in commit 4cd6b3b557 on Dec 21, 2022
  32. sidhujag referenced this in commit 616b95a3f5 on Dec 21, 2022
  33. DrahtBot locked this on Apr 27, 2023

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-04-13 15:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me