Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions output_compressed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@
namespace Sass {
using namespace std;

Output_Compressed::Output_Compressed(Context* ctx) : buffer(""), rendered_imports(""), ctx(ctx) { }
Output_Compressed::Output_Compressed(Context* ctx) : buffer(""), rendered_imports(""), ctx(ctx), seen_utf8(false) { }
Output_Compressed::~Output_Compressed() { }

inline void Output_Compressed::fallback_impl(AST_Node* n)
{
Inspect i(ctx);
n->perform(&i);
buffer += i.get_buffer();
const string& text = i.get_buffer();
for(const char& chr : text) {
// abort clause
if (seen_utf8) break;
// skip all normal ascii chars
if (Util::isAscii(chr)) continue;
// singleton
seen_utf8 = true;
}
buffer += text;
}

void Output_Compressed::operator()(Import* imp)
Expand Down Expand Up @@ -205,7 +214,16 @@ namespace Sass {
else {
Inspect i(ctx);
c->perform(&i);
buffer += i.get_buffer();
const string& text = i.get_buffer();
for(const char& chr : text) {
// abort clause
if (seen_utf8) break;
// skip all normal ascii chars
if (Util::isAscii(chr)) continue;
// singleton
seen_utf8 = true;
}
buffer += text;
}
}

Expand Down Expand Up @@ -364,6 +382,14 @@ namespace Sass {
void Output_Compressed::append_singleline_part_to_buffer(const string& text)
{
buffer += text;
for(const char& chr : text) {
// abort clause
if (seen_utf8) break;
// skip all normal ascii chars
if (Util::isAscii(chr)) continue;
// singleton
seen_utf8 = true;
}
if (ctx && !ctx->_skip_source_map_update)
ctx->source_map.update_column(text);
}
Expand Down
6 changes: 5 additions & 1 deletion output_compressed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Sass {
string buffer;
string rendered_imports;
Context* ctx;
bool seen_utf8;

void fallback_impl(AST_Node* n);

Expand All @@ -25,7 +26,10 @@ namespace Sass {
Output_Compressed(Context* ctx = 0);
virtual ~Output_Compressed();

string get_buffer() { return rendered_imports + buffer; }
string get_buffer() {
return (seen_utf8 ? "@charset \"UTF-8\";\n" : "")
+ rendered_imports + buffer;
}

// statements
virtual void operator()(Block*);
Expand Down
21 changes: 19 additions & 2 deletions output_nested.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ namespace Sass {
using namespace std;

Output_Nested::Output_Nested(bool source_comments, Context* ctx)
: buffer(""), rendered_imports(""), indentation(0), source_comments(source_comments), ctx(ctx)
: buffer(""), rendered_imports(""), indentation(0), source_comments(source_comments), ctx(ctx), seen_utf8(false)
{ }
Output_Nested::~Output_Nested() { }

inline void Output_Nested::fallback_impl(AST_Node* n)
{
Inspect i(ctx);
n->perform(&i);
buffer += i.get_buffer();
const string& text = i.get_buffer();
for(const char& chr : text) {
// abort clause
if (seen_utf8) break;
// skip all normal ascii chars
if (Util::isAscii(chr)) continue;
// singleton
seen_utf8 = true;
}
buffer += text;
}

void Output_Nested::operator()(Import* imp)
Expand Down Expand Up @@ -338,6 +347,14 @@ namespace Sass {
void Output_Nested::append_to_buffer(const string& text)
{
buffer += text;
for(const char& chr : text) {
// abort clause
if (seen_utf8) break;
// skip all normal ascii chars
if (Util::isAscii(chr)) continue;
// singleton
seen_utf8 = true;
}
if (ctx && !ctx->_skip_source_map_update)
ctx->source_map.update_column(text);
}
Expand Down
10 changes: 6 additions & 4 deletions output_nested.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Sass {
size_t indentation;
bool source_comments;
Context* ctx;
bool seen_utf8;
void indent();

void fallback_impl(AST_Node* n);
Expand All @@ -33,10 +34,11 @@ namespace Sass {
virtual ~Output_Nested();

string get_buffer() {
if (!rendered_imports.empty() && !buffer.empty()) {
rendered_imports += "\n";
}
return rendered_imports + buffer;
if (!rendered_imports.empty() && !buffer.empty()) {
rendered_imports += "\n";
}
return (seen_utf8 ? "@charset \"UTF-8\";\n" : "")
+ rendered_imports + buffer;
}

// statements
Expand Down