Remove direct references to absl ::string_view from tstring.h

PiperOrigin-RevId: 370097141
Change-Id: I2ef3776c9b54de4866098e702494925a0548a381
diff --git a/tensorflow/core/platform/BUILD b/tensorflow/core/platform/BUILD
index 27978cf..a046856 100644
--- a/tensorflow/core/platform/BUILD
+++ b/tensorflow/core/platform/BUILD
@@ -722,6 +722,7 @@
 cc_library(
     name = "stringpiece",
     hdrs = ["stringpiece.h"],
+    compatible_with = get_compatible_with_portable(),
     deps = [
         "@com_google_absl//absl/strings",
     ],
@@ -825,7 +826,7 @@
     compatible_with = get_compatible_with_portable(),
     deps = [
         ":cord",
-        "@com_google_absl//absl/strings",
+        ":stringpiece",
     ],
 )
 
@@ -1198,6 +1199,7 @@
     srcs = ["tstring_test.cc"],
     deps = [
         ":cord",
+        ":stringpiece",
         ":tstring",
         "//tensorflow/core:test",
         "//tensorflow/core:test_main",
diff --git a/tensorflow/core/platform/tstring.h b/tensorflow/core/platform/tstring.h
index 3fe1be2..60dbb85 100644
--- a/tensorflow/core/platform/tstring.h
+++ b/tensorflow/core/platform/tstring.h
@@ -23,19 +23,7 @@
 
 #include "tensorflow/core/platform/cord.h"
 #include "tensorflow/core/platform/ctstring.h"
-
-// TODO(dero): This include is temporary, and will be superfluous once
-// absl::string_view is aliased to std::string_view.
-#include "absl/strings/string_view.h"
-namespace absl {
-#ifdef ABSL_NAMESPACE_BEGIN
-ABSL_NAMESPACE_BEGIN
-#endif  // ABSL_NAMESPACE_BEGIN
-class AlphaNum;
-#ifdef ABSL_NAMESPACE_END
-ABSL_NAMESPACE_END
-#endif  // ABSL_NAMESPACE_END
-}  // namespace absl
+#include "tensorflow/core/platform/stringpiece.h"
 
 namespace tensorflow {
 
@@ -111,7 +99,7 @@
   tstring(const char* str, size_t len);
   tstring(const char* str);  // NOLINT TODO(b/147740521): Make explicit.
   tstring(size_t n, char c);
-  explicit tstring(const absl::string_view str);
+  explicit tstring(const StringPiece str);
 #ifdef PLATFORM_GOOGLE
   explicit tstring(const absl::Cord& cord);
 #endif  // PLATFORM_GOOGLE
@@ -130,7 +118,7 @@
   tstring& operator=(const std::string& str);
   tstring& operator=(const char* str);
   tstring& operator=(char ch);
-  tstring& operator=(const absl::string_view str);
+  tstring& operator=(const StringPiece str);
 #ifdef PLATFORM_GOOGLE
   tstring& operator=(const absl::Cord& cord);
 #endif  // PLATFORM_GOOGLE
@@ -154,7 +142,7 @@
   // TODO(b/147740521): Make explicit.
   operator std::string() const;  // NOLINT
   // TODO(b/147740521): Make explicit.
-  operator absl::string_view() const;  // NOLINT
+  operator StringPiece() const;  // NOLINT
 #ifdef PLATFORM_GOOGLE
   template <typename T,
             typename std::enable_if<std::is_same<T, absl::AlphaNum>::value,
@@ -202,7 +190,7 @@
   // View Assignment
   tstring& assign_as_view(const tstring& str);
   tstring& assign_as_view(const std::string& str);
-  tstring& assign_as_view(const absl::string_view str);
+  tstring& assign_as_view(const StringPiece str);
   tstring& assign_as_view(const char* str, size_t len);
   tstring& assign_as_view(const char* str);
 
@@ -256,7 +244,7 @@
 inline tstring::tstring(const std::string& str)
     : tstring(str.data(), str.size()) {}
 
-inline tstring::tstring(const absl::string_view str)
+inline tstring::tstring(const StringPiece str)
     : tstring(str.data(), str.size()) {}
 
 #ifdef PLATFORM_GOOGLE
@@ -312,7 +300,7 @@
   return *this;
 }
 
-inline tstring& tstring::operator=(const absl::string_view str) {
+inline tstring& tstring::operator=(const StringPiece str) {
   TF_TString_Copy(&tstr_, str.data(), str.size());
 
   return *this;
@@ -388,15 +376,15 @@
   return std::string(data(), size());
 }
 
-inline tstring::operator absl::string_view() const {
-  return absl::string_view(data(), size());
+inline tstring::operator StringPiece() const {
+  return StringPiece(data(), size());
 }
 
 #ifdef PLATFORM_GOOGLE
 template <typename T, typename std::enable_if<
                           std::is_same<T, absl::AlphaNum>::value, T>::type*>
 inline tstring::operator T() const {
-  return T(absl::string_view(*this));
+  return T(StringPiece(*this));
 }
 #endif  // PLATFORM_GOOGLE
 
@@ -488,7 +476,7 @@
   return *this;
 }
 
-inline tstring& tstring::assign_as_view(const absl::string_view str) {
+inline tstring& tstring::assign_as_view(const StringPiece str) {
   assign_as_view(str.data(), str.size());
 
   return *this;
diff --git a/tensorflow/core/platform/tstring_test.cc b/tensorflow/core/platform/tstring_test.cc
index ced5dc9..f9b1f47 100644
--- a/tensorflow/core/platform/tstring_test.cc
+++ b/tensorflow/core/platform/tstring_test.cc
@@ -13,15 +13,15 @@
 limitations under the License.
 ==============================================================================*/
 
+#include "tensorflow/core/platform/tstring.h"
+
 #include <memory>
 #include <string>
 
 #include "tensorflow/core/platform/cord.h"
+#include "tensorflow/core/platform/stringpiece.h"
 #include "tensorflow/core/platform/test.h"
 
-// TODO(dero): fix ordering issue.
-#include "tensorflow/core/platform/tstring.h"  // NOLINT
-
 using tensorflow::tstring;
 
 static const char kLongString[] =
@@ -37,7 +37,7 @@
   tstring s11("a\0a", 3);
   tstring s12(kLongString);
   tstring s13(3, 'b');
-  tstring s14(absl::string_view("hi"));
+  tstring s14(tensorflow::StringPiece("hi"));
   tstring s15(std::string("bye"));
 
   EXPECT_EQ("", s10);
@@ -125,7 +125,7 @@
   EXPECT_EQ(tstring::Type::SMALL, s33.type());
   EXPECT_EQ(1, s33.size());
 
-  s32 = absl::string_view(kLongString);
+  s32 = tensorflow::StringPiece(kLongString);
 
   EXPECT_EQ(kLongString, s32);
   EXPECT_EQ(tstring::Type::LARGE, s32.type());
@@ -134,7 +134,8 @@
   // LARGE -> SMALL but still LARGE
   s32.resize(TF_TString_SmallCapacity * 2);
 
-  EXPECT_EQ(absl::string_view(kLongString, TF_TString_SmallCapacity * 2), s32);
+  EXPECT_EQ(tensorflow::StringPiece(kLongString, TF_TString_SmallCapacity * 2),
+            s32);
   EXPECT_EQ(tstring::Type::LARGE, s32.type());
   EXPECT_EQ(TF_TString_SmallCapacity * 2, s32.size());
 
@@ -173,7 +174,7 @@
 
   EXPECT_EQ(2, s33.size());
 
-  s32.assign_as_view(absl::string_view(kLongString));
+  s32.assign_as_view(tensorflow::StringPiece(kLongString));
 
   EXPECT_EQ(tstring::Type::VIEW, s32.type());
   EXPECT_EQ(kLongString, s32.c_str());
@@ -254,7 +255,7 @@
 TEST(TF_TStringTest, Conversion) {
   tstring s50(kLongString);
   std::string s51(s50);
-  absl::string_view s52(s50);
+  tensorflow::StringPiece s52(s50);
   EXPECT_EQ(kLongString, s51);
   EXPECT_EQ(kLongStringLen, s51.size());
   EXPECT_EQ(kLongString, s52);