mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 21:24:26 +08:00
Fixed: 1454724 Change-Id: Ideff961691d108176ebf09981d3665dffc81bca6 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4742599 Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Auto-Submit: Philip Pfaffe <pfaffe@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
// Copyright 2023 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
struct MyStringView {
|
|
explicit MyStringView(const std::string& s)
|
|
: the_string_(s), begin_(0), end_(s.size()) {}
|
|
MyStringView(const std::string& s, size_t begin, size_t length)
|
|
: the_string_(s), begin_(begin), end_(begin + length) {}
|
|
|
|
// NOLINTNEXTLINE
|
|
auto begin() const { return the_string_.begin() + begin_; }
|
|
// NOLINTNEXTLINE
|
|
auto end() const { return the_string_.begin() + end_; }
|
|
// NOLINTNEXTLINE
|
|
auto str() const { return the_string_.substr(begin_, end_ - begin_); }
|
|
// NOLINTNEXTLINE
|
|
auto size() const { return end_ - begin_; }
|
|
|
|
private:
|
|
// const std::string& the_string_;
|
|
const std::string& the_string_;
|
|
const size_t begin_, end_;
|
|
};
|
|
|
|
std::ostream& operator<<(std::ostream& o, const MyStringView& v) {
|
|
return o << v.str();
|
|
}
|
|
|
|
int main() {
|
|
std::string my_string = "Hello World!";
|
|
MyStringView full_view(my_string);
|
|
std::cout << "Full string: " << full_view << " (size=" << full_view.size()
|
|
<< ")\n";
|
|
MyStringView hello(my_string, 0, 6);
|
|
std::cout << "Hello string: " << hello << " (size=" << hello.size() << ")\n";
|
|
}
|