[PATCH] D148547: Revert "[ADT] add StringViewExtras llvm::starts_with for std::string_view"

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 10:57:27 PDT 2023


nickdesaulniers created this revision.
nickdesaulniers added reviewers: MaskRay, erichkeane, chapuni.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This reverts commit d6d30dd9590b41fbcdc88b43767b27a31bfb1c73 <https://reviews.llvm.org/rGd6d30dd9590b41fbcdc88b43767b27a31bfb1c73>.

These helpers were added to be used by LLVMDemangle, which would be a
layering violation for that to depend on LLVMSupport. Undo this commit,
and I'll these these directly in LLVMDemangle.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148547

Files:
  llvm/include/llvm/ADT/StringViewExtras.h
  llvm/unittests/ADT/CMakeLists.txt
  llvm/unittests/ADT/StringViewExtrasTest.cpp


Index: llvm/unittests/ADT/StringViewExtrasTest.cpp
===================================================================
--- llvm/unittests/ADT/StringViewExtrasTest.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//===- StringExtrasTest.cpp - Unit tests for String extras ----------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ADT/StringViewExtras.h"
-#include "llvm/Support/raw_ostream.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-#include <string_view>
-
-using namespace llvm;
-
-TEST(StringViewExtrasTest, starts_with) {
-  std::string haystack = "hello world";
-  EXPECT_TRUE(llvm::starts_with(haystack, 'h'));
-  EXPECT_FALSE(llvm::starts_with(haystack, '\0'));
-  EXPECT_TRUE(llvm::starts_with(haystack, "hello"));
-  // TODO: should this differ from \0?
-  EXPECT_TRUE(llvm::starts_with(haystack, ""));
-
-  std::string empty;
-  EXPECT_FALSE(llvm::starts_with(empty, 'h'));
-  EXPECT_FALSE(llvm::starts_with(empty, '\0'));
-  EXPECT_FALSE(llvm::starts_with(empty, "hello"));
-  // TODO: should this differ from \0?
-  EXPECT_TRUE(llvm::starts_with(empty, ""));
-}
Index: llvm/unittests/ADT/CMakeLists.txt
===================================================================
--- llvm/unittests/ADT/CMakeLists.txt
+++ llvm/unittests/ADT/CMakeLists.txt
@@ -79,7 +79,6 @@
   StringRefTest.cpp
   StringSetTest.cpp
   StringSwitchTest.cpp
-  StringViewExtrasTest.cpp
   TinyPtrVectorTest.cpp
   TwineTest.cpp
   TypeSwitchTest.cpp
Index: llvm/include/llvm/ADT/StringViewExtras.h
===================================================================
--- llvm/include/llvm/ADT/StringViewExtras.h
+++ /dev/null
@@ -1,35 +0,0 @@
-//===- llvm/ADT/StringViewExtras.h - Useful string_view functions C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// This file contains some functions that are useful when dealing with
-/// string_views.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ADT_STRINGVIEWEXTRAS_H
-#define LLVM_ADT_STRINGVIEWEXTRAS_H
-
-#include <string_view>
-
-namespace llvm {
-
-// FIXME: std::string_view::starts_with is not available until C++20. Once LLVM
-// is upgraded to C++20, remove this header and users.
-
-inline constexpr bool starts_with(std::string_view self, char C) {
-  return !self.empty() && self.front() == C;
-}
-inline constexpr bool starts_with(std::string_view haystack,
-                                  std::string_view needle) {
-  return haystack.substr(0, needle.size()) == needle;
-}
-
-} // end namespace llvm
-
-#endif // LLVM_ADT_STRINGVIEWEXTRAS_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148547.514318.patch
Type: text/x-patch
Size: 3103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230417/d324a36f/attachment.bin>


More information about the llvm-commits mailing list