StringViewExtras.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===--- StringViewExtras.h ----------*- mode:c++;eval:(read-only-mode) -*-===//
  2. // Do not edit! See README.txt.
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-FileCopyrightText: Part of the LLVM Project
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // There are two copies of this file in the source tree. The one under
  11. // libcxxabi is the original and the one under llvm is the copy. Use
  12. // cp-to-llvm.sh to update the copy. See README.txt for more details.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef DEMANGLE_STRINGVIEW_H
  16. #define DEMANGLE_STRINGVIEW_H
  17. #include "DemangleConfig.h"
  18. #include <string_view>
  19. DEMANGLE_NAMESPACE_BEGIN
  20. inline bool starts_with(std::string_view self, char C) noexcept {
  21. return !self.empty() && *self.begin() == C;
  22. }
  23. inline bool starts_with(std::string_view haystack,
  24. std::string_view needle) noexcept {
  25. if (needle.size() > haystack.size())
  26. return false;
  27. haystack.remove_suffix(haystack.size() - needle.size());
  28. return haystack == needle;
  29. }
  30. DEMANGLE_NAMESPACE_END
  31. #endif