mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-02 11:46:34 +02:00
string compat functions throw
This commit is contained in:
parent
244202674b
commit
f11a7055a1
12 changed files with 36 additions and 18 deletions
|
@ -19,7 +19,7 @@
|
|||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include "clientConnection.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
#include "common/snapException.h"
|
||||
#include "message/hello.h"
|
||||
#include "common/log.h"
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#endif
|
||||
#include "common/log.h"
|
||||
#include "common/signalHandler.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "sampleFormat.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/log.h"
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#ifdef NO_CPP11_STRING
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <climits>
|
||||
#include <stdexcept>
|
||||
#include <cerrno>
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -24,19 +28,26 @@ namespace cpt
|
|||
#endif
|
||||
}
|
||||
|
||||
static long stoul(const std::string& s)
|
||||
static long stoul(const std::string& str)
|
||||
{
|
||||
#ifdef NO_CPP11_STRING
|
||||
return atol(s.c_str());
|
||||
errno = 0;
|
||||
char *temp;
|
||||
long val = strtol(str.c_str(), &temp, 10);
|
||||
if (temp == str.c_str() || *temp != '\0')
|
||||
throw std::invalid_argument("stoi");
|
||||
if (((val == LONG_MIN) || (val == LONG_MAX)) && (errno == ERANGE))
|
||||
throw std::out_of_range("stoi");
|
||||
return val;
|
||||
#else
|
||||
return std::stoul(s);
|
||||
return std::stoul(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int stoi(const std::string& str)
|
||||
{
|
||||
#ifdef NO_CPP11_STRING
|
||||
return strtol(str.c_str(), 0, 10);
|
||||
return cpt::stoul(str);
|
||||
#else
|
||||
return std::stoi(str);
|
||||
#endif
|
||||
|
@ -45,7 +56,14 @@ namespace cpt
|
|||
static double stod(const std::string& str)
|
||||
{
|
||||
#ifdef NO_CPP11_STRING
|
||||
return strtod(str.c_str(), NULL);
|
||||
errno = 0;
|
||||
char *temp;
|
||||
double val = strtod(str.c_str(), &temp);
|
||||
if (temp == str.c_str() || *temp != '\0')
|
||||
throw std::invalid_argument("stod");
|
||||
if ((val == HUGE_VAL) && (errno == ERANGE))
|
||||
throw std::out_of_range("stod");
|
||||
return val;
|
||||
#else
|
||||
return std::stod(str.c_str());
|
||||
#endif
|
||||
|
@ -54,7 +72,7 @@ namespace cpt
|
|||
static long double strtold(const char* str, char** endptr)
|
||||
{
|
||||
#ifdef NO_CPP11_STRING
|
||||
return strtod(str, endptr);
|
||||
return cpt::stod(str);
|
||||
#else
|
||||
return std::strtold(str, endptr);
|
||||
#endif
|
||||
|
@ -63,7 +81,7 @@ namespace cpt
|
|||
static float strtof(const char* str, char** endptr)
|
||||
{
|
||||
#ifdef NO_CPP11_STRING
|
||||
return (float)strtod(str, endptr);
|
||||
return (float)cpt::stod(str);
|
||||
#else
|
||||
return std::strtof(str, endptr);
|
||||
#endif
|
2
externals/json.hpp
vendored
2
externals/json.hpp
vendored
|
@ -61,7 +61,7 @@ Class @ref nlohmann::basic_json is a good entry point for the documentation.
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
|
||||
// enable ssize_t on MinGW
|
||||
#ifdef __GNUC__
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <fstream>
|
||||
#include <cerrno>
|
||||
#include "common/snapException.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
#include "common/log.h"
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "flacEncoder.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
#include "common/snapException.h"
|
||||
#include "common/log.h"
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "oggEncoder.h"
|
||||
#include "common/snapException.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/log.h"
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "encoder/encoderFactory.h"
|
||||
#include "common/snapException.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
#include "pcmStream.h"
|
||||
#include "common/log.h"
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "encoder/encoderFactory.h"
|
||||
#include "common/log.h"
|
||||
#include "common/snapException.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "pipeStream.h"
|
||||
#include "fileStream.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/strCompat.h"
|
||||
#include "common/log.h"
|
||||
#include "common/snapException.h"
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
|
||||
#include <common/utils.h>
|
||||
#include <common/compat.h>
|
||||
#include <common/strCompat.h>
|
||||
#include <common/log.h>
|
||||
#include "streamUri.h"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue