Add support CSS color text for class nana::color

This commit is contained in:
cnjinhao
2015-02-06 01:45:17 +08:00
parent fd5ff571a7
commit 81a50fd84f
6 changed files with 267 additions and 19 deletions

View File

@@ -12,7 +12,8 @@
*/
#include <nana/deploy.hpp>
#include <cstdlib>
#include <exception>
#if defined(NANA_WINDOWS)
#include <windows.h>
#elif defined(NANA_LINUX)
@@ -49,6 +50,88 @@ namespace nana
#endif
}
int stoi(const std::string& str, std::size_t * pos, int base)
{
#if defined(NANA_MINGW)
auto sptr = str.c_str();
char *end;
errno = 0;
auto result = std::strtol(sptr, &end, base);
if (sptr == end)
throw std::invalid_argument("invalid stoi argument");
if (errno == ERANGE)
throw std::out_of_range("stoi argument out of range");
if (pos)
*pos = (std::size_t)(end - sptr);
return ((int)result);
#else
return std::stoi(str, pos, base);
#endif
}
int stoi(const std::wstring& str, std::size_t* pos, int base)
{
#if defined(NANA_MINGW)
auto sptr = str.data();
wchar_t *end;
errno = 0;
auto result = std::wcstol(sptr, &end, base);
if (sptr == end)
throw std::invalid_argument("invalid stoi argument");
if (errno == ERANGE)
throw std::out_of_range("stoi argument out of range");
if (pos)
*pos = (std::size_t)(end - sptr);
return ((int)result);
#else
return std::stoi(str, pos, base);
#endif
}
double stod(const std::string& str, std::size_t * pos)
{
#ifdef NANA_MINGW
auto *ptr = str.data();
errno = 0;
char *end;
auto result = std::strtod(ptr, &end);
if (ptr == end)
throw std::invalid_argument("invalid stod argument");
if (errno == ERANGE)
throw std::out_of_range("stod argument out of range");
if (pos)
*pos = (std::size_t)(end - ptr);
return result;
#else
return std::stod(str, pos);
#endif
}
double stod(const std::wstring& str, std::size_t* pos)
{
#ifdef NANA_MINGW
auto *ptr = str.data();
errno = 0;
wchar_t *end;
auto result = std::wcstod(ptr, &end);
if (ptr == end)
throw std::invalid_argument("invalid stod argument");
if (errno == ERANGE)
throw std::out_of_range("stod argument out of range");
if (pos)
*pos = (std::size_t)(end - ptr);
return result;
#else
return std::stod(str, pos);
#endif
}
bool is_incomplete(const nana::string& str, unsigned pos)
{
#ifndef NANA_UNICODE