string_helpers.h 992 B

12345678910111213141516171819202122232425262728293031
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef COMMON_STRING_HELPERS_H_
  5. #define COMMON_STRING_HELPERS_H_
  6. #include <optional>
  7. #include <string>
  8. #include "llvm/ADT/StringRef.h"
  9. #include "llvm/Support/Error.h"
  10. namespace Carbon {
  11. // Note llvm StringExtras has significant functionality which is intended to be
  12. // complementary to this.
  13. // Unescapes Carbon escape sequences in the source string. Returns std::nullopt
  14. // on bad input. `is_block_string` enables escaping unique to block string
  15. // literals, such as \<newline>.
  16. auto UnescapeStringLiteral(llvm::StringRef source, bool is_block_string = false)
  17. -> std::optional<std::string>;
  18. // Parses a block string literal in `source`.
  19. auto ParseBlockStringLiteral(llvm::StringRef source)
  20. -> llvm::Expected<std::string>;
  21. } // namespace Carbon
  22. #endif // COMMON_STRING_HELPERS_H_