string_helpers.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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 "common/error.h"
  9. #include "llvm/ADT/StringRef.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) -> ErrorOr<std::string>;
  20. // Returns true if the pointer is in the string ref (including equality with
  21. // `ref.end()`). This should be used instead of `<=` comparisons for
  22. // correctness.
  23. auto StringRefContainsPointer(llvm::StringRef ref, const char* ptr) -> bool;
  24. } // namespace Carbon
  25. #endif // COMMON_STRING_HELPERS_H_