result_t Url::get_href(exlib::string& retVal) { retVal.clear(); if (m_protocol.length() > 0) retVal.append(m_protocol); if (m_slashes) retVal.append("//", 2); exlib::string str; if (m_username.length() > 0) { get_auth(str); retVal.append(str); retVal.append(1, '@'); } get_host(str); retVal.append(str); get_path(str); retVal.append(str); retVal.append(m_hash); return 0; }
result_t fs_base::readTextFile(exlib::string fname, exlib::string& retVal, AsyncEvent* ac) { if (ac->isSync()) return CHECK_ERROR(CALL_E_NOSYNC); obj_ptr<SeekableStream_base> f; obj_ptr<Buffer_base> buf; result_t hr; hr = openFile(fname, "r", f, ac); if (hr < 0) return hr; hr = f->cc_readAll(buf); f->cc_close(); if (hr == CALL_RETURN_NULL) { retVal.clear(); return 0; } if (hr < 0) return hr; return buf->toString(retVal); }
void Url::parseHost(const char*& url, exlib::string& hostname, exlib::string& port) { const char* p1 = url; const char* p2 = NULL; char ch; if (*p1 == '[') { p1++; while ((ch = *p1) && (qisxdigit(ch) || ch == ':' || ch == '.')) p1++; if (ch == ']') ch = *++p1; else url++; } else { while ((ch = *p1) && (qisascii(ch) || qisdigit(ch) || ch == '.' || ch == '_' || ch == '-' || ch < 0)) p1++; } if (ch == ':') { p2 = p1 + 1; while ((ch = *p2) && qisdigit(ch)) p2++; } if (*url == '[') hostname.assign(url + 1, p1 - url - 2); else hostname.assign(url, p1 - url); if (hostname.length() > 0) { qstrlwr(&hostname[0]); punycode_base::toASCII(hostname, hostname); } if (p2) port.assign(p1 + 1, p2 - p1 - 1); else port.clear(); url = p2 ? p2 : p1; }
result_t path_base::get_delimiter(exlib::string &retVal) { retVal.clear(); retVal.append(1, PATH_DELIMITER); return 0; }
result_t path_base::get_sep(exlib::string &retVal) { retVal.clear(); retVal.append(1, PATH_SLASH); return 0; }