#include "tensorflow/core/framework/op_gen_lib.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/io/path.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
namespace tensorflow {
)";
void ExpectHasSubstr(StringPiece s, StringPiece expected) {
- EXPECT_TRUE(s.contains(expected))
+ EXPECT_TRUE(str_util::StrContains(s, expected))
<< "'" << s << "' does not contain '" << expected << "'";
}
void ExpectDoesNotHaveSubstr(StringPiece s, StringPiece expected) {
- EXPECT_FALSE(s.contains(expected))
+ EXPECT_FALSE(str_util::StrContains(s, expected))
<< "'" << s << "' contains '" << expected << "'";
}
#include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h"
+#include "tensorflow/core/lib/strings/str_util.h"
namespace tensorflow {
if (GetNodeAttr(attrs, kColocationAttrName, &node_constraints).ok()) {
for (const string& entry : node_constraints) {
StringPiece s(entry);
- if (s.Consume(kColocationGroupPrefix)) {
+ if (str_util::ConsumePrefix(&s, kColocationGroupPrefix)) {
current_constraints.insert(s.ToString());
}
}
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/io/path.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/test.h"
void ExpectErrorContains(const Status& status, StringPiece str) {
EXPECT_NE(Status::OK(), status);
- EXPECT_TRUE(StringPiece(status.error_message()).contains(str))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(), str))
<< "expected error: " << status.error_message() << " to contain: " << str;
}
"\n";
Status ReadProtoFile(const string& fname, protobuf::Message* proto) {
- if (StringPiece(fname).ends_with(".pbtxt")) {
+ if (str_util::EndsWith(fname, ".pbtxt")) {
return ReadTextProto(Env::Default(), fname, proto);
} else {
return ReadBinaryProto(Env::Default(), fname, proto);
// Otherwise, print e.g. "%constant.42 (s32[100])".
string constant_name;
- if (tensorflow::StringPiece(constant->name()).starts_with("constant")) {
+ if (tensorflow::str_util::StartsWith(constant->name(), "constant")) {
constant_name = constant->name();
} else {
constant_name = StrCat("constant ", constant->name());
// The HLO instruction name contains usually the opcode, e.g. "%add.42" is
// an add instruction. In this case we render just the name.
- if (tensorflow::StringPiece(instr->name())
- .starts_with(HloOpcodeString(instr->opcode()))) {
+ if (tensorflow::str_util::StartsWith(instr->name(),
+ HloOpcodeString(instr->opcode()))) {
return Printf("<b>%s</b>", HtmlLikeStringSanitize(instr->name()));
}
string extended_opcode =
TF_RETURN_IF_ERROR(LookUpRequest(handle).status());
}
- if (tensorflow::StringPiece(custom_call_request.call_target_name())
- .starts_with("$")) {
+ if (tensorflow::str_util::StartsWith(custom_call_request.call_target_name(),
+ "$")) {
return InvalidArgument(
"Invalid custom_call_target \"%s\": Call targets that start with '$' "
"are reserved for internal use.",
#include "tensorflow/compiler/xla/tests/test_macros.h"
#include "tensorflow/compiler/xla/tests/test_utils.h"
#include "tensorflow/compiler/xla/xla_data.pb.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/types.h"
namespace xla {
EXPECT_FALSE(IsConstant(computation, &b));
auto value = ComputeConstantScalar<float>(client, computation, &b);
- EXPECT_TRUE(tensorflow::StringPiece(value.status().ToString())
- .contains("depends on a parameter"))
+ EXPECT_TRUE(tensorflow::str_util::StrContains(value.status().ToString(),
+ "depends on a parameter"))
<< value.status();
}
}
EXPECT_FALSE(IsConstant(computation, &b));
auto value = ComputeConstantScalar<float>(client, computation, &b);
- EXPECT_TRUE(tensorflow::StringPiece(value.status().ToString())
- .contains("depends on a parameter"))
+ EXPECT_TRUE(tensorflow::str_util::StrContains(value.status().ToString(),
+ "depends on a parameter"))
<< value.status();
}
}
#include "tensorflow/compiler/xla/tests/test_utils.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/gtl/flatmap.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/regexp.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/types.h"
auto while_body_profile_start =
std::find_if(profile_output_lines.begin(), profile_output_lines.end(),
[](tensorflow::StringPiece s) {
- return s.starts_with("Execution profile for body");
+ return tensorflow::str_util::StartsWith(
+ s, "Execution profile for body");
});
ASSERT_NE(while_body_profile_start, profile_output_lines.end());
],
deps = [
":bigquery_table_accessor",
+ "//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core:protos_all_cc",
"//tensorflow/core:test",
#include "tensorflow/core/example/feature.pb.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/gtl/stl_util.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/cloud/http_request_fake.h"
#include "tensorflow/core/platform/test.h"
constexpr char kTestDataset[] = "test-dataset";
constexpr char kTestTable[] = "test-table";
-bool HasSubstr(const string& base, const string& substr) {
- bool ok = StringPiece(base).contains(substr);
+bool HasSubstr(StringPiece base, StringPiece substr) {
+ bool ok = str_util::StrContains(base, substr);
EXPECT_TRUE(ok) << base << ", expected substring " << substr;
return ok;
}
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/io/path.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/public/session.h"
// Expect failed session run calls with invalid run-options.
EXPECT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Invalid inter_op_thread_pool: 2"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Invalid inter_op_thread_pool: 2"))
<< status.error_message();
}
});
status_ = LoadSessionBundleFromPath(options_, path, &bundle_);
EXPECT_FALSE(status_.ok());
- EXPECT_TRUE(StringPiece(status_.error_message())
- .contains("Expected exactly one serving GraphDef"))
+ EXPECT_TRUE(str_util::StrContains(status_.error_message(),
+ "Expected exactly one serving GraphDef"))
<< status_.error_message();
}
});
status_ = LoadSessionBundleFromPath(options_, path, &bundle_);
EXPECT_FALSE(status_.ok());
- EXPECT_TRUE(StringPiece(status_.error_message())
- .contains("Expected Any type_url for: tensorflow.GraphDef"))
+ EXPECT_TRUE(
+ str_util::StrContains(status_.error_message(),
+ "Expected Any type_url for: tensorflow.GraphDef"))
<< status_.error_message();
}
});
status_ = LoadSessionBundleFromPath(options_, path, &bundle_);
EXPECT_FALSE(status_.ok());
- EXPECT_TRUE(StringPiece(status_.error_message()).contains("Failed to unpack"))
+ EXPECT_TRUE(
+ str_util::StrContains(status_.error_message(), "Failed to unpack"))
<< status_.error_message();
}
});
status_ = LoadSessionBundleFromPath(options_, path, &bundle_);
EXPECT_FALSE(status_.ok());
- EXPECT_TRUE(
- StringPiece(status_.error_message())
- .contains("Expected Any type_url for: tensorflow.serving.AssetFile"))
+ EXPECT_TRUE(str_util::StrContains(
+ status_.error_message(),
+ "Expected Any type_url for: tensorflow.serving.AssetFile"))
<< status_.error_message();
}
});
status_ = LoadSessionBundleFromPath(options_, path, &bundle_);
EXPECT_FALSE(status_.ok());
- EXPECT_TRUE(StringPiece(status_.error_message()).contains("Failed to unpack"))
+ EXPECT_TRUE(
+ str_util::StrContains(status_.error_message(), "Failed to unpack"))
<< status_.error_message();
}
});
status_ = LoadSessionBundleFromPath(options_, path, &bundle_);
EXPECT_FALSE(status_.ok());
- EXPECT_TRUE(StringPiece(status_.error_message())
- .contains("Expected exactly one serving init op"))
+ EXPECT_TRUE(str_util::StrContains(status_.error_message(),
+ "Expected exactly one serving init op"))
<< status_.error_message();
}
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/core/stringpiece.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/public/session.h"
namespace serving {
namespace {
-static bool HasSubstr(const string& base, const string& substr) {
- bool ok = StringPiece(base).contains(substr);
+static bool HasSubstr(StringPiece base, StringPiece substr) {
+ bool ok = str_util::StrContains(base, substr);
EXPECT_TRUE(ok) << base << ", expected substring " << substr;
return ok;
}
ClassificationSignature signature;
const Status status = GetClassificationSignature(meta_graph_def, &signature);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Expected a classification signature"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Expected a classification signature"))
<< status.error_message();
}
ClassificationSignature signature;
const Status status = GetClassificationSignature(meta_graph_def, &signature);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Expected a classification signature"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Expected a classification signature"))
<< status.error_message();
}
const Status status =
GetNamedClassificationSignature("foo", meta_graph_def, &signature);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Missing signature named \"foo\""))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Missing signature named \"foo\""))
<< status.error_message();
}
const Status status =
GetNamedClassificationSignature("foo", meta_graph_def, &signature);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(
- StringPiece(status.error_message())
- .contains("Expected a classification signature for name \"foo\""))
+ EXPECT_TRUE(str_util::StrContains(
+ status.error_message(),
+ "Expected a classification signature for name \"foo\""))
<< status.error_message();
}
RegressionSignature signature;
const Status status = GetRegressionSignature(meta_graph_def, &signature);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Expected a regression signature"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Expected a regression signature"))
<< status.error_message();
}
RegressionSignature signature;
const Status status = GetRegressionSignature(meta_graph_def, &signature);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Expected a regression signature"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Expected a regression signature"))
<< status.error_message();
}
Signature signature;
const Status status = GetNamedSignature("foo", meta_graph_def, &signature);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Missing signature named \"foo\""))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Missing signature named \"foo\""))
<< status.error_message();
}
const Status status = RunClassification(signature, input_tensor, &session,
&classes_tensor, nullptr);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message()).contains("Data is gone"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(), "Data is gone"))
<< status.error_message();
}
const Status status = RunClassification(signature, input_tensor, &session,
&classes_tensor, nullptr);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message()).contains("Expected 1 output"))
+ EXPECT_TRUE(
+ str_util::StrContains(status.error_message(), "Expected 1 output"))
<< status.error_message();
}
const Status status = RunClassification(signature, input_tensor, &session,
&classes_tensor, nullptr);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Input batch size did not match output batch size"))
+ EXPECT_TRUE(
+ str_util::StrContains(status.error_message(),
+ "Input batch size did not match output batch size"))
<< status.error_message();
}
const Status status =
RunRegression(signature_, input_tensor_, &session_, &output_tensor_);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message()).contains("Data is gone"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(), "Data is gone"))
<< status.error_message();
}
const Status status =
RunRegression(signature_, input_tensor_, &session_, &output_tensor_);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Input batch size did not match output batch size"))
+ EXPECT_TRUE(
+ str_util::StrContains(status.error_message(),
+ "Input batch size did not match output batch size"))
<< status.error_message();
}
const auto status = GetSignatures(meta_graph_def, &read_signatures);
EXPECT_EQ(tensorflow::error::FAILED_PRECONDITION, status.code());
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Expected exactly one"))
+ str_util::StrContains(status.error_message(), "Expected exactly one"))
<< status.error_message();
}
Signatures read_signatures;
const auto status = GetSignatures(meta_graph_def, &read_signatures);
EXPECT_EQ(tensorflow::error::FAILED_PRECONDITION, status.code());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Expected Any type_url for: "
- "tensorflow.serving.Signatures"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Expected Any type_url for: "
+ "tensorflow.serving.Signatures"))
<< status.error_message();
}
Signatures read_signatures;
const auto status = GetSignatures(meta_graph_def, &read_signatures);
EXPECT_EQ(tensorflow::error::FAILED_PRECONDITION, status.code());
- EXPECT_TRUE(StringPiece(status.error_message()).contains("Failed to unpack"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(), "Failed to unpack"))
<< status.error_message();
}
const auto status = GetSignatures(meta_graph_def, &read_signatures);
EXPECT_EQ(tensorflow::error::FAILED_PRECONDITION, status.code());
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Expected exactly one"))
+ str_util::StrContains(status.error_message(), "Expected exactly one"))
<< status.error_message();
}
const Status status =
GetGenericSignature("generic_bindings", meta_graph_def, &signature);
ASSERT_FALSE(status.ok());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("Expected a generic signature:"))
+ EXPECT_TRUE(str_util::StrContains(status.error_message(),
+ "Expected a generic signature:"))
<< status.error_message();
}
":utils",
"//tensorflow/core:core_cpu_base",
"//tensorflow/core:framework",
+ "//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc",
"//tensorflow/core/grappler:grappler_item",
"//tensorflow/core/grappler:utils",
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/grappler/costs/utils.h"
#include "tensorflow/core/grappler/utils.h"
+#include "tensorflow/core/lib/strings/str_util.h"
namespace tensorflow {
namespace grappler {
}
bool IsQueue(const Node& node) {
- StringPiece type(node.type_string());
- return type.ends_with("QueueV2");
+ return str_util::EndsWith(node.type_string(), "QueueV2");
}
// Returns true if the node is an Enter op AND its input is a Queue.
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/status_test_util.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/test.h"
EXPECT_TRUE(errors::IsOutOfRange(in.ReadNBytes(1, &read)));
EXPECT_TRUE(
- StringPiece(in.Seek(-1).ToString()).contains("negative position"));
+ str_util::StrContains(in.Seek(-1).ToString(), "negative position"));
}
}
#include "tensorflow/core/lib/io/record_reader.h"
#include "tensorflow/core/lib/io/record_writer.h"
#include "tensorflow/core/lib/random/simple_philox.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/test.h"
// Tests of all the error paths in log_reader.cc follow:
static void AssertHasSubstr(StringPiece s, StringPiece expected) {
- EXPECT_TRUE(StringPiece(s).contains(expected))
+ EXPECT_TRUE(str_util::StrContains(s, expected))
<< s << " does not contain " << expected;
}
return TensorToPython(value.tensor());
} else if (type == "func") {
return StringToPython(value.func().name());
- } else if (StringPiece(type).starts_with("list(")) {
+ } else if (str_util::StartsWith(type, "list(")) {
return strings::StrCat("[", AttrListToPython(value, dtype_module), "]");
} else {
return "?";
#include "tensorflow/core/lib/io/inputbuffer.h"
#include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/lib/strings/scanner.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/platform/logging.h"
// operators defined in <op type>_ops.cc
const char* kExecPrefix = "gen_";
const char* kExecSuffix = "_py_wrappers_cc";
- if (command_str.Consume(kExecPrefix) && command_str.ends_with(kExecSuffix)) {
+ if (str_util::ConsumePrefix(&command_str, kExecPrefix) &&
+ str_util::EndsWith(command_str, kExecSuffix)) {
command_str.remove_suffix(strlen(kExecSuffix));
return strings::StrCat(command_str, ".cc");
} else {
#include "tensorflow/stream_executor/platform/port.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/stream_executor/lib/demangle.h"
#include "tensorflow/stream_executor/platform.h"
#include "tensorflow/stream_executor/platform/logging.h"
void KernelBase::set_name(port::StringPiece name) {
name_ = name.ToString();
port::StringPiece stubless_name = name;
- if (name.starts_with(kStubPrefix)) {
+ if (tensorflow::str_util::StartsWith(name, kStubPrefix)) {
stubless_name.remove_prefix(strlen(kStubPrefix));
}
demangled_name_ = port::Demangle(stubless_name.data());
// Returns a copy of the input string 'str' with the given 'suffix'
// removed. If the suffix doesn't match, returns a copy of the original string.
inline string StripSuffixString(port::StringPiece str, port::StringPiece suffix) {
- if (str.ends_with(suffix)) {
+ if (tensorflow::str_util::EndsWith(str, suffix)) {
str.remove_suffix(suffix.size());
}
return str.ToString();