Files
carbon-lang/common/string_helpers.h
T
pk19604014andGeoff Romer 2017eb4da0 Initial implementation of block string literals following lexical_conventions/string_literals.md. (#1028)
* Initial implementation of block string literals following lexical_conventions/string_literals.md.

Enabled yyinput() in flex to implement parsing.
Added ParseBlockStringLiteral() helper to handler further transformations such as indenting.
Modified formar_grammar to support single-quoted strings to prevent a failure on lexer.lpp.

* Fixed _find_string_end quote parameter type int -> str.

* Update executable_semantics/syntax/BUILD

Co-authored-by: Geoff Romer <gromer@google.com>

* Addressed code review comments - split table-drived test into individual tests, renamed constants to match style guide.

* Addressed code review comments -- using EXPECT_THAT_EXPECTED() in tests, lexer comments and code cleanup.

Co-authored-by: Geoff Romer <gromer@google.com>
2022-01-21 13:11:18 -05:00

32 lines
992 B
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 COMMON_STRING_HELPERS_H_
#define COMMON_STRING_HELPERS_H_
#include <optional>
#include <string>
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.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)
-> llvm::Expected<std::string>;
} // namespace Carbon
#endif // COMMON_STRING_HELPERS_H_