Skip to content

Commit 9ba6000

Browse files
committed
Implement css linefeed \a handling better
1 parent 31eeac0 commit 9ba6000

File tree

6 files changed

+46
-47
lines changed

6 files changed

+46
-47
lines changed

src/ast.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,12 +2040,12 @@ namespace Sass {
20402040

20412041
std::string String_Quoted::inspect() const
20422042
{
2043-
return quote(value_, '*', true);
2043+
return quote(value_, '*');
20442044
}
20452045

20462046
std::string String_Constant::inspect() const
20472047
{
2048-
return quote(value_, '*', true);
2048+
return quote(value_, '*');
20492049
}
20502050

20512051
//////////////////////////////////////////////////////////////////////////////////////////

src/inspect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ namespace Sass {
709709
void Inspect::operator()(String_Quoted* s)
710710
{
711711
if (const char q = s->quote_mark()) {
712-
append_token(quote(s->value(), q, true), s);
712+
append_token(quote(s->value(), q), s);
713713
} else {
714714
append_token(s->value(), s);
715715
}

src/prelexer.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,43 +1215,5 @@ namespace Sass {
12151215
>(src);
12161216
}
12171217

1218-
template <size_t size, prelexer mx, prelexer pad>
1219-
const char* padded_token(const char* src)
1220-
{
1221-
size_t got = 0;
1222-
const char* pos = src;
1223-
while (got < size) {
1224-
if (!mx(pos)) break;
1225-
++ pos; ++ got;
1226-
}
1227-
while (got < size) {
1228-
if (!pad(pos)) break;
1229-
++ pos; ++ got;
1230-
}
1231-
return got ? pos : 0;
1232-
}
1233-
1234-
template <size_t min, size_t max, prelexer mx>
1235-
const char* minmax_range(const char* src)
1236-
{
1237-
size_t got = 0;
1238-
const char* pos = src;
1239-
while (got < max) {
1240-
if (!mx(pos)) break;
1241-
++ pos; ++ got;
1242-
}
1243-
if (got < min) return 0;
1244-
if (got > max) return 0;
1245-
return pos;
1246-
}
1247-
1248-
template <char min, char max>
1249-
const char* char_range(const char* src)
1250-
{
1251-
if (*src < min) return 0;
1252-
if (*src > max) return 0;
1253-
return src + 1;
1254-
}
1255-
12561218
}
12571219
}

src/prelexer.hpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,42 @@ namespace Sass {
421421
}
422422

423423
template <size_t size, prelexer mx, prelexer pad>
424-
const char* padded_token(const char* src);
424+
const char* padded_token(const char* src)
425+
{
426+
size_t got = 0;
427+
const char* pos = src;
428+
while (got < size) {
429+
if (!mx(pos)) break;
430+
++ pos; ++ got;
431+
}
432+
while (got < size) {
433+
if (!pad(pos)) break;
434+
++ pos; ++ got;
435+
}
436+
return got ? pos : 0;
437+
}
425438

426439
template <size_t min, size_t max, prelexer mx>
427-
const char* minmax_range(const char* src);
440+
const char* minmax_range(const char* src)
441+
{
442+
size_t got = 0;
443+
const char* pos = src;
444+
while (got < max) {
445+
if (!mx(pos)) break;
446+
++ pos; ++ got;
447+
}
448+
if (got < min) return 0;
449+
if (got > max) return 0;
450+
return pos;
451+
}
428452

429453
template <char min, char max>
430-
const char* char_range(const char* src);
454+
const char* char_range(const char* src)
455+
{
456+
if (*src < min) return 0;
457+
if (*src > max) return 0;
458+
return src + 1;
459+
}
431460

432461
}
433462
}

src/util.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ namespace Sass {
315315

316316
}
317317

318-
std::string quote(const std::string& s, char q, bool keep_linefeed_whitespace)
318+
std::string quote(const std::string& s, char q)
319319
{
320320

321321
// autodetect with fallback to given quote
@@ -352,8 +352,16 @@ namespace Sass {
352352
quoted.push_back('a');
353353
// we hope we can remove this flag once we figure out
354354
// why ruby sass has these different output behaviors
355-
if (keep_linefeed_whitespace)
355+
// gsub(/\n(?![a-fA-F0-9\s])/, "\\a").gsub("\n", "\\a ")
356+
using namespace Prelexer;
357+
if (alternatives <
358+
Prelexer::char_range<'a', 'f'>,
359+
Prelexer::char_range<'A', 'F'>,
360+
Prelexer::char_range<'0', '9'>,
361+
space
362+
>(it) != NULL) {
356363
quoted.push_back(' ');
364+
}
357365
} else if (cp < 127) {
358366
quoted.push_back((char) cp);
359367
} else {

src/util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Sass {
2323
std::string string_to_output(const std::string& str);
2424
std::string comment_to_string(const std::string& text);
2525

26-
std::string quote(const std::string&, char q = 0, bool keep_linefeed_whitespace = false);
26+
std::string quote(const std::string&, char q = 0);
2727
std::string unquote(const std::string&, char* q = 0, bool keep_utf8_sequences = false);
2828
char detect_best_quotemark(const char* s, char qm = '"');
2929

0 commit comments

Comments
 (0)