1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a method to return query parameters as a URL encoded string, and to optionally include these in getSubPath

This commit is contained in:
James Hurst 2019-04-15 12:24:16 +01:00 committed by ed
parent f4eec3d80a
commit 60f58be769
2 changed files with 27 additions and 6 deletions

View file

@ -325,8 +325,8 @@ void URL::addParameter (const String& name, const String& value)
String URL::toString (bool includeGetParameters) const
{
if (includeGetParameters && parameterNames.size() > 0)
return url + "?" + URLHelpers::getMangledParameters (*this);
if (includeGetParameters)
return url + getQueryString();
return url;
}
@ -347,12 +347,24 @@ String URL::getDomain() const
return getDomainInternal (false);
}
String URL::getSubPath() const
String URL::getSubPath (bool includeGetParameters) const
{
auto startOfPath = URLHelpers::findStartOfPath (url);
auto subPath = startOfPath <= 0 ? String()
: url.substring (startOfPath);
return startOfPath <= 0 ? String()
: url.substring (startOfPath);
if (includeGetParameters)
subPath += getQueryString();
return subPath;
}
String URL::getQueryString() const
{
if (parameterNames.size() > 0)
return "?" + URLHelpers::getMangledParameters (*this);
return {};
}
String URL::getScheme() const

View file

@ -90,8 +90,17 @@ public:
/** Returns the path part of the URL.
E.g. for "http://www.xyz.com/foo/bar?x=1", this will return "foo/bar".
If includeGetParameters is true and any parameters have been set with the
withParameter() method, then the string will have these appended on the
end and url-encoded.
*/
String getSubPath() const;
String getSubPath (bool includeGetParamters = false) const;
/** If any parameters are set, returns these URL encoded, including the "?"
* prefix.
*/
String getQueryString() const;
/** Returns the scheme of the URL.
E.g. for "http://www.xyz.com/foobar", this will return "http". (It won't