]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspstring.h
Fixes by misspell-fixer
[user/henk/code/inspircd.git] / include / inspstring.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
6  *   Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
10  *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
11  *   Copyright (C) 2007, 2010 Craig Edwards <brain@inspircd.org>
12  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13  *
14  * This file is part of InspIRCd.  InspIRCd is free software: you can
15  * redistribute it and/or modify it under the terms of the GNU General Public
16  * License as published by the Free Software Foundation, version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but WITHOUT
19  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21  * details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26
27
28 #pragma once
29
30 // This (config) is needed as inspstring doesn't pull in the central header
31 #include "config.h"
32 #include <cstring>
33
34 /** Sets ret to the formatted string. last is the last parameter before ..., and format is the format in printf-style */
35 #define VAFORMAT(ret, last, format) \
36         do { \
37         va_list _vaList; \
38         va_start(_vaList, last); \
39         ret.assign(InspIRCd::Format(_vaList, format)); \
40         va_end(_vaList); \
41         } while (false);
42
43 /** Compose a hex string from raw data.
44  * @param raw The raw data to compose hex from (can be NULL if rawsize is 0)
45  * @param rawsize The size of the raw data buffer
46  * @return The hex string
47  */
48 CoreExport std::string BinToHex(const void* raw, size_t rawsize);
49
50 /** Base64 encode */
51 CoreExport std::string BinToBase64(const std::string& data, const char* table = NULL, char pad = 0);
52 /** Base64 decode */
53 CoreExport std::string Base64ToBin(const std::string& data, const char* table = NULL);
54
55 /** Compose a hex string from the data in a std::string.
56  * @param data The data to compose hex from
57  * @return The hex string.
58  */
59 inline std::string BinToHex(const std::string& data)
60 {
61         return BinToHex(data.data(), data.size());
62 }