Browse Source

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

tags/2021-05-28
James Hurst ed 6 years ago
parent
commit
60f58be769
2 changed files with 27 additions and 6 deletions
  1. +17
    -5
      modules/juce_core/network/juce_URL.cpp
  2. +10
    -1
      modules/juce_core/network/juce_URL.h

+ 17
- 5
modules/juce_core/network/juce_URL.cpp View File

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


+ 10
- 1
modules/juce_core/network/juce_URL.h View File

@@ -90,8 +90,17 @@ public:
/** Returns the path part of the URL. /** Returns the path part of the URL.
E.g. for "http://www.xyz.com/foo/bar?x=1", this will return "foo/bar". 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 (bool includeGetParamters = false) const;
/** If any parameters are set, returns these URL encoded, including the "?"
* prefix.
*/ */
String getSubPath() const;
String getQueryString() const;
/** Returns the scheme of the URL. /** Returns the scheme of the URL.
E.g. for "http://www.xyz.com/foobar", this will return "http". (It won't E.g. for "http://www.xyz.com/foobar", this will return "http". (It won't


Loading…
Cancel
Save