Commit 2ee9fce3 by Aaron Leung

Implementing string unquoting.

parent 40050f5a
......@@ -83,8 +83,10 @@ namespace Sass {
buf << string(token) << ":";
break;
case values:
for (int i = 0; i < children.size(); ++i)
buf << " " << string(children[i].token);
for (int i = 0; i < children.size(); ++i) {
buf << " ";
children[i].token.stream_unquoted(buf);
}
break;
case rule:
buf << " ";
......
$blah: bloo blee;
$blip: "a 'red' and \"blue\" value";
/* top level comment -- should preserved */
div {
......@@ -21,6 +22,9 @@ div {
-webkit-box-sizing: $blux;
}
margin: 10px 5px;
h1 {
color: $blip;
}
}
/* last comment, top level again --
compare the indentation! */
\ No newline at end of file
......@@ -4,4 +4,40 @@ namespace Sass {
Token::Token() : begin(0), end(0) { }
Token::Token(const char* _begin, const char* _end)
: begin(_begin), end(_end) { }
void Token::stream_unquoted(std::stringstream& buf) const {
const char* p = begin;
if (*begin == '\'' || *begin == '"') {
++p;
while (p < end) {
if (*p == '\\') {
switch (*(++p)) {
case 'n': buf << '\n'; break;
case 't': buf << '\t'; break;
case 'b': buf << '\b'; break;
case 'r': buf << '\r'; break;
case 'f': buf << '\f'; break;
case 'v': buf << '\v'; break;
case 'a': buf << '\a'; break;
case '\\': buf << '\\'; break;
default: buf << *p; break;
}
}
else if (p == end - 1) {
return;
}
else {
buf << *p;
}
++p;
}
return;
}
else {
while (p < end) {
buf << *(p++);
}
return;
}
}
}
\ No newline at end of file
#include <string>
#include <sstream>
#include "prelexer.hpp"
namespace Sass {
......@@ -11,7 +12,14 @@ namespace Sass {
Token();
Token(const char* _begin, const char* _end);
inline bool is_null() { return begin == 0 || end == 0; }
inline operator string() const { return string(begin, end - begin); }
inline bool is_null() const {
return begin == 0 || end == 0 || begin >= end;
}
inline operator string() const {
return string(begin, end - begin);
}
void stream_unquoted(std::stringstream& buf) const;
};
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment