ZLMediaKit/src/Common/Parser.cpp

38 lines
1.0 KiB
C++
Raw Normal View History

2020-04-04 20:30:09 +08:00
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
2019-06-28 16:48:02 +08:00
#include "Parser.h"
namespace mediakit{
string FindField(const char* buf, const char* start, const char *end ,int bufSize) {
if(bufSize <=0 ){
bufSize = strlen(buf);
}
const char *msg_start = buf, *msg_end = buf + bufSize;
int len = 0;
if (start != NULL) {
len = strlen(start);
msg_start = strstr(buf, start);
}
if (msg_start == NULL) {
return "";
}
msg_start += len;
if (end != NULL) {
msg_end = strstr(msg_start, end);
if (msg_end == NULL) {
return "";
}
}
return string(msg_start, msg_end);
}
}//namespace mediakit