Replaced calls to deprecated tensorflow::StringPiece methods with their

tensorflow::str_util equivalents.

This will allow the deprecated methods to be removed.

PiperOrigin-RevId: 191627087
This commit is contained in:
A. Unique TensorFlower 2018-04-04 12:08:49 -07:00 committed by TensorFlower Gardener
parent bd540c8c45
commit 13e103b8f0
22 changed files with 94 additions and 70 deletions

View File

@ -23,6 +23,7 @@ limitations under the License.
#include <locale> #include <locale>
#include <unordered_map> #include <unordered_map>
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/macros.h"
@ -203,7 +204,7 @@ bool safe_strto64(StringPiece str, int64* value) {
int64 vlimit = kint64max; int64 vlimit = kint64max;
int sign = 1; int sign = 1;
if (str.Consume("-")) { if (str_util::ConsumePrefix(&str, "-")) {
sign = -1; sign = -1;
// Different limit for positive and negative integers. // Different limit for positive and negative integers.
vlimit = kint64min; vlimit = kint64min;
@ -265,7 +266,7 @@ bool safe_strto32(StringPiece str, int32* value) {
int64 vmax = kint32max; int64 vmax = kint32max;
int sign = 1; int sign = 1;
if (str.Consume("-")) { if (str_util::ConsumePrefix(&str, "-")) {
sign = -1; sign = -1;
// Different max for positive and negative integers. // Different max for positive and negative integers.
++vmax; ++vmax;

View File

@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/random/simple_philox.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/logging.h"
#include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h" #include "tensorflow/core/platform/test_benchmark.h"
@ -128,7 +129,7 @@ void TestWriteAppends(T first, U second) {
string encoded_first_only = encoded; string encoded_first_only = encoded;
OCWriteToString<U>(&encoded, second); OCWriteToString<U>(&encoded, second);
EXPECT_NE(encoded, encoded_first_only); 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> template <typename T>

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <string> #include <string>
#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/macros.h"
namespace tensorflow { namespace tensorflow {
@ -75,14 +76,14 @@ class Scanner {
// Consume the next s.size() characters of the input, if they match <s>. If // Consume the next s.size() characters of the input, if they match <s>. If
// they don't match <s>, this is a no-op. // they don't match <s>, this is a no-op.
Scanner& ZeroOrOneLiteral(StringPiece s) { Scanner& ZeroOrOneLiteral(StringPiece s) {
cur_.Consume(s); str_util::ConsumePrefix(&cur_, s);
return *this; return *this;
} }
// Consume the next s.size() characters of the input, if they match <s>. If // 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. // they don't match <s>, then GetResult will ultimately return false.
Scanner& OneLiteral(StringPiece s) { Scanner& OneLiteral(StringPiece s) {
if (!cur_.Consume(s)) { if (!str_util::ConsumePrefix(&cur_, s)) {
error_ = true; error_ = true;
} }
return *this; return *this;

View File

@ -85,6 +85,7 @@ cc_library(
":retrying_utils", ":retrying_utils",
":time_util", ":time_util",
"//tensorflow/core:framework_headers_lib", "//tensorflow/core:framework_headers_lib",
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal", "//tensorflow/core:lib_internal",
"@jsoncpp_git//:jsoncpp", "@jsoncpp_git//:jsoncpp",
], ],
@ -263,6 +264,7 @@ tf_cc_test(
deps = [ deps = [
":gcs_file_system", ":gcs_file_system",
":http_request_fake", ":http_request_fake",
"//tensorflow/core:lib",
"//tensorflow/core:test", "//tensorflow/core:test",
"//tensorflow/core:test_main", "//tensorflow/core:test_main",
], ],

View File

@ -172,7 +172,7 @@ Status ParseGcsPath(StringPiece fname, bool empty_object_ok, string* bucket,
return errors::InvalidArgument("GCS path doesn't contain a bucket name: ", return errors::InvalidArgument("GCS path doesn't contain a bucket name: ",
fname); fname);
} }
objectp.Consume("/"); str_util::ConsumePrefix(&objectp, "/");
*object = objectp.ToString(); *object = objectp.ToString();
if (!empty_object_ok && object->empty()) { if (!empty_object_ok && object->empty()) {
return errors::InvalidArgument("GCS path doesn't contain an object name: ", return errors::InvalidArgument("GCS path doesn't contain an object name: ",
@ -535,7 +535,8 @@ class GcsWritableFile : public WritableFile {
*uploaded = 0; *uploaded = 0;
} else { } else {
StringPiece range_piece(received_range); 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; std::vector<int64> range_parts;
if (!str_util::SplitAndParseAsInts(range_piece, '-', &range_parts) || if (!str_util::SplitAndParseAsInts(range_piece, '-', &range_parts) ||
range_parts.size() != 2) { range_parts.size() != 2) {
@ -1172,7 +1173,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname,
// 'object_prefix', which is part of 'dirname', should be removed from // 'object_prefix', which is part of 'dirname', should be removed from
// the beginning of 'name'. // the beginning of 'name'.
StringPiece relative_path(name); StringPiece relative_path(name);
if (!relative_path.Consume(object_prefix)) { if (!str_util::ConsumePrefix(&relative_path, object_prefix)) {
return errors::Internal(strings::StrCat( return errors::Internal(strings::StrCat(
"Unexpected response: the returned file name ", name, "Unexpected response: the returned file name ", name,
" doesn't match the prefix ", object_prefix)); " doesn't match the prefix ", object_prefix));
@ -1201,7 +1202,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname,
} }
const string& prefix_str = prefix.asString(); const string& prefix_str = prefix.asString();
StringPiece relative_path(prefix_str); StringPiece relative_path(prefix_str);
if (!relative_path.Consume(object_prefix)) { if (!str_util::ConsumePrefix(&relative_path, object_prefix)) {
return errors::Internal( return errors::Internal(
"Unexpected response: the returned folder name ", prefix_str, "Unexpected response: the returned folder name ", prefix_str,
" doesn't match the prefix ", object_prefix); " doesn't match the prefix ", object_prefix);

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/core/platform/cloud/gcs_file_system.h" #include "tensorflow/core/platform/cloud/gcs_file_system.h"
#include <fstream> #include <fstream>
#include "tensorflow/core/lib/core/status_test_util.h" #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/cloud/http_request_fake.h"
#include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test.h"
@ -584,8 +585,9 @@ TEST(GcsFileSystemTest, NewWritableFile_ResumeUploadAllAttemptsFail) {
TF_EXPECT_OK(file->Append("content2")); TF_EXPECT_OK(file->Append("content2"));
const auto& status = file->Close(); const auto& status = file->Close();
EXPECT_EQ(errors::Code::ABORTED, status.code()); EXPECT_EQ(errors::Code::ABORTED, status.code());
EXPECT_TRUE(StringPiece(status.error_message()) EXPECT_TRUE(
.contains("All 10 retry attempts failed. The last failure: " str_util::StrContains(status.error_message(),
"All 10 retry attempts failed. The last failure: "
"Unavailable: important HTTP error 503")) "Unavailable: important HTTP error 503"))
<< status; << status;
} }
@ -641,13 +643,12 @@ TEST(GcsFileSystemTest, NewWritableFile_UploadReturns410) {
const auto& status = file->Close(); const auto& status = file->Close();
EXPECT_EQ(errors::Code::UNAVAILABLE, status.code()); EXPECT_EQ(errors::Code::UNAVAILABLE, status.code());
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()) str_util::StrContains(status.error_message(),
.contains( "Upload to gs://bucket/path/writeable.txt failed, "
"Upload to gs://bucket/path/writeable.txt failed, caused by: " "caused by: Not found: important HTTP error 410"))
"Not found: important HTTP error 410"))
<< status; << status;
EXPECT_TRUE(StringPiece(status.error_message()) EXPECT_TRUE(str_util::StrContains(
.contains("when uploading gs://bucket/path/writeable.txt")) status.error_message(), "when uploading gs://bucket/path/writeable.txt"))
<< status; << status;
} }

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/core/platform/cloud/retrying_file_system.h" #include "tensorflow/core/platform/cloud/retrying_file_system.h"
#include <fstream> #include <fstream>
#include "tensorflow/core/lib/core/status_test_util.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.h"
namespace tensorflow { namespace tensorflow {
@ -245,7 +246,7 @@ TEST(RetryingFileSystemTest, NewRandomAccessFile_AllRetriesFailed) {
char scratch[10]; char scratch[10];
const auto& status = random_access_file->Read(0, 10, &result, scratch); const auto& status = random_access_file->Read(0, 10, &result, scratch);
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -399,7 +400,7 @@ TEST(RetryingFileSystemTest, NewWritableFile_AllRetriesFailed) {
// Use it and check the results. // Use it and check the results.
const auto& status = writable_file->Sync(); const auto& status = writable_file->Sync();
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -428,7 +429,7 @@ TEST(RetryingFileSystemTest, NewReadOnlyMemoryRegionFromFile_AllRetriesFailed) {
const auto& status = const auto& status =
fs.NewReadOnlyMemoryRegionFromFile("filename.txt", &result); fs.NewReadOnlyMemoryRegionFromFile("filename.txt", &result);
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -454,7 +455,7 @@ TEST(RetryingFileSystemTest, GetChildren_AllRetriesFailed) {
std::vector<string> result; std::vector<string> result;
const auto& status = fs.GetChildren("gs://path", &result); const auto& status = fs.GetChildren("gs://path", &result);
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -481,7 +482,7 @@ TEST(RetryingFileSystemTest, GetMatchingPaths_AllRetriesFailed) {
std::vector<string> result; std::vector<string> result;
const auto& status = fs.GetMatchingPaths("gs://path/dir", &result); const auto& status = fs.GetMatchingPaths("gs://path/dir", &result);
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -506,7 +507,7 @@ TEST(RetryingFileSystemTest, DeleteFile_AllRetriesFailed) {
std::vector<string> result; std::vector<string> result;
const auto& status = fs.DeleteFile("gs://path/file.txt"); const auto& status = fs.DeleteFile("gs://path/file.txt");
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -531,7 +532,7 @@ TEST(RetryingFileSystemTest, CreateDir_AllRetriesFailed) {
std::vector<string> result; std::vector<string> result;
const auto& status = fs.CreateDir("gs://path/newdir"); const auto& status = fs.CreateDir("gs://path/newdir");
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -556,7 +557,7 @@ TEST(RetryingFileSystemTest, DeleteDir_AllRetriesFailed) {
std::vector<string> result; std::vector<string> result;
const auto& status = fs.DeleteDir("gs://path/dir"); const auto& status = fs.DeleteDir("gs://path/dir");
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -582,7 +583,7 @@ TEST(RetryingFileSystemTest, GetFileSize_AllRetriesFailed) {
uint64 size; uint64 size;
const auto& status = fs.GetFileSize("gs://path/file.txt", &size); const auto& status = fs.GetFileSize("gs://path/file.txt", &size);
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -605,7 +606,7 @@ TEST(RetryingFileSystemTest, RenameFile_AllRetriesFailed) {
const auto& status = fs.RenameFile("old_name", "new_name"); const auto& status = fs.RenameFile("old_name", "new_name");
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -630,7 +631,7 @@ TEST(RetryingFileSystemTest, Stat_AllRetriesFailed) {
FileStatistics stat; FileStatistics stat;
const auto& status = fs.Stat("file_name", &stat); const auto& status = fs.Stat("file_name", &stat);
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -642,7 +643,7 @@ TEST(RetryingFileSystemTest, FileExists_AllRetriesFailed) {
const auto& status = fs.FileExists("file_name"); const auto& status = fs.FileExists("file_name");
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -677,7 +678,7 @@ TEST(RetryingFileSystemTest, IsDirectory_AllRetriesFailed) {
const auto& status = fs.IsDirectory("gs://path/dir"); const auto& status = fs.IsDirectory("gs://path/dir");
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }
@ -706,7 +707,7 @@ TEST(RetryingFileSystemTest, DeleteRecursively_AllRetriesFailed) {
const auto& status = const auto& status =
fs.DeleteRecursively("gs://path/dir", &undeleted_files, &undeleted_dirs); fs.DeleteRecursively("gs://path/dir", &undeleted_files, &undeleted_dirs);
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(status.error_message()).contains("Retriable error #10")) str_util::StrContains(status.error_message(), "Retriable error #10"))
<< status; << status;
} }

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/core/platform/cloud/retrying_utils.h" #include "tensorflow/core/platform/cloud/retrying_utils.h"
#include <fstream> #include <fstream>
#include "tensorflow/core/lib/core/status_test_util.h" #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/env.h"
#include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test.h"
@ -31,10 +32,9 @@ TEST(RetryingUtilsTest, CallWithRetries_RetryDelays) {
const auto& status = RetryingUtils::CallWithRetries(f, 500000L, sleep); const auto& status = RetryingUtils::CallWithRetries(f, 500000L, sleep);
EXPECT_EQ(errors::Code::ABORTED, status.code()); EXPECT_EQ(errors::Code::ABORTED, status.code());
EXPECT_TRUE(StringPiece(status.error_message()) EXPECT_TRUE(str_util::StrContains(
.contains("All 10 retry attempts " status.error_message(),
"failed. The last failure: " "All 10 retry attempts failed. The last failure: Unavailable: Failed."))
"Unavailable: Failed."))
<< status; << status;
EXPECT_EQ(10, requested_delays.size()); EXPECT_EQ(10, requested_delays.size());

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <vector> #include <vector>
#include "tensorflow/core/lib/core/stringpiece.h" #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/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/util/command_line_flags.h" #include "tensorflow/core/util/command_line_flags.h"
@ -28,7 +29,9 @@ bool ParseStringFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag,
const std::function<bool(string)>& hook, const std::function<bool(string)>& hook,
bool* value_parsing_ok) { bool* value_parsing_ok) {
*value_parsing_ok = true; *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()); *value_parsing_ok = hook(arg.ToString());
return true; return true;
} }
@ -40,7 +43,9 @@ bool ParseInt32Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag,
const std::function<bool(int32)>& hook, const std::function<bool(int32)>& hook,
bool* value_parsing_ok) { bool* value_parsing_ok) {
*value_parsing_ok = true; *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; char extra;
int32 parsed_int32; int32 parsed_int32;
if (sscanf(arg.data(), "%d%c", &parsed_int32, &extra) != 1) { if (sscanf(arg.data(), "%d%c", &parsed_int32, &extra) != 1) {
@ -60,7 +65,9 @@ bool ParseInt64Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag,
const std::function<bool(int64)>& hook, const std::function<bool(int64)>& hook,
bool* value_parsing_ok) { bool* value_parsing_ok) {
*value_parsing_ok = true; *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; char extra;
int64 parsed_int64; int64 parsed_int64;
if (sscanf(arg.data(), "%lld%c", &parsed_int64, &extra) != 1) { if (sscanf(arg.data(), "%lld%c", &parsed_int64, &extra) != 1) {
@ -80,7 +87,8 @@ bool ParseBoolFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag,
const std::function<bool(bool)>& hook, const std::function<bool(bool)>& hook,
bool* value_parsing_ok) { bool* value_parsing_ok) {
*value_parsing_ok = true; *value_parsing_ok = true;
if (arg.Consume("--") && arg.Consume(flag)) { if (str_util::ConsumePrefix(&arg, "--") &&
str_util::ConsumePrefix(&arg, flag)) {
if (arg.empty()) { if (arg.empty()) {
*value_parsing_ok = hook(true); *value_parsing_ok = hook(true);
return true; return true;
@ -107,7 +115,9 @@ bool ParseFloatFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag,
const std::function<bool(float)>& hook, const std::function<bool(float)>& hook,
bool* value_parsing_ok) { bool* value_parsing_ok) {
*value_parsing_ok = true; *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; char extra;
float parsed_float; float parsed_float;
if (sscanf(arg.data(), "%f%c", &parsed_float, &extra) != 1) { if (sscanf(arg.data(), "%f%c", &parsed_float, &extra) != 1) {

View File

@ -408,7 +408,7 @@ static void MergeDevNamesError(const string& name_a, const string& name_b,
DeviceNameUtils::ParsedName target_a = Name(name_a); DeviceNameUtils::ParsedName target_a = Name(name_a);
Status s = DeviceNameUtils::MergeDevNames(&target_a, Name(name_b)); Status s = DeviceNameUtils::MergeDevNames(&target_a, Name(name_b));
EXPECT_EQ(s.code(), error::INVALID_ARGUMENT); 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; << s;
} }

View File

@ -23,6 +23,7 @@ limitations under the License.
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/lib/hash/hash.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/lib/strings/strcat.h"
#include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/protobuf.h"
@ -144,7 +145,7 @@ bool EqualNodeDef(const NodeDef& actual, const NodeDef& expected, string* diff,
int first_control_input = actual.input_size(); int first_control_input = actual.input_size();
for (int i = 0; i < actual.input_size(); ++i) { 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; first_control_input = i;
break; break;
} }
@ -240,7 +241,7 @@ uint64 NodeDefHash(const NodeDef& ndef, const EqualGraphDefOptions& options) {
// Normal inputs. Order important. // Normal inputs. Order important.
int first_control_input = ndef.input_size(); int first_control_input = ndef.input_size();
for (int i = 0; i < ndef.input_size(); ++i) { 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; first_control_input = i;
break; break;
} }

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/core/util/memmapped_file_system.h" #include "tensorflow/core/util/memmapped_file_system.h"
#include "tensorflow/core/lib/core/errors.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/platform/protobuf.h"
#include "tensorflow/core/util/memmapped_file_system.pb.h" #include "tensorflow/core/util/memmapped_file_system.pb.h"
@ -242,7 +243,7 @@ Status MemmappedFileSystem::InitializeFromFile(Env* env,
} }
bool MemmappedFileSystem::IsMemmappedPackageFilename(const string& filename) { bool MemmappedFileSystem::IsMemmappedPackageFilename(const string& filename) {
return StringPiece(filename).starts_with(kMemmappedPackagePrefix); return str_util::StartsWith(filename, kMemmappedPackagePrefix);
} }
namespace { namespace {

View File

@ -29,7 +29,7 @@ namespace {
// Tests of all the error paths in log_reader.cc follow: // Tests of all the error paths in log_reader.cc follow:
static void ExpectHasSubstr(StringPiece s, StringPiece expected) { 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; << s << " does not contain " << expected;
} }

View File

@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/io/path.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/lib/strings/strcat.h"
#include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/logging.h"
@ -422,7 +423,7 @@ static void VersionTest(const VersionDef& versions, const string& error) {
// Read it back in and verify that we get the expected error // Read it back in and verify that we get the expected error
TensorSliceReader reader(path, OpenTableTensorSliceReader); TensorSliceReader reader(path, OpenTableTensorSliceReader);
EXPECT_TRUE(reader.status().code() == error::INVALID_ARGUMENT && 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) << "Expected error starting with '" << errors::InvalidArgument(error)
<< "', got '" << reader.status() << "'"; << "', got '" << reader.status() << "'";
} }

View File

@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/io/path.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/logging.h"
#include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test.h"
@ -333,8 +334,8 @@ TEST(TensorSliceWriteTest, SizeErrors) {
const std::vector<int8> data(300000000, -1); const std::vector<int8> data(300000000, -1);
Status s = writer.Add("test1", shape, slice, data.data()); Status s = writer.Add("test1", shape, slice, data.data());
EXPECT_EQ(s.code(), error::INVALID_ARGUMENT); EXPECT_EQ(s.code(), error::INVALID_ARGUMENT);
EXPECT_TRUE(StringPiece(s.error_message()) EXPECT_TRUE(str_util::StrContains(
.contains("Tensor slice is too large to serialize")); s.error_message(), "Tensor slice is too large to serialize"));
} }
// Add a large string tensor slice, which will fail. // Add a large string tensor slice, which will fail.
@ -344,8 +345,8 @@ TEST(TensorSliceWriteTest, SizeErrors) {
const std::vector<string> data(256 * 1024, std::string(8192, 'f')); const std::vector<string> data(256 * 1024, std::string(8192, 'f'));
Status s = writer.Add("test2", shape, slice, data.data()); Status s = writer.Add("test2", shape, slice, data.data());
EXPECT_EQ(s.code(), error::INVALID_ARGUMENT); EXPECT_EQ(s.code(), error::INVALID_ARGUMENT);
EXPECT_TRUE(StringPiece(s.error_message()) EXPECT_TRUE(str_util::StrContains(
.contains("Tensor slice is too large to serialize")); s.error_message(), "Tensor slice is too large to serialize"));
} }
} }

View File

@ -20,6 +20,7 @@ limitations under the License.
#include "tensorflow/cc/ops/standard_ops.h" #include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor_testutil.h" #include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.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.h"
#include "tensorflow/core/platform/test_benchmark.h" #include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session.h"
@ -191,7 +192,7 @@ TEST(BackportTensorArrayV3Test, TestBackportTensorArrayV3Subtypes) {
std::map<string, const NodeDef*> node_lookup; std::map<string, const NodeDef*> node_lookup;
MapNamesToNodes(result, &node_lookup); MapNamesToNodes(result, &node_lookup);
ASSERT_EQ(1, node_lookup.count("v3_node")); 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"));
} }
} }

View File

@ -24,6 +24,7 @@ limitations under the License.
#include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/tensor_shape.pb.h"
#include "tensorflow/core/framework/tensor_testutil.h" #include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.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.h"
#include "tensorflow/core/platform/test_benchmark.h" #include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session.h"
@ -209,10 +210,10 @@ class ConstantFoldingTest : public ::testing::Test {
for (const NodeDef& node : graph_def.node()) { for (const NodeDef& node : graph_def.node()) {
const StringPiece name(node.name()); const StringPiece name(node.name());
const int occurrence_count = folded_node_map.count(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(); 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(); EXPECT_EQ(1, occurrence_count) << "node.name()=" << node.name();
} }
} }

View File

@ -40,8 +40,8 @@ Status ExtractMinMaxRecords(const string& log_file_name,
for (const string& file_line : file_lines) { for (const string& file_line : file_lines) {
// We expect to find a line with components separated by semicolons, so to // We expect to find a line with components separated by semicolons, so to
// start make sure that the basic structure is in place/ // start make sure that the basic structure is in place/
StringPiece line(file_line); if (!str_util::StrContains(file_line,
if (!line.contains(print_suffix + ";" + requant_prefix)) { print_suffix + ";" + requant_prefix)) {
continue; continue;
} }
std::vector<string> line_parts = str_util::Split(file_line, ';'); std::vector<string> line_parts = str_util::Split(file_line, ';');
@ -53,8 +53,7 @@ Status ExtractMinMaxRecords(const string& log_file_name,
bool min_max_found = false; bool min_max_found = false;
int min_max_index; int min_max_index;
for (int i = 1; i < line_parts.size(); ++i) { for (int i = 1; i < line_parts.size(); ++i) {
StringPiece line_part(line_parts[i]); if (str_util::StartsWith(line_parts[i], requant_prefix)) {
if (line_part.starts_with(requant_prefix)) {
min_max_found = true; min_max_found = true;
min_max_index = i; min_max_index = i;
} }
@ -90,7 +89,7 @@ Status ExtractMinMaxRecords(const string& log_file_name,
continue; continue;
} }
StringPiece name_string = line_parts[min_max_index - 1]; 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; continue;
} }
string name = string name =

View File

@ -19,6 +19,7 @@ limitations under the License.
#include "tensorflow/core/graph/graph_constructor.h" #include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h" #include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/graph/subgraph.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/platform/init_main.h"
#include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session.h"
#include "tensorflow/core/util/command_line_flags.h" #include "tensorflow/core/util/command_line_flags.h"
@ -101,7 +102,7 @@ Status InsertLogging(const GraphDef& input_graph_def,
const bool op_matches = (ops.count(node.op()) > 0); const bool op_matches = (ops.count(node.op()) > 0);
bool prefix_matches = false; bool prefix_matches = false;
for (const string& prefix : prefixes) { for (const string& prefix : prefixes) {
if (StringPiece(node.name()).starts_with(prefix)) { if (str_util::StartsWith(node.name(), prefix)) {
prefix_matches = true; prefix_matches = true;
} }
} }

View File

@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/core/graph/graph_constructor.h" #include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h" #include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/graph/subgraph.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/platform/init_main.h"
#include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session.h"
#include "tensorflow/core/util/command_line_flags.h" #include "tensorflow/core/util/command_line_flags.h"
@ -88,7 +89,7 @@ void CreateConstNode(const Tensor& tensor, const string& name,
string GetMonolithicTensorKey(const string& tensor_slice_name) { string GetMonolithicTensorKey(const string& tensor_slice_name) {
std::vector<string> names = Split(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); CHECK_GE(names.size(), 2);
names.pop_back(); names.pop_back();
} }
@ -102,8 +103,8 @@ Status ObtainTensorSlice(const GraphDef& input_graph_def,
for (const auto& node : input_graph_def.node()) { for (const auto& node : input_graph_def.node()) {
std::vector<string> node_name_parts = Split(node.name(), "/"); std::vector<string> node_name_parts = Split(node.name(), "/");
if (node_name_parts.size() == 2 && if (node_name_parts.size() == 2 &&
StringPiece(node_name_parts[0]).starts_with("save") && str_util::StartsWith(node_name_parts[0], "save") &&
StringPiece(node_name_parts[1]).starts_with("Assign") && str_util::StartsWith(node_name_parts[1], "Assign") &&
node.input(0) == target_name) { node.input(0) == target_name) {
restore_node_name = node.input(1); restore_node_name = node.input(1);
break; break;

View File

@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/core/framework/tensor_testutil.h" #include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/io/path.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.h"
#include "tensorflow/core/platform/test_benchmark.h" #include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session.h"
@ -112,12 +113,11 @@ class TransformGraphTest : public ::testing::Test {
graph_transforms::MapNamesToNodes(out_graph_def, &out_node_map); graph_transforms::MapNamesToNodes(out_graph_def, &out_node_map);
for (const NodeDef& node : out_graph_def.node()) { for (const NodeDef& node : out_graph_def.node()) {
const StringPiece name(node.name());
const int occurrence_count = out_node_map.count(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(); 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(); EXPECT_EQ(1, occurrence_count) << "node.name()=" << node.name();
} }
} }
@ -139,7 +139,7 @@ class TransformGraphTest : public ::testing::Test {
Status no_such_status = Status no_such_status =
TransformGraph({}, {}, {{"test_no_such_transform", {}}}, &graph_def); TransformGraph({}, {}, {{"test_no_such_transform", {}}}, &graph_def);
EXPECT_TRUE( EXPECT_TRUE(
StringPiece(no_such_status.ToString()).contains("not recognized")); str_util::StrContains(no_such_status.ToString(), "not recognized"));
} }
void TestParseTransformParameters() { void TestParseTransformParameters() {

View File

@ -88,7 +88,7 @@ void NodeNamePartsFromInput(const string& input_name, string* prefix,
*suffix = ":" + input_parts[1]; *suffix = ":" + input_parts[1];
} }
StringPiece node_name_piece(input_parts[0]); StringPiece node_name_piece(input_parts[0]);
if (node_name_piece.Consume("^")) { if (str_util::ConsumePrefix(&node_name_piece, "^")) {
*prefix = "^"; *prefix = "^";
} else { } else {
*prefix = ""; *prefix = "";
@ -200,8 +200,7 @@ Status SortByExecutionOrder(const GraphDef& input_graph_def,
// for merge only wait for one non-control input. // for merge only wait for one non-control input.
int32 num_control_edges = 0; int32 num_control_edges = 0;
for (int i = 0; i < node_def.input_size(); ++i) { for (int i = 0; i < node_def.input_size(); ++i) {
StringPiece input_name(node_def.input(i)); if (str_util::StartsWith(node_def.input(i), "^")) {
if (input_name.starts_with("^")) {
num_control_edges++; num_control_edges++;
} }
} }
@ -504,7 +503,7 @@ Status RenameNodeInputs(const GraphDef& input_graph_def,
const string& dest_name = input_to_rename.second; const string& dest_name = input_to_rename.second;
bool is_match; bool is_match;
string match_name; string match_name;
if (StringPiece(source_name).ends_with(":*")) { if (str_util::EndsWith(source_name, ":*")) {
is_match = true; is_match = true;
string prefix; string prefix;
string unused_node_name; string unused_node_name;