Variant f_strripos(CStrRef haystack, CVarRef needle, int offset /* = 0 */) { int pos; if (needle.isString()) { pos = haystack.rfind(needle.toString(), offset, false); } else { pos = haystack.rfind(needle.toByte(), offset, false); } if (pos >= 0) return pos; return false; }
// 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; } } }