Skip to content

Commit

Permalink
Add local unaware atof function
Browse files Browse the repository at this point in the history
Fixes sass#923

Conflicts:
	eval.cpp
	util.cpp
	util.hpp
  • Loading branch information
mgreter authored and npiguet committed Mar 10, 2015
1 parent 31521ef commit 7b95a0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,21 +627,21 @@ namespace Sass {
case Textual::NUMBER:
result = new (ctx.mem) Number(t->path(),
t->position(),
atof(num.c_str()),
Util::sass_atof(num.c_str()),
"",
zero);
break;
case Textual::PERCENTAGE:
result = new (ctx.mem) Number(t->path(),
t->position(),
atof(num.c_str()),
Util::sass_atof(num.c_str()),
"%",
zero);
break;
case Textual::DIMENSION:
result = new (ctx.mem) Number(t->path(),
t->position(),
atof(num.c_str()),
Util::sass_atof(num.c_str()),
Token(number(text.c_str())),
zero);
break;
Expand Down
11 changes: 11 additions & 0 deletions util.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#include "util.hpp"

namespace Sass {

namespace Util {
using std::string;

/* Locale unspecific atof function. */
double sass_atof(const char *str)
{
char* locale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C");
double val = atof(str);
setlocale(LC_NUMERIC, locale);
return val;
}

string normalize_underscores(const string& str) {
string normalized = str;
for(size_t i = 0, L = normalized.length(); i < L; ++i) {
Expand Down
2 changes: 2 additions & 0 deletions util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace Sass {
namespace Util {

double sass_atof(const char* str);

std::string normalize_underscores(const std::string& str);
std::string normalize_decimals(const std::string& str);
std::string normalize_sixtuplet(const std::string& col);
Expand Down

0 comments on commit 7b95a0b

Please sign in to comment.