Skip to content

Commit

Permalink
Implement css string reading function
Browse files Browse the repository at this point in the history
Handle trailing backslash + newline token
sass#942
  • Loading branch information
mgreter committed Mar 17, 2015
1 parent dea27e5 commit 1b1fc93
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
8 changes: 4 additions & 4 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,16 +1392,16 @@ namespace Sass {
size_t hash_;
public:
String_Constant(ParserState pstate, string val)
: String(pstate), quote_mark_(0), value_(val), hash_(0)
: String(pstate), quote_mark_(0), value_(read_css_string(val)), hash_(0)
{ }
String_Constant(ParserState pstate, const char* beg)
: String(pstate), quote_mark_(0), value_(string(beg)), hash_(0)
: String(pstate), quote_mark_(0), value_(read_css_string(string(beg))), hash_(0)
{ }
String_Constant(ParserState pstate, const char* beg, const char* end)
: String(pstate), quote_mark_(0), value_(string(beg, end-beg)), hash_(0)
: String(pstate), quote_mark_(0), value_(read_css_string(string(beg, end-beg))), hash_(0)
{ }
String_Constant(ParserState pstate, const Token& tok)
: String(pstate), quote_mark_(0), value_(string(tok.begin, tok.end)), hash_(0)
: String(pstate), quote_mark_(0), value_(read_css_string(string(tok.begin, tok.end))), hash_(0)
{ }
string type() { return "string"; }
static string type_name() { return "string"; }
Expand Down
4 changes: 2 additions & 2 deletions sass_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ extern "C" {
}

// generic compilation function (not exported, use file/data compile instead)
static Context* sass_prepare_context (Sass_Context* c_ctx, Context::Data cpp_opt)
static Context* sass_prepare_context (Sass_Context* c_ctx, Context::Data cpp_opt) throw()
{
try {

Expand Down Expand Up @@ -422,7 +422,7 @@ extern "C" {

}

static Block* sass_parse_block (Sass_Context* c_ctx, Context* cpp_ctx)
static Block* sass_parse_block (Sass_Context* c_ctx, Context* cpp_ctx) throw()
{
try {

Expand Down
23 changes: 23 additions & 0 deletions util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,29 @@ namespace Sass {
return out;
}

// read css string (handle multiline DELIM)
string read_css_string(const string& str)
{
string out("");
bool esc = false;
for (auto i : str) {
if (i == '\\') {
esc = ! esc;
} else if (esc && i == '\r') {
out.resize (out.size () - 1);
continue;
} else if (esc && i == '\n') {
out.resize (out.size () - 1);
esc = false;
continue;
} else {
esc = false;
}
out.push_back(i);
}
return out;
}

// evacuate unescaped quoted
// leave everything else untouched
string evacuate_quotes(const string& str)
Expand Down
1 change: 1 addition & 0 deletions util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Sass {
double sass_atof(const char* str);
string string_escape(const string& str);
string string_unescape(const string& str);
string read_css_string(const string& str);
string evacuate_quotes(const string& str);
string evacuate_escapes(const string& str);
string string_to_output(const string& str);
Expand Down

0 comments on commit 1b1fc93

Please sign in to comment.