Skip to content

Commit 5f01135

Browse files
committed
Merge pull request #956 from mgreter/bugfix/issue_942
Implement css string reading function
2 parents ecf9ff4 + 8d1f21f commit 5f01135

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

ast.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,16 +1393,16 @@ namespace Sass {
13931393
size_t hash_;
13941394
public:
13951395
String_Constant(ParserState pstate, string val)
1396-
: String(pstate), quote_mark_(0), value_(val), hash_(0)
1396+
: String(pstate), quote_mark_(0), value_(read_css_string(val)), hash_(0)
13971397
{ }
13981398
String_Constant(ParserState pstate, const char* beg)
1399-
: String(pstate), quote_mark_(0), value_(string(beg)), hash_(0)
1399+
: String(pstate), quote_mark_(0), value_(read_css_string(string(beg))), hash_(0)
14001400
{ }
14011401
String_Constant(ParserState pstate, const char* beg, const char* end)
1402-
: String(pstate), quote_mark_(0), value_(string(beg, end-beg)), hash_(0)
1402+
: String(pstate), quote_mark_(0), value_(read_css_string(string(beg, end-beg))), hash_(0)
14031403
{ }
14041404
String_Constant(ParserState pstate, const Token& tok)
1405-
: String(pstate), quote_mark_(0), value_(string(tok.begin, tok.end)), hash_(0)
1405+
: String(pstate), quote_mark_(0), value_(read_css_string(string(tok.begin, tok.end))), hash_(0)
14061406
{ }
14071407
string type() { return "string"; }
14081408
static string type_name() { return "string"; }

sass_context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ extern "C" {
320320
}
321321

322322
// generic compilation function (not exported, use file/data compile instead)
323-
static Context* sass_prepare_context (Sass_Context* c_ctx, Context::Data cpp_opt)
323+
static Context* sass_prepare_context (Sass_Context* c_ctx, Context::Data cpp_opt) throw()
324324
{
325325
try {
326326

@@ -422,7 +422,7 @@ extern "C" {
422422

423423
}
424424

425-
static Block* sass_parse_block (Sass_Context* c_ctx, Context* cpp_ctx)
425+
static Block* sass_parse_block (Sass_Context* c_ctx, Context* cpp_ctx) throw()
426426
{
427427
try {
428428

util.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ namespace Sass {
7979
return out;
8080
}
8181

82+
// read css string (handle multiline DELIM)
83+
string read_css_string(const string& str)
84+
{
85+
string out("");
86+
bool esc = false;
87+
for (auto i : str) {
88+
if (i == '\\') {
89+
esc = ! esc;
90+
} else if (esc && i == '\r') {
91+
out.resize (out.size () - 1);
92+
continue;
93+
} else if (esc && i == '\n') {
94+
out.resize (out.size () - 1);
95+
esc = false;
96+
continue;
97+
} else {
98+
esc = false;
99+
}
100+
out.push_back(i);
101+
}
102+
if (esc) out += '\\';
103+
return out;
104+
}
105+
82106
// evacuate unescaped quoted
83107
// leave everything else untouched
84108
string evacuate_quotes(const string& str)

util.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Sass {
1212
double sass_atof(const char* str);
1313
string string_escape(const string& str);
1414
string string_unescape(const string& str);
15+
string read_css_string(const string& str);
1516
string evacuate_quotes(const string& str);
1617
string evacuate_escapes(const string& str);
1718
string string_to_output(const string& str);

0 commit comments

Comments
 (0)