wxExtend
Additional templates and function helpers for wxWidgets
Loading...
Searching...
No Matches
url.h
1/*
2 ​​​SPDX-License-Identifier: GPL-3.0-or-later
3 Copyright © 2015-2022 Amebis
4 Copyright © 2016 GÉANT
5*/
6
7#pragma once
8
9#include "common.h"
10
11#include <codeanalysis\warnings.h>
12#pragma warning(push)
13#pragma warning(disable: WXWIDGETS_CODE_ANALYSIS_WARNINGS)
14#include <wx/string.h>
15#include <wx/buffer.h>
16#pragma warning(pop)
17
20
30inline bool wxURLIsProtected(char chr)
31{
32 switch (chr) {
33 case ' ':
34 case '!':
35 case '*':
36 case '\'':
37 case '(':
38 case ')':
39 case ';':
40 case ':':
41 case '@':
42 case '&':
43 case '=':
44 case '+':
45 case '$':
46 case ',':
47 case '/':
48 case '?':
49 case '#':
50 case '[':
51 case ']': return true;
52 }
53
54 return chr < 0x20;
55}
56
57
66inline size_t wxURLEncodedSize(size_t len)
67{
68 return len*3;
69}
70
71
86size_t WXEXTEND_API wxURLEncode(char *dst, size_t dstLen, const char *src, size_t srcLen);
87
88
98inline wxString wxURLEncode(const char *src, size_t srcLen)
99{
100 const size_t dstLen = wxURLEncodedSize(srcLen);
101 wxCharBuffer dst(dstLen);
102 dst.shrink(wxURLEncode(dst.data(), dstLen, src, srcLen));
103
104 return dst;
105}
106
107
115inline wxString wxURLEncode(const wxString& str)
116{
117 return wxURLEncode(str.GetData(), str.Length());
118}
119
120
128inline wxString wxURLEncode(const wxMemoryBuffer& buf)
129{
130 return wxURLEncode(reinterpret_cast<const char*>(buf.GetData()), buf.GetDataLen());
131}
132
133
134// ----------------------------------------------------------------------------
135// Decoding Functions
136// ----------------------------------------------------------------------------
137
146inline size_t wxURLDecodedSize(size_t len)
147{
148 return len;
149}
150
166size_t WXEXTEND_API wxURLDecode(char *dst, size_t dstLen, const char *src, size_t srcLen = wxNO_LEN);
167
168
181inline size_t wxURLDecode(char *dst, size_t dstLen, const wxString& src)
182{
183 // don't use str.length() here as the ASCII buffer is shorter than it is for
184 // strings with embedded NULs
185 return wxURLDecode(dst, dstLen, src.ToAscii(), wxNO_LEN);
186}
187
188
198wxMemoryBuffer WXEXTEND_API wxURLDecode(const char *src, size_t srcLen = wxNO_LEN);
199
200
208inline wxMemoryBuffer wxURLDecode(const wxString& src)
209{
210 // don't use str.length() here as the ASCII buffer is shorter than it for
211 // strings with embedded NULs
212 return wxURLDecode(src.ToAscii(), wxNO_LEN);
213}
214
#define WXEXTEND_API
Public function calling convention.
Definition common.h:56
bool wxURLIsProtected(char chr)
Test if given character should be protected for URL encoding.
Definition url.h:30
size_t wxURLDecodedSize(size_t len)
Return the buffer size necessary for decoding a URL string of the given length.
Definition url.h:146
size_t WXEXTEND_API wxURLDecode(char *dst, size_t dstLen, const char *src, size_t srcLen=wxNO_LEN)
Raw decoding function which decodes the contents of the string of specified length (or zero terminate...
Definition url.cpp:50
size_t WXEXTEND_API wxURLEncode(char *dst, size_t dstLen, const char *src, size_t srcLen)
Raw URL encoding function which encodes the contents of a string of the specified length into the buf...
Definition url.cpp:10
size_t wxURLEncodedSize(size_t len)
Return the size needed for the buffer containing the encoded representation of a string of given leng...
Definition url.h:66