MCPcopy Create free account
hub / github.com/caozhiyi/CppNet / _FindStrInMem

Method _FindStrInMem

base/LoopBuffer.cpp:260–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260const char* CLoopBuffer::_FindStrInMem(const char* buffer, const char* ch, int buffer_len, int ch_len) const {
261 if (!buffer) {
262 return nullptr;
263 }
264
265 const char* buff = buffer;
266 const char* find = nullptr;
267 int finded = 0;
268 while(true) {
269 find = (char*)memchr(buff, *ch, buffer_len - finded);
270 if (!find) {
271 break;
272 }
273 if (memcmp(find, ch, ch_len) == 0) {
274 return find;
275 }
276 finded += find - buff + 1;
277 if (buffer_len - finded < ch_len) {
278 break;
279 }
280 buff = ++find;
281 }
282 return nullptr;
283}
284
285int CLoopBuffer::_Read(char* res, int len, bool clear) {
286 std::unique_lock<std::mutex> lock(_mutex);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected