mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine codes.
This commit is contained in:
parent
b2ae1acaa4
commit
fabcc91a0e
5 changed files with 71 additions and 1 deletions
|
@ -357,7 +357,57 @@ vector<string> srs_string_split(string str, string flag)
|
|||
|
||||
while ((pos = s.find(flag)) != string::npos) {
|
||||
arr.push_back(s.substr(0, pos));
|
||||
s = s.substr(pos + 1);
|
||||
s = s.substr(pos + flag.length());
|
||||
}
|
||||
|
||||
if (!s.empty()) {
|
||||
arr.push_back(s);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
string srs_string_min_match(string str, vector<string> flags)
|
||||
{
|
||||
string match;
|
||||
|
||||
size_t min_pos = string::npos;
|
||||
for (vector<string>::iterator it = flags.begin(); it != flags.end(); ++it) {
|
||||
string flag = *it;
|
||||
|
||||
size_t pos = str.find(flag);
|
||||
if (pos == string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (min_pos == string::npos || pos < min_pos) {
|
||||
min_pos = pos;
|
||||
match = flag;
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
vector<string> srs_string_split(string str, vector<string> flags)
|
||||
{
|
||||
vector<string> arr;
|
||||
|
||||
size_t pos = string::npos;
|
||||
string s = str;
|
||||
|
||||
while (true) {
|
||||
string flag = srs_string_min_match(s, flags);
|
||||
if (flag.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((pos = s.find(flag)) == string::npos) {
|
||||
break;
|
||||
}
|
||||
|
||||
arr.push_back(s.substr(0, pos));
|
||||
s = s.substr(pos + flag.length());
|
||||
}
|
||||
|
||||
if (!s.empty()) {
|
||||
|
|
|
@ -90,6 +90,7 @@ extern bool srs_string_starts_with(std::string str, std::string flag0, std::stri
|
|||
extern bool srs_string_contains(std::string str, std::string flag);
|
||||
// split the string by flag to array.
|
||||
extern std::vector<std::string> srs_string_split(std::string str, std::string flag);
|
||||
extern std::vector<std::string> srs_string_split(std::string str, std::vector<std::string> flags);
|
||||
|
||||
// create dir recursively
|
||||
extern int srs_create_dir_recursively(std::string dir);
|
||||
|
|
3
trunk/src/protocol/srs_http_stack.cpp
Executable file → Normal file
3
trunk/src/protocol/srs_http_stack.cpp
Executable file → Normal file
|
@ -2989,6 +2989,9 @@ int SrsHttpUri::initialize(string _url)
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
port = 0;
|
||||
schema = host = path = query = "";
|
||||
|
||||
url = _url;
|
||||
const char* purl = url.c_str();
|
||||
|
||||
|
|
|
@ -630,6 +630,21 @@ SrsJsonAny* SrsJsonObject::ensure_property_integer(string name)
|
|||
return prop;
|
||||
}
|
||||
|
||||
SrsJsonAny* SrsJsonObject::ensure_property_number(string name)
|
||||
{
|
||||
SrsJsonAny* prop = get_property(name);
|
||||
|
||||
if (!prop) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!prop->is_number()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
||||
SrsJsonAny* SrsJsonObject::ensure_property_boolean(string name)
|
||||
{
|
||||
SrsJsonAny* prop = get_property(name);
|
||||
|
|
|
@ -157,6 +157,7 @@ public:
|
|||
virtual SrsJsonAny* get_property(std::string name);
|
||||
virtual SrsJsonAny* ensure_property_string(std::string name);
|
||||
virtual SrsJsonAny* ensure_property_integer(std::string name);
|
||||
virtual SrsJsonAny* ensure_property_number(std::string name);
|
||||
virtual SrsJsonAny* ensure_property_boolean(std::string name);
|
||||
virtual SrsJsonAny* ensure_property_object(std::string name);
|
||||
virtual SrsJsonAny* ensure_property_array(std::string name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue