Files
carbon-lang/common/string_helpers.h
T
Jon Meow 20728dbd3a CARBON_ header guards (#1261)
This modifies scripts/check_header_guards.py to add the CARBON_ prefix; everything else is pre-commit.
2022-05-12 17:25:43 -07:00

36 lines
1.2 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_COMMON_STRING_HELPERS_H_
#define CARBON_COMMON_STRING_HELPERS_H_
#include <optional>
#include <string>
#include "common/error.h"
#include "llvm/ADT/StringRef.h"
namespace Carbon {
// Note llvm StringExtras has significant functionality which is intended to be
// complementary to this.
// Unescapes Carbon escape sequences in the source string. Returns std::nullopt
// on bad input. `is_block_string` enables escaping unique to block string
// literals, such as \<newline>.
auto UnescapeStringLiteral(llvm::StringRef source, bool is_block_string = false)
-> std::optional<std::string>;
// Parses a block string literal in `source`.
auto ParseBlockStringLiteral(llvm::StringRef source) -> ErrorOr<std::string>;
// Returns true if the pointer is in the string ref (including equality with
// `ref.end()`). This should be used instead of `<=` comparisons for
// correctness.
auto StringRefContainsPointer(llvm::StringRef ref, const char* ptr) -> bool;
} // namespace Carbon
#endif // CARBON_COMMON_STRING_HELPERS_H_