]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspstring.h
Fix a bunch of really obvious unnecessary includes.
[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 #include <cstring>
31
32 /** Sets ret to the formatted string. last is the last parameter before ..., and format is the format in printf-style */
33 #define VAFORMAT(ret, last, format) \
34         do { \
35         va_list _vaList; \
36         va_start(_vaList, last); \
37         ret.assign(InspIRCd::Format(_vaList, format)); \
38         va_end(_vaList); \
39         } while (false);
40
41 /** Compose a hex string from raw data.
42  * @param raw The raw data to compose hex from (can be NULL if rawsize is 0)
43  * @param rawsize The size of the raw data buffer
44  * @return The hex string
45  */
46 CoreExport std::string BinToHex(const void* raw, size_t rawsize);
47
48 /** Base64 encode */
49 CoreExport std::string BinToBase64(const std::string& data, const char* table = NULL, char pad = 0);
50 /** Base64 decode */
51 CoreExport std::string Base64ToBin(const std::string& data, const char* table = NULL);
52
53 /** Compose a hex string from the data in a std::string.
54  * @param data The data to compose hex from
55  * @return The hex string.
56  */
57 inline std::string BinToHex(const std::string& data)
58 {
59         return BinToHex(data.data(), data.size());
60 }