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

Function EncodeStringFragment

tensorflow/core/lib/strings/ordered_code.cc:163–188  ·  view source on GitHub ↗

Helper routine to encode "s" and append to "*dest", escaping special characters.

Source from the content-addressed store, hash-verified

161// Helper routine to encode "s" and append to "*dest", escaping special
162// characters.
163inline static void EncodeStringFragment(string* dest, StringPiece s) {
164 const char* p = s.data();
165 const char* limit = p + s.size();
166 const char* copy_start = p;
167 while (true) {
168 p = SkipToNextSpecialByte(p, limit);
169 if (p >= limit) break; // No more special characters that need escaping
170 char c = *(p++);
171 DCHECK(IsSpecialByte(c));
172 if (c == kEscape1) {
173 AppendBytes(dest, copy_start, p - copy_start - 1);
174 dest->push_back(kEscape1);
175 dest->push_back(kNullCharacter);
176 copy_start = p;
177 } else {
178 assert(c == kEscape2);
179 AppendBytes(dest, copy_start, p - copy_start - 1);
180 dest->push_back(kEscape2);
181 dest->push_back(kFFCharacter);
182 copy_start = p;
183 }
184 }
185 if (p > copy_start) {
186 AppendBytes(dest, copy_start, p - copy_start);
187 }
188}
189
190void OrderedCode::WriteString(string* dest, StringPiece s) {
191 EncodeStringFragment(dest, s);

Callers 1

WriteStringMethod · 0.85

Calls 6

SkipToNextSpecialByteFunction · 0.85
IsSpecialByteFunction · 0.85
AppendBytesFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected