27class CharBlock :
public llvm::StringRef {
29 using llvm::StringRef::StringRef;
30 CharBlock(
const char *begin,
const char *end)
31 : llvm::StringRef(begin, end - begin) {}
32 CharBlock(
const char *begin) : llvm::StringRef(begin, 1) {}
36 bool Contains(
const CharBlock &that)
const {
37 uintptr_t thisBegin{
reinterpret_cast<uintptr_t
>(begin())};
38 uintptr_t thisEnd{
reinterpret_cast<uintptr_t
>(end())};
39 uintptr_t thatBegin{
reinterpret_cast<uintptr_t
>(that.begin())};
40 uintptr_t thatEnd{
reinterpret_cast<uintptr_t
>(that.end())};
41 return thisBegin <= thatBegin && thatEnd <= thisEnd;
44 void ExtendToCover(
const CharBlock &that) {
47 }
else if (!that.empty()) {
49 std::min(begin(), that.begin()), std::max(end(), that.end()));
55 char FirstNonBlank()
const {
56 size_t idx{LocateFirstNonBlank()};
57 return idx != npos ? data()[idx] :
' ';
62 char OnlyNonBlank()
const {
64 for (
char ch : *
this) {
65 if (ch !=
' ' && ch !=
'\t') {
76 size_t CountLeadingBlanks()
const {
77 size_t idx{LocateFirstNonBlank()};
78 return idx != npos ? idx : size();
81 bool IsBlank()
const {
return LocateFirstNonBlank() == npos; }
83 std::string ToString()
const {
return str(); }
86 std::string NULTerminatedToString()
const {
87 return std::string{begin(), strnlen(begin(), size())};
91 size_t LocateFirstNonBlank()
const {
92 return find_if_not([](
char c) {
return c ==
' ' || c ==
'\t'; });