decode_rust_punycode.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2024 The Abseil Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef ABSL_DEBUGGING_INTERNAL_DECODE_RUST_PUNYCODE_H_
  15. #define ABSL_DEBUGGING_INTERNAL_DECODE_RUST_PUNYCODE_H_
  16. #include "absl/base/config.h"
  17. #include "absl/base/nullability.h"
  18. namespace absl {
  19. ABSL_NAMESPACE_BEGIN
  20. namespace debugging_internal {
  21. struct DecodeRustPunycodeOptions {
  22. const char* punycode_begin;
  23. const char* punycode_end;
  24. char* out_begin;
  25. char* out_end;
  26. };
  27. // Given Rust Punycode in `punycode_begin .. punycode_end`, writes the
  28. // corresponding UTF-8 plaintext into `out_begin .. out_end`, followed by a NUL
  29. // character, and returns a pointer to that final NUL on success. On failure
  30. // returns a null pointer, and the contents of `out_begin .. out_end` are
  31. // unspecified.
  32. //
  33. // Failure occurs in precisely these cases:
  34. // - Any input byte does not match [0-9a-zA-Z_].
  35. // - The first input byte is an underscore, but no other underscore appears in
  36. // the input.
  37. // - The delta sequence does not represent a valid sequence of code-point
  38. // insertions.
  39. // - The plaintext would contain more than 256 code points.
  40. //
  41. // DecodeRustPunycode is async-signal-safe with bounded runtime and a small
  42. // stack footprint, making it suitable for use in demangling Rust symbol names
  43. // from a signal handler.
  44. absl::Nullable<char*> DecodeRustPunycode(DecodeRustPunycodeOptions options);
  45. } // namespace debugging_internal
  46. ABSL_NAMESPACE_END
  47. } // namespace absl
  48. #endif // ABSL_DEBUGGING_INTERNAL_DECODE_RUST_PUNYCODE_H_