const String application_path() { cf::Url url(CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle())); cf::String url_string(CFStringCreateCopy(NULL, CFURLGetString(url.c_obj()))); char path_buffer[PATH_MAX]; if (!CFURLGetFileSystemRepresentation( url.c_obj(), true, reinterpret_cast<UInt8*>(path_buffer), PATH_MAX)) { throw Exception("couldn't get application_path()"); } return String(utf8::decode(path_buffer)); }
/*! * \brief * Splits a URL into its constituent parts. * * \param url * Pointer to the URL string to parse. * * Splits a URL into its constituent parts. * * \remarks * The URL string passed to this function must be an escaped URL, attempting to parse an unescaped URL will have unknown results. */ void c_url_interface::ParseURL(const char* url) { // scheme://username:password@address:port/directory/directory/resource?field=value&field=&field=value#fragment std::string url_string(url); std::string query; std::string network_location; // forward parsing // get the scheme SplitString(url_string, m_scheme, "://", true, false); if(m_scheme.length() == 0) m_scheme.assign("http"); // get the network location SplitString(url_string, network_location, "/", true); if(!network_location.length()) { network_location = url_string; url_string.clear(); } // reverse parsing // get the fragment SplitString(url_string, m_fragment, "#", false); m_fragment = Unescape(m_fragment); // get the query SplitString(url_string, query, "?", false); // get the path ParseNetworkLocation(network_location); ParsePath(url_string.c_str()); ParseQuery(query.c_str()); }