本文整理汇总了C++中CStrRef::find方法的典型用法代码示例。如果您正苦于以下问题:C++ CStrRef::find方法的具体用法?C++ CStrRef::find怎么用?C++ CStrRef::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStrRef
的用法示例。
在下文中一共展示了CStrRef::find方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: splitHeader
bool Transport::splitHeader(CStrRef header, String &name, const char *&value) {
int pos = header.find(':');
if (pos != String::npos) {
name = header.substr(0, pos);
value = header.data() + pos;
do {
value++;
} while (*value == ' ');
return true;
}
// header("HTTP/1.0 404 Not Found");
// header("HTTP/1.0 404");
if (strncasecmp(header.data(), "http/", 5) == 0) {
int pos1 = header.find(' ');
if (pos1 != String::npos) {
int pos2 = header.find(' ', pos1 + 1);
if (pos2 == String::npos) pos2 = header.size();
if (pos2 - pos1 > 1) {
setResponse(atoi(header.data() + pos1),
getResponseInfo().empty() ? "splitHeader"
: getResponseInfo().c_str()
);
return false;
}
}
}
throw InvalidArgumentException("header", header.c_str());
}
示例2: f_substr_count
Variant f_substr_count(CStrRef haystack, CStrRef needle, int offset /* = 0 */,
int length /* = 0x7FFFFFFF */) {
int lenNeedle = needle.size();
if (lenNeedle == 0) {
throw_invalid_argument("needle: (empty)");
return false;
}
if (offset < 0 || offset > haystack.size()) {
throw_invalid_argument("offset: (out of range)");
return false;
}
if (length == 0x7FFFFFFF) {
length = haystack.size() - offset;
} else if (length <= 0 || length > haystack.size() - offset) {
throw_invalid_argument("length: (out of range)");
return false;
}
int count = 0;
int posMax = offset + length - lenNeedle;
for (int pos = haystack.find(needle, offset);
pos != -1 && pos <= posMax;
pos = haystack.find(needle, pos + lenNeedle)) {
++count;
}
return count;
}
示例3: f_stripos
Variant f_stripos(CStrRef haystack, CVarRef needle, int offset /* = 0 */) {
int pos;
if (needle.isString()) {
pos = haystack.find(needle.toString(), offset, false);
} else {
pos = haystack.find(needle.toByte(), offset, false);
}
if (pos >= 0) return pos;
return false;
}
示例4: Explode
Variant StringUtil::Explode(CStrRef input, CStrRef delimiter,
int limit /* = 0x7FFFFFFF */) {
if (delimiter.empty()) {
throw_invalid_argument("delimiter: (empty)");
return false;
}
Array ret;
int pos = input.find(delimiter);
if (limit >= 0) {
if (pos < 0) {
ret.append(input);
} else {
int len = delimiter.size();
int pos0 = 0;
do {
ret.append(input.substr(pos0, pos - pos0));
pos += len;
pos0 = pos;
} while ((pos = input.find(delimiter, pos)) >= 0 && --limit > 1);
if (pos0 <= input.size()) {
ret.append(input.substr(pos0));
}
}
} else if (pos >= 0) {
vector<int> positions;
int len = delimiter.size();
int pos0 = 0;
int found = 0;
do {
positions.push_back(pos0);
positions.push_back(pos - pos0);
pos += len;
pos0 = pos;
found++;
} while ((pos = input.find(delimiter, pos)) >= 0);
if (pos0 <= input.size()) {
positions.push_back(pos0);
positions.push_back(input.size() - pos0);
found++;
}
int iMax = (found + limit) << 1;
for (int i = 0; i < iMax; i += 2) {
ret.append(input.substr(positions[i], positions[i+1]));
}
} // else we have negative limit and delimiter not found, returning empty arr
return ret;
}
示例5: f_strpos
Variant f_strpos(CStrRef haystack, CVarRef needle, int offset /* = 0 */) {
int pos;
if (needle.isString()) {
String n(needle.toString());
if (n.length() == 0) {
raise_warning("Empty delimiter");
return false;
}
pos = haystack.find(n, offset);
} else {
pos = haystack.find(needle.toByte(), offset);
}
if (pos >= 0) return pos;
return false;
}
示例6: f_putenv
bool f_putenv(CStrRef setting) {
int pos = setting.find('=');
if (pos >= 0) {
String name = setting.substr(0, pos);
String value = setting.substr(pos + 1);
g_context->setenv(name, value);
return true;
}
return false;
}
示例7: parse_host
static void parse_host(CStrRef address, String &host, int &port) {
int pos = address.find(':');
if (pos >= 0) {
host = address.substr(0, pos);
port = address.substr(pos + 1).toInt16();
} else {
host = address;
port = 0;
}
}
示例8: parse_socket
static void parse_socket(CStrRef socket, String &protocol, String &host,
int &port) {
String address;
int pos = socket.find("://");
if (pos >= 0) {
protocol = socket.substr(0, pos);
address = socket.substr(pos + 3);
} else {
protocol = "tcp";
address = socket;
}
parse_host(address, host, port);
}
示例9: parse_host
// Extract host:port pair.
// 192.168.1.1:80 -> 192.168.1.0 80
// [2a03:2880::1]:80 -> [2a03:2880::1] 80
static void parse_host(CStrRef address, String &host, int &port) {
if (address.find('[') != std::string::npos) {
auto epos = address.rfind(']');
if (epos != std::string::npos) {
auto cpos = address.rfind(':', epos);
if (cpos != std::string::npos) {
port = address.substr(cpos + 1).toInt16();
}
}
host = address.substr(0, epos + 1);
} else {
auto cpos = address.rfind(':');
if (cpos != std::string::npos) {
host = address.substr(0, cpos);
port = address.substr(cpos + 1).toInt16();
} else {
host = address;
port = 0;
}
}
}
示例10: IsPlainFilePath
bool File::IsPlainFilePath(CStrRef filename) {
return filename.find("://") == String::npos;
}