MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / StringReplace

Function StringReplace

tensorflow/core/platform/str_util.cc:131–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131string StringReplace(StringPiece s, StringPiece oldsub, StringPiece newsub,
132 bool replace_all) {
133 // TODO(jlebar): We could avoid having to shift data around in the string if
134 // we had a StringPiece::find() overload that searched for a StringPiece.
135 string res(s);
136 size_t pos = 0;
137 while ((pos = res.find(oldsub.data(), pos, oldsub.size())) != string::npos) {
138 res.replace(pos, oldsub.size(), newsub.data(), newsub.size());
139 pos += newsub.size();
140 if (oldsub.empty()) {
141 pos++; // Match at the beginning of the text and after every byte
142 }
143 if (!replace_all) {
144 break;
145 }
146 }
147 return res;
148}
149
150bool StartsWith(StringPiece text, StringPiece prefix) {
151 return absl::StartsWith(text, prefix);

Callers 9

TESTFunction · 0.70
SparsifyGatherInternalFunction · 0.50
GetPythonOpsFunction · 0.50
FlipMinMaxMethod · 0.50
SanitizedDeviceNameMethod · 0.50
ComputeMethod · 0.50
GenerateOpFunction · 0.50

Calls 5

replaceMethod · 0.80
findMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by 1

TESTFunction · 0.56