X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fconvto.h;h=9bad62b93d0894782aaa02a649c020a9e234173c;hb=413a08a4d3d3381dbcc215eb81fe4713cb646602;hp=3332580edd491c23963f3d8286fc4f2f4bed0833;hpb=0f7cfd46ef2d277f5f82e34a2852c75212d75261;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/convto.h b/include/convto.h index 3332580ed..9bad62b93 100644 --- a/include/convto.h +++ b/include/convto.h @@ -1,8 +1,9 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2014 Attila Molnar - * Copyright (C) 2006 Craig Edwards + * Copyright (C) 2020 Matt Schatz + * Copyright (C) 2017-2019 Sadie Powell + * Copyright (C) 2016 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -99,3 +100,19 @@ template inline TOut ConvToNum(const std::string& in) return 0; return ret; } + +template<> inline char ConvToNum(const std::string& in) +{ + // We specialise ConvToNum for char to avoid istringstream treating + // the input as a character literal. + int16_t num = ConvToNum(in); + return num >= INT8_MIN && num <= INT8_MAX ? num : 0; +} + +template<> inline unsigned char ConvToNum(const std::string& in) +{ + // We specialise ConvToNum for unsigned char to avoid istringstream + // treating the input as a character literal. + uint16_t num = ConvToNum(in); + return num <= UINT8_MAX ? num : 0; +}