#include <locale>
#include <unordered_map>
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/macros.h"
int64 vlimit = kint64max;
int sign = 1;
- if (str.Consume("-")) {
+ if (str_util::ConsumePrefix(&str, "-")) {
sign = -1;
// Different limit for positive and negative integers.
vlimit = kint64min;
int64 vmax = kint32max;
int sign = 1;
- if (str.Consume("-")) {
+ if (str_util::ConsumePrefix(&str, "-")) {
sign = -1;
// Different max for positive and negative integers.
++vmax;
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/random/simple_philox.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
string encoded_first_only = encoded;
OCWriteToString<U>(&encoded, second);
EXPECT_NE(encoded, encoded_first_only);
- EXPECT_TRUE(StringPiece(encoded).starts_with(encoded_first_only));
+ EXPECT_TRUE(str_util::StartsWith(encoded, encoded_first_only));
}
template <typename T>
#include <string>
#include "tensorflow/core/lib/core/stringpiece.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/macros.h"
namespace tensorflow {
// Consume the next s.size() characters of the input, if they match <s>. If
// they don't match <s>, this is a no-op.
Scanner& ZeroOrOneLiteral(StringPiece s) {
- cur_.Consume(s);
+ str_util::ConsumePrefix(&cur_, s);
return *this;
}
// Consume the next s.size() characters of the input, if they match <s>. If
// they don't match <s>, then GetResult will ultimately return false.
Scanner& OneLiteral(StringPiece s) {
- if (!cur_.Consume(s)) {
+ if (!str_util::ConsumePrefix(&cur_, s)) {
error_ = true;
}
return *this;
":retrying_utils",
":time_util",
"//tensorflow/core:framework_headers_lib",
+ "//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"@jsoncpp_git//:jsoncpp",
],
deps = [
":gcs_file_system",
":http_request_fake",
+ "//tensorflow/core:lib",
"//tensorflow/core:test",
"//tensorflow/core:test_main",
],
return errors::InvalidArgument("GCS path doesn't contain a bucket name: ",
fname);
}
- objectp.Consume("/");
+ str_util::ConsumePrefix(&objectp, "/");
*object = objectp.ToString();
if (!empty_object_ok && object->empty()) {
return errors::InvalidArgument("GCS path doesn't contain an object name: ",
*uploaded = 0;
} else {
StringPiece range_piece(received_range);
- range_piece.Consume("bytes="); // May or may not be present.
+ str_util::ConsumePrefix(&range_piece,
+ "bytes="); // May or may not be present.
std::vector<int64> range_parts;
if (!str_util::SplitAndParseAsInts(range_piece, '-', &range_parts) ||
range_parts.size() != 2) {
// 'object_prefix', which is part of 'dirname', should be removed from
// the beginning of 'name'.
StringPiece relative_path(name);
- if (!relative_path.Consume(object_prefix)) {
+ if (!str_util::ConsumePrefix(&relative_path, object_prefix)) {
return errors::Internal(strings::StrCat(
"Unexpected response: the returned file name ", name,
" doesn't match the prefix ", object_prefix));
}
const string& prefix_str = prefix.asString();
StringPiece relative_path(prefix_str);
- if (!relative_path.Consume(object_prefix)) {
+ if (!str_util::ConsumePrefix(&relative_path, object_prefix)) {
return errors::Internal(
"Unexpected response: the returned folder name ", prefix_str,
" doesn't match the prefix ", object_prefix);
#include "tensorflow/core/platform/cloud/gcs_file_system.h"
#include <fstream>
#include "tensorflow/core/lib/core/status_test_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"
TF_EXPECT_OK(file->Append("content2"));
const auto& status = file->Close();
EXPECT_EQ(errors::Code::ABORTED, status.code());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("All 10 retry attempts failed. The last failure: "
+ EXPECT_TRUE(
+ str_util::StrContains(status.error_message(),
+ "All 10 retry attempts failed. The last failure: "
"Unavailable: important HTTP error 503"))
<< status;
}
const auto& status = file->Close();
EXPECT_EQ(errors::Code::UNAVAILABLE, status.code());
EXPECT_TRUE(
- StringPiece(status.error_message())
- .contains(
- "Upload to gs://bucket/path/writeable.txt failed, caused by: "
- "Not found: important HTTP error 410"))
+ str_util::StrContains(status.error_message(),
+ "Upload to gs://bucket/path/writeable.txt failed, "
+ "caused by: Not found: important HTTP error 410"))
<< status;
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("when uploading gs://bucket/path/writeable.txt"))
+ EXPECT_TRUE(str_util::StrContains(
+ status.error_message(), "when uploading gs://bucket/path/writeable.txt"))
<< status;
}
#include "tensorflow/core/platform/cloud/retrying_file_system.h"
#include <fstream>
#include "tensorflow/core/lib/core/status_test_util.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
namespace tensorflow {
char scratch[10];
const auto& status = random_access_file->Read(0, 10, &result, scratch);
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
// Use it and check the results.
const auto& status = writable_file->Sync();
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
const auto& status =
fs.NewReadOnlyMemoryRegionFromFile("filename.txt", &result);
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
std::vector<string> result;
const auto& status = fs.GetChildren("gs://path", &result);
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
std::vector<string> result;
const auto& status = fs.GetMatchingPaths("gs://path/dir", &result);
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
std::vector<string> result;
const auto& status = fs.DeleteFile("gs://path/file.txt");
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
std::vector<string> result;
const auto& status = fs.CreateDir("gs://path/newdir");
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
std::vector<string> result;
const auto& status = fs.DeleteDir("gs://path/dir");
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
uint64 size;
const auto& status = fs.GetFileSize("gs://path/file.txt", &size);
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
const auto& status = fs.RenameFile("old_name", "new_name");
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
FileStatistics stat;
const auto& status = fs.Stat("file_name", &stat);
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
const auto& status = fs.FileExists("file_name");
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
const auto& status = fs.IsDirectory("gs://path/dir");
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
const auto& status =
fs.DeleteRecursively("gs://path/dir", &undeleted_files, &undeleted_dirs);
EXPECT_TRUE(
- StringPiece(status.error_message()).contains("Retriable error #10"))
+ str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status;
}
#include "tensorflow/core/platform/cloud/retrying_utils.h"
#include <fstream>
#include "tensorflow/core/lib/core/status_test_util.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/test.h"
const auto& status = RetryingUtils::CallWithRetries(f, 500000L, sleep);
EXPECT_EQ(errors::Code::ABORTED, status.code());
- EXPECT_TRUE(StringPiece(status.error_message())
- .contains("All 10 retry attempts "
- "failed. The last failure: "
- "Unavailable: Failed."))
+ EXPECT_TRUE(str_util::StrContains(
+ status.error_message(),
+ "All 10 retry attempts failed. The last failure: Unavailable: Failed."))
<< status;
EXPECT_EQ(10, requested_delays.size());
#include <vector>
#include "tensorflow/core/lib/core/stringpiece.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/util/command_line_flags.h"
const std::function<bool(string)>& hook,
bool* value_parsing_ok) {
*value_parsing_ok = true;
- if (arg.Consume("--") && arg.Consume(flag) && arg.Consume("=")) {
+ if (str_util::ConsumePrefix(&arg, "--") &&
+ str_util::ConsumePrefix(&arg, flag) &&
+ str_util::ConsumePrefix(&arg, "=")) {
*value_parsing_ok = hook(arg.ToString());
return true;
}
const std::function<bool(int32)>& hook,
bool* value_parsing_ok) {
*value_parsing_ok = true;
- if (arg.Consume("--") && arg.Consume(flag) && arg.Consume("=")) {
+ if (str_util::ConsumePrefix(&arg, "--") &&
+ str_util::ConsumePrefix(&arg, flag) &&
+ str_util::ConsumePrefix(&arg, "=")) {
char extra;
int32 parsed_int32;
if (sscanf(arg.data(), "%d%c", &parsed_int32, &extra) != 1) {
const std::function<bool(int64)>& hook,
bool* value_parsing_ok) {
*value_parsing_ok = true;
- if (arg.Consume("--") && arg.Consume(flag) && arg.Consume("=")) {
+ if (str_util::ConsumePrefix(&arg, "--") &&
+ str_util::ConsumePrefix(&arg, flag) &&
+ str_util::ConsumePrefix(&arg, "=")) {
char extra;
int64 parsed_int64;
if (sscanf(arg.data(), "%lld%c", &parsed_int64, &extra) != 1) {
const std::function<bool(bool)>& hook,
bool* value_parsing_ok) {
*value_parsing_ok = true;
- if (arg.Consume("--") && arg.Consume(flag)) {
+ if (str_util::ConsumePrefix(&arg, "--") &&
+ str_util::ConsumePrefix(&arg, flag)) {
if (arg.empty()) {
*value_parsing_ok = hook(true);
return true;
const std::function<bool(float)>& hook,
bool* value_parsing_ok) {
*value_parsing_ok = true;
- if (arg.Consume("--") && arg.Consume(flag) && arg.Consume("=")) {
+ if (str_util::ConsumePrefix(&arg, "--") &&
+ str_util::ConsumePrefix(&arg, flag) &&
+ str_util::ConsumePrefix(&arg, "=")) {
char extra;
float parsed_float;
if (sscanf(arg.data(), "%f%c", &parsed_float, &extra) != 1) {
DeviceNameUtils::ParsedName target_a = Name(name_a);
Status s = DeviceNameUtils::MergeDevNames(&target_a, Name(name_b));
EXPECT_EQ(s.code(), error::INVALID_ARGUMENT);
- EXPECT_TRUE(StringPiece(s.error_message()).contains(expected_error_substr))
+ EXPECT_TRUE(str_util::StrContains(s.error_message(), expected_error_substr))
<< s;
}
#include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/lib/hash/hash.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/protobuf.h"
int first_control_input = actual.input_size();
for (int i = 0; i < actual.input_size(); ++i) {
- if (StringPiece(actual.input(i)).starts_with("^")) {
+ if (str_util::StartsWith(actual.input(i), "^")) {
first_control_input = i;
break;
}
// Normal inputs. Order important.
int first_control_input = ndef.input_size();
for (int i = 0; i < ndef.input_size(); ++i) {
- if (StringPiece(ndef.input(i)).starts_with("^")) {
+ if (str_util::StartsWith(ndef.input(i), "^")) {
first_control_input = i;
break;
}
#include "tensorflow/core/util/memmapped_file_system.h"
#include "tensorflow/core/lib/core/errors.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/util/memmapped_file_system.pb.h"
}
bool MemmappedFileSystem::IsMemmappedPackageFilename(const string& filename) {
- return StringPiece(filename).starts_with(kMemmappedPackagePrefix);
+ return str_util::StartsWith(filename, kMemmappedPackagePrefix);
}
namespace {
// Tests of all the error paths in log_reader.cc follow:
static void ExpectHasSubstr(StringPiece s, StringPiece expected) {
- EXPECT_TRUE(StringPiece(s).contains(expected))
+ EXPECT_TRUE(str_util::StrContains(s, expected))
<< s << " does not contain " << expected;
}
#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/lib/strings/strcat.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/logging.h"
// Read it back in and verify that we get the expected error
TensorSliceReader reader(path, OpenTableTensorSliceReader);
EXPECT_TRUE(reader.status().code() == error::INVALID_ARGUMENT &&
- StringPiece(reader.status().error_message()).starts_with(error))
+ str_util::StartsWith(reader.status().error_message(), error))
<< "Expected error starting with '" << errors::InvalidArgument(error)
<< "', got '" << reader.status() << "'";
}
#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/logging.h"
#include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/test.h"
const std::vector<int8> data(300000000, -1);
Status s = writer.Add("test1", shape, slice, data.data());
EXPECT_EQ(s.code(), error::INVALID_ARGUMENT);
- EXPECT_TRUE(StringPiece(s.error_message())
- .contains("Tensor slice is too large to serialize"));
+ EXPECT_TRUE(str_util::StrContains(
+ s.error_message(), "Tensor slice is too large to serialize"));
}
// Add a large string tensor slice, which will fail.
const std::vector<string> data(256 * 1024, std::string(8192, 'f'));
Status s = writer.Add("test2", shape, slice, data.data());
EXPECT_EQ(s.code(), error::INVALID_ARGUMENT);
- EXPECT_TRUE(StringPiece(s.error_message())
- .contains("Tensor slice is too large to serialize"));
+ EXPECT_TRUE(str_util::StrContains(
+ s.error_message(), "Tensor slice is too large to serialize"));
}
}
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h"
std::map<string, const NodeDef*> node_lookup;
MapNamesToNodes(result, &node_lookup);
ASSERT_EQ(1, node_lookup.count("v3_node"));
- EXPECT_TRUE(StringPiece(node_lookup.at("v3_node")->op()).ends_with("V2"));
+ EXPECT_TRUE(str_util::EndsWith(node_lookup.at("v3_node")->op(), "V2"));
}
}
#include "tensorflow/core/framework/tensor_shape.pb.h"
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h"
for (const NodeDef& node : graph_def.node()) {
const StringPiece name(node.name());
const int occurrence_count = folded_node_map.count(node.name());
- if (name.ends_with("expect_removed")) {
+ if (str_util::EndsWith(name, "expect_removed")) {
EXPECT_EQ(0, occurrence_count) << "node.name()=" << node.name();
}
- if (name.ends_with("expect_remains")) {
+ if (str_util::EndsWith(name, "expect_remains")) {
EXPECT_EQ(1, occurrence_count) << "node.name()=" << node.name();
}
}
for (const string& file_line : file_lines) {
// We expect to find a line with components separated by semicolons, so to
// start make sure that the basic structure is in place/
- StringPiece line(file_line);
- if (!line.contains(print_suffix + ";" + requant_prefix)) {
+ if (!str_util::StrContains(file_line,
+ print_suffix + ";" + requant_prefix)) {
continue;
}
std::vector<string> line_parts = str_util::Split(file_line, ';');
bool min_max_found = false;
int min_max_index;
for (int i = 1; i < line_parts.size(); ++i) {
- StringPiece line_part(line_parts[i]);
- if (line_part.starts_with(requant_prefix)) {
+ if (str_util::StartsWith(line_parts[i], requant_prefix)) {
min_max_found = true;
min_max_index = i;
}
continue;
}
StringPiece name_string = line_parts[min_max_index - 1];
- if (!name_string.ends_with(print_suffix)) {
+ if (!str_util::EndsWith(name_string, print_suffix)) {
continue;
}
string name =
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/graph/subgraph.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/util/command_line_flags.h"
const bool op_matches = (ops.count(node.op()) > 0);
bool prefix_matches = false;
for (const string& prefix : prefixes) {
- if (StringPiece(node.name()).starts_with(prefix)) {
+ if (str_util::StartsWith(node.name(), prefix)) {
prefix_matches = true;
}
}
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/graph/subgraph.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/util/command_line_flags.h"
string GetMonolithicTensorKey(const string& tensor_slice_name) {
std::vector<string> names = Split(tensor_slice_name, "/");
- if (StringPiece(names[names.size() - 1]).starts_with("part_")) {
+ if (str_util::StartsWith(names[names.size() - 1], "part_")) {
CHECK_GE(names.size(), 2);
names.pop_back();
}
for (const auto& node : input_graph_def.node()) {
std::vector<string> node_name_parts = Split(node.name(), "/");
if (node_name_parts.size() == 2 &&
- StringPiece(node_name_parts[0]).starts_with("save") &&
- StringPiece(node_name_parts[1]).starts_with("Assign") &&
+ str_util::StartsWith(node_name_parts[0], "save") &&
+ str_util::StartsWith(node_name_parts[1], "Assign") &&
node.input(0) == target_name) {
restore_node_name = node.input(1);
break;
#include "tensorflow/core/framework/tensor_testutil.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/test_benchmark.h"
#include "tensorflow/core/public/session.h"
graph_transforms::MapNamesToNodes(out_graph_def, &out_node_map);
for (const NodeDef& node : out_graph_def.node()) {
- const StringPiece name(node.name());
const int occurrence_count = out_node_map.count(node.name());
- if (name.ends_with("expect_removed")) {
+ if (str_util::EndsWith(node.name(), "expect_removed")) {
EXPECT_EQ(0, occurrence_count) << "node.name()=" << node.name();
}
- if (name.ends_with("expect_remains")) {
+ if (str_util::EndsWith(node.name(), "expect_remains")) {
EXPECT_EQ(1, occurrence_count) << "node.name()=" << node.name();
}
}
Status no_such_status =
TransformGraph({}, {}, {{"test_no_such_transform", {}}}, &graph_def);
EXPECT_TRUE(
- StringPiece(no_such_status.ToString()).contains("not recognized"));
+ str_util::StrContains(no_such_status.ToString(), "not recognized"));
}
void TestParseTransformParameters() {
*suffix = ":" + input_parts[1];
}
StringPiece node_name_piece(input_parts[0]);
- if (node_name_piece.Consume("^")) {
+ if (str_util::ConsumePrefix(&node_name_piece, "^")) {
*prefix = "^";
} else {
*prefix = "";
// for merge only wait for one non-control input.
int32 num_control_edges = 0;
for (int i = 0; i < node_def.input_size(); ++i) {
- StringPiece input_name(node_def.input(i));
- if (input_name.starts_with("^")) {
+ if (str_util::StartsWith(node_def.input(i), "^")) {
num_control_edges++;
}
}
const string& dest_name = input_to_rename.second;
bool is_match;
string match_name;
- if (StringPiece(source_name).ends_with(":*")) {
+ if (str_util::EndsWith(source_name, ":*")) {
is_match = true;
string prefix;
string unused_node_name;