Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
pct.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_address/pct.h
10 //! @brief Percent-encoding and -decoding.
11 
12 #ifndef ROC_ADDRESS_PCT_H_
13 #define ROC_ADDRESS_PCT_H_
14 
15 #include "roc_core/attributes.h"
16 #include "roc_core/stddefs.h"
18 
19 namespace roc {
20 namespace address {
21 
22 //! Percent-encoding mode.
23 enum PctMode {
24  //! Percent-encode all symbols that are not unreserved.
26 
27  //! Percent-encode all symbols that are not allowed in host.
29 
30  //! Percent-encode all symbols that are not allowed in path.
32 };
33 
34 //! Percent-encode an UTF-8 string.
35 //
36 //! @b Parameters
37 //! - @p dst - destination buffer
38 //! - @p src - source string in UTF-8
39 //! - @p src_sz - source string size
40 //! - @p mode - encoding mode
41 //!
42 //! @remarks
43 //! The source string should NOT be null-terminated.
44 //! The source string size should NOT include the terminating zero byte.
46 pct_encode(core::StringBuilder& dst, const char* src, size_t src_sz, PctMode mode);
47 
48 //! Percent-decode an UTF-8 string.
49 //
50 //! @b Parameters
51 //! - @p dst - destination buffer
52 //! - @p src - source string in UTF-8
53 //! - @p src_sz - source string size
54 //!
55 //! @remarks
56 //! The source string should NOT be null-terminated.
57 //! The source string size should NOT include the terminating zero byte.
59 pct_decode(core::StringBuilder& dst, const char* src, size_t src_sz);
60 
61 } // namespace address
62 } // namespace roc
63 
64 #endif // ROC_ADDRESS_PCT_H_
Compiler attributes.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition: attributes.h:31
ROC_ATTR_NODISCARD bool pct_encode(core::StringBuilder &dst, const char *src, size_t src_sz, PctMode mode)
Percent-encode an UTF-8 string.
ROC_ATTR_NODISCARD bool pct_decode(core::StringBuilder &dst, const char *src, size_t src_sz)
Percent-decode an UTF-8 string.
PctMode
Percent-encoding mode.
Definition: pct.h:23
@ PctNonPath
Percent-encode all symbols that are not allowed in path.
Definition: pct.h:31
@ PctNonUnreserved
Percent-encode all symbols that are not unreserved.
Definition: pct.h:25
@ PctNonHost
Percent-encode all symbols that are not allowed in host.
Definition: pct.h:28
Root namespace.
Commonly used types and functions.
String builder.