sassc 2.1.0.pre3 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +24 -0
- data/Rakefile +2 -4
- data/ext/extconf.rb +13 -5
- data/ext/libsass/VERSION +1 -1
- data/ext/libsass/include/sass/base.h +2 -1
- data/ext/libsass/include/sass/context.h +4 -0
- data/ext/libsass/src/MurmurHash2.hpp +91 -0
- data/ext/libsass/src/ast.cpp +158 -168
- data/ext/libsass/src/ast.hpp +389 -230
- data/ext/libsass/src/ast_def_macros.hpp +18 -10
- data/ext/libsass/src/ast_fwd_decl.cpp +4 -3
- data/ext/libsass/src/ast_fwd_decl.hpp +98 -165
- data/ext/libsass/src/ast_helpers.hpp +292 -0
- data/ext/libsass/src/ast_sel_cmp.cpp +219 -732
- data/ext/libsass/src/ast_sel_super.cpp +539 -0
- data/ext/libsass/src/ast_sel_unify.cpp +207 -212
- data/ext/libsass/src/ast_sel_weave.cpp +616 -0
- data/ext/libsass/src/ast_selectors.cpp +594 -1026
- data/ext/libsass/src/ast_selectors.hpp +339 -385
- data/ext/libsass/src/ast_supports.cpp +36 -52
- data/ext/libsass/src/ast_supports.hpp +29 -29
- data/ext/libsass/src/ast_values.cpp +271 -84
- data/ext/libsass/src/ast_values.hpp +116 -107
- data/ext/libsass/src/backtrace.cpp +9 -9
- data/ext/libsass/src/backtrace.hpp +5 -5
- data/ext/libsass/src/base64vlq.cpp +2 -2
- data/ext/libsass/src/base64vlq.hpp +1 -1
- data/ext/libsass/src/bind.cpp +18 -18
- data/ext/libsass/src/bind.hpp +1 -1
- data/ext/libsass/src/c2ast.cpp +3 -3
- data/ext/libsass/src/c2ast.hpp +1 -1
- data/ext/libsass/src/cencode.c +4 -6
- data/ext/libsass/src/check_nesting.cpp +40 -41
- data/ext/libsass/src/check_nesting.hpp +6 -2
- data/ext/libsass/src/color_maps.cpp +14 -13
- data/ext/libsass/src/color_maps.hpp +1 -9
- data/ext/libsass/src/constants.cpp +5 -0
- data/ext/libsass/src/constants.hpp +6 -0
- data/ext/libsass/src/context.cpp +92 -119
- data/ext/libsass/src/context.hpp +41 -53
- data/ext/libsass/src/cssize.cpp +66 -149
- data/ext/libsass/src/cssize.hpp +17 -23
- data/ext/libsass/src/dart_helpers.hpp +199 -0
- data/ext/libsass/src/debugger.hpp +451 -295
- data/ext/libsass/src/emitter.cpp +15 -16
- data/ext/libsass/src/emitter.hpp +10 -12
- data/ext/libsass/src/environment.cpp +27 -27
- data/ext/libsass/src/environment.hpp +29 -24
- data/ext/libsass/src/error_handling.cpp +62 -41
- data/ext/libsass/src/error_handling.hpp +61 -51
- data/ext/libsass/src/eval.cpp +167 -281
- data/ext/libsass/src/eval.hpp +27 -29
- data/ext/libsass/src/eval_selectors.cpp +75 -0
- data/ext/libsass/src/expand.cpp +275 -222
- data/ext/libsass/src/expand.hpp +36 -16
- data/ext/libsass/src/extender.cpp +1188 -0
- data/ext/libsass/src/extender.hpp +399 -0
- data/ext/libsass/src/extension.cpp +43 -0
- data/ext/libsass/src/extension.hpp +89 -0
- data/ext/libsass/src/file.cpp +81 -72
- data/ext/libsass/src/file.hpp +28 -37
- data/ext/libsass/src/fn_colors.cpp +20 -18
- data/ext/libsass/src/fn_lists.cpp +30 -29
- data/ext/libsass/src/fn_maps.cpp +3 -3
- data/ext/libsass/src/fn_miscs.cpp +34 -46
- data/ext/libsass/src/fn_numbers.cpp +20 -13
- data/ext/libsass/src/fn_selectors.cpp +98 -128
- data/ext/libsass/src/fn_strings.cpp +47 -33
- data/ext/libsass/src/fn_utils.cpp +31 -29
- data/ext/libsass/src/fn_utils.hpp +17 -11
- data/ext/libsass/src/inspect.cpp +186 -148
- data/ext/libsass/src/inspect.hpp +31 -29
- data/ext/libsass/src/lexer.cpp +20 -82
- data/ext/libsass/src/lexer.hpp +5 -16
- data/ext/libsass/src/listize.cpp +23 -37
- data/ext/libsass/src/listize.hpp +8 -9
- data/ext/libsass/src/mapping.hpp +1 -0
- data/ext/libsass/src/memory.hpp +12 -0
- data/ext/libsass/src/memory/allocator.cpp +48 -0
- data/ext/libsass/src/memory/allocator.hpp +138 -0
- data/ext/libsass/src/memory/config.hpp +20 -0
- data/ext/libsass/src/memory/memory_pool.hpp +186 -0
- data/ext/libsass/src/memory/{SharedPtr.cpp → shared_ptr.cpp} +2 -2
- data/ext/libsass/src/memory/{SharedPtr.hpp → shared_ptr.hpp} +55 -9
- data/ext/libsass/src/operation.hpp +71 -61
- data/ext/libsass/src/operators.cpp +19 -18
- data/ext/libsass/src/operators.hpp +11 -11
- data/ext/libsass/src/ordered_map.hpp +112 -0
- data/ext/libsass/src/output.cpp +45 -64
- data/ext/libsass/src/output.hpp +6 -6
- data/ext/libsass/src/parser.cpp +512 -700
- data/ext/libsass/src/parser.hpp +89 -97
- data/ext/libsass/src/parser_selectors.cpp +189 -0
- data/ext/libsass/src/permutate.hpp +164 -0
- data/ext/libsass/src/plugins.cpp +7 -7
- data/ext/libsass/src/plugins.hpp +8 -8
- data/ext/libsass/src/position.cpp +7 -26
- data/ext/libsass/src/position.hpp +44 -21
- data/ext/libsass/src/prelexer.cpp +6 -6
- data/ext/libsass/src/remove_placeholders.cpp +55 -56
- data/ext/libsass/src/remove_placeholders.hpp +21 -18
- data/ext/libsass/src/sass.cpp +16 -15
- data/ext/libsass/src/sass.hpp +10 -5
- data/ext/libsass/src/sass2scss.cpp +4 -4
- data/ext/libsass/src/sass_context.cpp +91 -122
- data/ext/libsass/src/sass_context.hpp +2 -2
- data/ext/libsass/src/sass_functions.cpp +1 -1
- data/ext/libsass/src/sass_values.cpp +8 -11
- data/ext/libsass/src/settings.hpp +19 -0
- data/ext/libsass/src/source.cpp +69 -0
- data/ext/libsass/src/source.hpp +95 -0
- data/ext/libsass/src/source_data.hpp +32 -0
- data/ext/libsass/src/source_map.cpp +22 -18
- data/ext/libsass/src/source_map.hpp +12 -9
- data/ext/libsass/src/stylesheet.cpp +22 -0
- data/ext/libsass/src/stylesheet.hpp +57 -0
- data/ext/libsass/src/to_value.cpp +2 -2
- data/ext/libsass/src/to_value.hpp +1 -1
- data/ext/libsass/src/units.cpp +24 -22
- data/ext/libsass/src/units.hpp +8 -8
- data/ext/libsass/src/utf8_string.cpp +9 -10
- data/ext/libsass/src/utf8_string.hpp +7 -6
- data/ext/libsass/src/util.cpp +48 -50
- data/ext/libsass/src/util.hpp +20 -21
- data/ext/libsass/src/util_string.cpp +111 -61
- data/ext/libsass/src/util_string.hpp +62 -8
- data/ext/libsass/src/values.cpp +12 -12
- data/lib/sassc/engine.rb +5 -3
- data/lib/sassc/functions_handler.rb +11 -13
- data/lib/sassc/native.rb +9 -7
- data/lib/sassc/script.rb +4 -6
- data/lib/sassc/version.rb +1 -1
- data/test/functions_test.rb +38 -1
- data/test/native_test.rb +4 -4
- metadata +31 -18
- data/ext/libsass/src/extend.cpp +0 -2132
- data/ext/libsass/src/extend.hpp +0 -86
- data/ext/libsass/src/node.cpp +0 -322
- data/ext/libsass/src/node.hpp +0 -118
- data/ext/libsass/src/paths.hpp +0 -71
- data/ext/libsass/src/sass_util.cpp +0 -152
- data/ext/libsass/src/sass_util.hpp +0 -256
- data/ext/libsass/src/subset_map.cpp +0 -58
- data/ext/libsass/src/subset_map.hpp +0 -76
- data/lib/sassc/native/lib_c.rb +0 -21
@@ -0,0 +1,22 @@
|
|
1
|
+
// sass.hpp must go before all system headers to get the
|
2
|
+
// __EXTENSIONS__ fix on Solaris.
|
3
|
+
#include "sass.hpp"
|
4
|
+
|
5
|
+
#include "stylesheet.hpp"
|
6
|
+
|
7
|
+
namespace Sass {
|
8
|
+
|
9
|
+
// Constructor
|
10
|
+
Sass::StyleSheet::StyleSheet(const Resource& res, Block_Obj root) :
|
11
|
+
Resource(res),
|
12
|
+
root(root)
|
13
|
+
{
|
14
|
+
}
|
15
|
+
|
16
|
+
StyleSheet::StyleSheet(const StyleSheet& sheet) :
|
17
|
+
Resource(sheet),
|
18
|
+
root(sheet.root)
|
19
|
+
{
|
20
|
+
}
|
21
|
+
|
22
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#ifndef SASS_STYLESHEET_H
|
2
|
+
#define SASS_STYLESHEET_H
|
3
|
+
|
4
|
+
// sass.hpp must go before all system headers to get the
|
5
|
+
// __EXTENSIONS__ fix on Solaris.
|
6
|
+
#include "sass.hpp"
|
7
|
+
|
8
|
+
#include "ast_fwd_decl.hpp"
|
9
|
+
#include "extender.hpp"
|
10
|
+
#include "file.hpp"
|
11
|
+
|
12
|
+
namespace Sass {
|
13
|
+
|
14
|
+
// parsed stylesheet from loaded resource
|
15
|
+
// this should be a `Module` for sass 4.0
|
16
|
+
class StyleSheet : public Resource {
|
17
|
+
public:
|
18
|
+
|
19
|
+
// The canonical URL for this module's source file. This may be `null`
|
20
|
+
// if the module was loaded from a string without a URL provided.
|
21
|
+
// Uri get url;
|
22
|
+
|
23
|
+
// Modules that this module uses.
|
24
|
+
// List<Module> get upstream;
|
25
|
+
|
26
|
+
// The module's variables.
|
27
|
+
// Map<String, Value> get variables;
|
28
|
+
|
29
|
+
// The module's functions. Implementations must ensure
|
30
|
+
// that each [Callable] is stored under its own name.
|
31
|
+
// Map<String, Callable> get functions;
|
32
|
+
|
33
|
+
// The module's mixins. Implementations must ensure that
|
34
|
+
// each [Callable] is stored under its own name.
|
35
|
+
// Map<String, Callable> get mixins;
|
36
|
+
|
37
|
+
// The extensions defined in this module, which is also able to update
|
38
|
+
// [css]'s style rules in-place based on downstream extensions.
|
39
|
+
// Extender extender;
|
40
|
+
|
41
|
+
// The module's CSS tree.
|
42
|
+
Block_Obj root;
|
43
|
+
|
44
|
+
public:
|
45
|
+
|
46
|
+
// default argument constructor
|
47
|
+
StyleSheet(const Resource& res, Block_Obj root);
|
48
|
+
|
49
|
+
// Copy constructor
|
50
|
+
StyleSheet(const StyleSheet& res);
|
51
|
+
|
52
|
+
};
|
53
|
+
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
#endif
|
@@ -95,8 +95,8 @@ namespace Sass {
|
|
95
95
|
return arg->value()->perform(this);
|
96
96
|
}
|
97
97
|
|
98
|
-
//
|
99
|
-
Value* To_Value::operator()(
|
98
|
+
// SelectorList is converted to a string
|
99
|
+
Value* To_Value::operator()(SelectorList* s)
|
100
100
|
{
|
101
101
|
return SASS_MEMORY_NEW(String_Quoted,
|
102
102
|
s->pstate(),
|
data/ext/libsass/src/units.cpp
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#include "sass.hpp"
|
2
|
+
#include <map>
|
2
3
|
#include <stdexcept>
|
4
|
+
#include <algorithm>
|
3
5
|
#include "units.hpp"
|
4
6
|
#include "error_handling.hpp"
|
5
7
|
|
@@ -63,7 +65,7 @@ namespace Sass {
|
|
63
65
|
}
|
64
66
|
};
|
65
67
|
|
66
|
-
|
68
|
+
sass::string get_unit_class(UnitType unit)
|
67
69
|
{
|
68
70
|
switch (unit & 0xFF00)
|
69
71
|
{
|
@@ -89,7 +91,7 @@ namespace Sass {
|
|
89
91
|
}
|
90
92
|
};
|
91
93
|
|
92
|
-
UnitType string_to_unit(const
|
94
|
+
UnitType string_to_unit(const sass::string& s)
|
93
95
|
{
|
94
96
|
// size units
|
95
97
|
if (s == "px") return UnitType::PX;
|
@@ -147,7 +149,7 @@ namespace Sass {
|
|
147
149
|
}
|
148
150
|
}
|
149
151
|
|
150
|
-
|
152
|
+
sass::string unit_to_class(const sass::string& s)
|
151
153
|
{
|
152
154
|
if (s == "px") return "LENGTH";
|
153
155
|
else if (s == "pt") return "LENGTH";
|
@@ -175,7 +177,7 @@ namespace Sass {
|
|
175
177
|
}
|
176
178
|
|
177
179
|
// throws incompatibleUnits exceptions
|
178
|
-
double conversion_factor(const
|
180
|
+
double conversion_factor(const sass::string& s1, const sass::string& s2)
|
179
181
|
{
|
180
182
|
// assert for same units
|
181
183
|
if (s1 == s2) return 1;
|
@@ -217,7 +219,7 @@ namespace Sass {
|
|
217
219
|
return 0;
|
218
220
|
}
|
219
221
|
|
220
|
-
double convert_units(const
|
222
|
+
double convert_units(const sass::string& lhs, const sass::string& rhs, int& lhsexp, int& rhsexp)
|
221
223
|
{
|
222
224
|
double f = 0;
|
223
225
|
// do not convert same ones
|
@@ -281,7 +283,7 @@ namespace Sass {
|
|
281
283
|
double factor = 1;
|
282
284
|
|
283
285
|
for (size_t i = 0; i < iL; i++) {
|
284
|
-
|
286
|
+
sass::string &lhs = numerators[i];
|
285
287
|
UnitType ulhs = string_to_unit(lhs);
|
286
288
|
if (ulhs == UNKNOWN) continue;
|
287
289
|
UnitClass clhs = get_unit_type(ulhs);
|
@@ -294,7 +296,7 @@ namespace Sass {
|
|
294
296
|
}
|
295
297
|
|
296
298
|
for (size_t n = 0; n < nL; n++) {
|
297
|
-
|
299
|
+
sass::string &rhs = denominators[n];
|
298
300
|
UnitType urhs = string_to_unit(rhs);
|
299
301
|
if (urhs == UNKNOWN) continue;
|
300
302
|
UnitClass crhs = get_unit_type(urhs);
|
@@ -326,9 +328,9 @@ namespace Sass {
|
|
326
328
|
// it seems that a map table will fit nicely to do this
|
327
329
|
// we basically construct exponents for each unit
|
328
330
|
// has the advantage that they will be pre-sorted
|
329
|
-
std::map<
|
331
|
+
std::map<sass::string, int> exponents;
|
330
332
|
|
331
|
-
// initialize by summing up
|
333
|
+
// initialize by summing up occurrences in unit vectors
|
332
334
|
// this will already cancel out equivalent units (e.q. px/px)
|
333
335
|
for (size_t i = 0; i < iL; i ++) exponents[numerators[i]] += 1;
|
334
336
|
for (size_t n = 0; n < nL; n ++) exponents[denominators[n]] -= 1;
|
@@ -339,7 +341,7 @@ namespace Sass {
|
|
339
341
|
// convert between compatible units
|
340
342
|
for (size_t i = 0; i < iL; i++) {
|
341
343
|
for (size_t n = 0; n < nL; n++) {
|
342
|
-
|
344
|
+
sass::string &lhs = numerators[i], &rhs = denominators[n];
|
343
345
|
int &lhsexp = exponents[lhs], &rhsexp = exponents[rhs];
|
344
346
|
double f(convert_units(lhs, rhs, lhsexp, rhsexp));
|
345
347
|
if (f == 0) continue;
|
@@ -365,9 +367,9 @@ namespace Sass {
|
|
365
367
|
|
366
368
|
}
|
367
369
|
|
368
|
-
|
370
|
+
sass::string Units::unit() const
|
369
371
|
{
|
370
|
-
|
372
|
+
sass::string u;
|
371
373
|
size_t iL = numerators.size();
|
372
374
|
size_t nL = denominators.size();
|
373
375
|
for (size_t i = 0; i < iL; i += 1) {
|
@@ -394,15 +396,15 @@ namespace Sass {
|
|
394
396
|
denominators.size() == 0;
|
395
397
|
}
|
396
398
|
|
397
|
-
// this does not cover all cases (multiple
|
399
|
+
// this does not cover all cases (multiple preferred units)
|
398
400
|
double Units::convert_factor(const Units& r) const
|
399
401
|
{
|
400
402
|
|
401
|
-
|
402
|
-
|
403
|
+
sass::vector<sass::string> miss_nums(0);
|
404
|
+
sass::vector<sass::string> miss_dens(0);
|
403
405
|
// create copy since we need these for state keeping
|
404
|
-
|
405
|
-
|
406
|
+
sass::vector<sass::string> r_nums(r.numerators);
|
407
|
+
sass::vector<sass::string> r_dens(r.denominators);
|
406
408
|
|
407
409
|
auto l_num_it = numerators.begin();
|
408
410
|
auto l_num_end = numerators.end();
|
@@ -417,7 +419,7 @@ namespace Sass {
|
|
417
419
|
while (l_num_it != l_num_end)
|
418
420
|
{
|
419
421
|
// get and increment afterwards
|
420
|
-
const
|
422
|
+
const sass::string l_num = *(l_num_it ++);
|
421
423
|
|
422
424
|
auto r_num_it = r_nums.begin(), r_num_end = r_nums.end();
|
423
425
|
|
@@ -426,7 +428,7 @@ namespace Sass {
|
|
426
428
|
while (r_num_it != r_num_end)
|
427
429
|
{
|
428
430
|
// get and increment afterwards
|
429
|
-
const
|
431
|
+
const sass::string r_num = *(r_num_it);
|
430
432
|
// get possible conversion factor for units
|
431
433
|
double conversion = conversion_factor(l_num, r_num);
|
432
434
|
// skip incompatible numerator
|
@@ -454,7 +456,7 @@ namespace Sass {
|
|
454
456
|
while (l_den_it != l_den_end)
|
455
457
|
{
|
456
458
|
// get and increment afterwards
|
457
|
-
const
|
459
|
+
const sass::string l_den = *(l_den_it ++);
|
458
460
|
|
459
461
|
auto r_den_it = r_dens.begin();
|
460
462
|
auto r_den_end = r_dens.end();
|
@@ -464,8 +466,8 @@ namespace Sass {
|
|
464
466
|
while (r_den_it != r_den_end)
|
465
467
|
{
|
466
468
|
// get and increment afterwards
|
467
|
-
const
|
468
|
-
// get possible
|
469
|
+
const sass::string r_den = *(r_den_it);
|
470
|
+
// get possible conversion factor for units
|
469
471
|
double conversion = conversion_factor(l_den, r_den);
|
470
472
|
// skip incompatible denominator
|
471
473
|
if (conversion == 0) {
|
data/ext/libsass/src/units.hpp
CHANGED
@@ -55,8 +55,8 @@ namespace Sass {
|
|
55
55
|
|
56
56
|
class Units {
|
57
57
|
public:
|
58
|
-
|
59
|
-
|
58
|
+
sass::vector<sass::string> numerators;
|
59
|
+
sass::vector<sass::string> denominators;
|
60
60
|
public:
|
61
61
|
// default constructor
|
62
62
|
Units() :
|
@@ -69,7 +69,7 @@ namespace Sass {
|
|
69
69
|
denominators(ptr->denominators)
|
70
70
|
{ }
|
71
71
|
// convert to string
|
72
|
-
|
72
|
+
sass::string unit() const;
|
73
73
|
// get if units are empty
|
74
74
|
bool is_unitless() const;
|
75
75
|
// return if valid for css
|
@@ -95,15 +95,15 @@ namespace Sass {
|
|
95
95
|
extern const double resolution_conversion_factors[3][3];
|
96
96
|
|
97
97
|
UnitType get_main_unit(const UnitClass unit);
|
98
|
-
enum Sass::UnitType string_to_unit(const
|
98
|
+
enum Sass::UnitType string_to_unit(const sass::string&);
|
99
99
|
const char* unit_to_string(Sass::UnitType unit);
|
100
100
|
enum Sass::UnitClass get_unit_type(Sass::UnitType unit);
|
101
|
-
|
102
|
-
|
101
|
+
sass::string get_unit_class(Sass::UnitType unit);
|
102
|
+
sass::string unit_to_class(const sass::string&);
|
103
103
|
// throws incompatibleUnits exceptions
|
104
|
-
double conversion_factor(const
|
104
|
+
double conversion_factor(const sass::string&, const sass::string&);
|
105
105
|
double conversion_factor(UnitType, UnitType, UnitClass, UnitClass);
|
106
|
-
double convert_units(const
|
106
|
+
double convert_units(const sass::string&, const sass::string&, int&, int&);
|
107
107
|
|
108
108
|
}
|
109
109
|
|
@@ -11,7 +11,6 @@
|
|
11
11
|
|
12
12
|
namespace Sass {
|
13
13
|
namespace UTF_8 {
|
14
|
-
using std::string;
|
15
14
|
|
16
15
|
// naming conventions:
|
17
16
|
// offset: raw byte offset (0 based)
|
@@ -19,25 +18,25 @@ namespace Sass {
|
|
19
18
|
// index: code point offset (1 based or negative)
|
20
19
|
|
21
20
|
// function that will count the number of code points (utf-8 characters) from the given beginning to the given end
|
22
|
-
size_t code_point_count(const string& str, size_t start, size_t end) {
|
21
|
+
size_t code_point_count(const sass::string& str, size_t start, size_t end) {
|
23
22
|
return utf8::distance(str.begin() + start, str.begin() + end);
|
24
23
|
}
|
25
24
|
|
26
|
-
size_t code_point_count(const string& str) {
|
25
|
+
size_t code_point_count(const sass::string& str) {
|
27
26
|
return utf8::distance(str.begin(), str.end());
|
28
27
|
}
|
29
28
|
|
30
29
|
// function that will return the byte offset at a code point position
|
31
|
-
size_t offset_at_position(const string& str, size_t position) {
|
32
|
-
string::const_iterator it = str.begin();
|
30
|
+
size_t offset_at_position(const sass::string& str, size_t position) {
|
31
|
+
sass::string::const_iterator it = str.begin();
|
33
32
|
utf8::advance(it, position, str.end());
|
34
33
|
return std::distance(str.begin(), it);
|
35
34
|
}
|
36
35
|
|
37
36
|
// function that returns number of bytes in a character at offset
|
38
|
-
size_t code_point_size_at_offset(const string& str, size_t offset) {
|
37
|
+
size_t code_point_size_at_offset(const sass::string& str, size_t offset) {
|
39
38
|
// get iterator from string and forward by offset
|
40
|
-
string::const_iterator stop = str.begin() + offset;
|
39
|
+
sass::string::const_iterator stop = str.begin() + offset;
|
41
40
|
// check if beyond boundary
|
42
41
|
if (stop == str.end()) return 0;
|
43
42
|
// advance by one code point
|
@@ -78,9 +77,9 @@ namespace Sass {
|
|
78
77
|
using std::wstring;
|
79
78
|
|
80
79
|
// convert from utf16/wide string to utf8 string
|
81
|
-
string convert_from_utf16(const wstring& utf16)
|
80
|
+
sass::string convert_from_utf16(const wstring& utf16)
|
82
81
|
{
|
83
|
-
string utf8;
|
82
|
+
sass::string utf8;
|
84
83
|
// pre-allocate expected memory
|
85
84
|
utf8.reserve(sizeof(utf16)/2);
|
86
85
|
utf8::utf16to8(utf16.begin(), utf16.end(),
|
@@ -89,7 +88,7 @@ namespace Sass {
|
|
89
88
|
}
|
90
89
|
|
91
90
|
// convert from utf8 string to utf16/wide string
|
92
|
-
wstring convert_to_utf16(const string& utf8)
|
91
|
+
wstring convert_to_utf16(const sass::string& utf8)
|
93
92
|
{
|
94
93
|
wstring utf16;
|
95
94
|
// pre-allocate expected memory
|
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
#include <string>
|
5
5
|
#include "utf8.h"
|
6
|
+
#include "memory.hpp"
|
6
7
|
|
7
8
|
namespace Sass {
|
8
9
|
namespace UTF_8 {
|
@@ -13,22 +14,22 @@ namespace Sass {
|
|
13
14
|
// index: code point offset (1 based or negative)
|
14
15
|
|
15
16
|
// function that will count the number of code points (utf-8 characters) from the beginning to the given end
|
16
|
-
size_t code_point_count(const
|
17
|
-
size_t code_point_count(const
|
17
|
+
size_t code_point_count(const sass::string& str, size_t start, size_t end);
|
18
|
+
size_t code_point_count(const sass::string& str);
|
18
19
|
|
19
20
|
// function that will return the byte offset of a code point in a
|
20
|
-
size_t offset_at_position(const
|
21
|
+
size_t offset_at_position(const sass::string& str, size_t position);
|
21
22
|
|
22
23
|
// function that returns number of bytes in a character in a string
|
23
|
-
size_t code_point_size_at_offset(const
|
24
|
+
size_t code_point_size_at_offset(const sass::string& str, size_t offset);
|
24
25
|
|
25
26
|
// function that will return a normalized index, given a crazy one
|
26
27
|
size_t normalize_index(int index, size_t len);
|
27
28
|
|
28
29
|
#ifdef _WIN32
|
29
30
|
// functions to handle unicode paths on windows
|
30
|
-
|
31
|
-
std::wstring convert_to_utf16(const
|
31
|
+
sass::string convert_from_utf16(const std::wstring& wstr);
|
32
|
+
std::wstring convert_to_utf16(const sass::string& str);
|
32
33
|
#endif
|
33
34
|
|
34
35
|
}
|
data/ext/libsass/src/util.cpp
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#include "sass.h"
|
3
3
|
#include "ast.hpp"
|
4
4
|
#include "util.hpp"
|
5
|
+
#include "util_string.hpp"
|
5
6
|
#include "lexer.hpp"
|
6
7
|
#include "prelexer.hpp"
|
7
8
|
#include "constants.hpp"
|
@@ -26,8 +27,8 @@ namespace Sass {
|
|
26
27
|
#endif
|
27
28
|
|
28
29
|
// https://github.com/sass/sass/commit/4e3e1d5684cc29073a507578fc977434ff488c93
|
29
|
-
if (fmod(val, 1) - 0.5 > - std::pow(0.1, precision + 1)) return std::ceil(val);
|
30
|
-
else if (fmod(val, 1) - 0.5 > std::pow(0.1, precision)) return std::floor(val);
|
30
|
+
if (std::fmod(val, 1) - 0.5 > - std::pow(0.1, precision + 1)) return std::ceil(val);
|
31
|
+
else if (std::fmod(val, 1) - 0.5 > std::pow(0.1, precision)) return std::floor(val);
|
31
32
|
// work around some compiler issue
|
32
33
|
// cygwin has it not defined in std
|
33
34
|
using namespace std;
|
@@ -75,7 +76,7 @@ namespace Sass {
|
|
75
76
|
free(arr);
|
76
77
|
}
|
77
78
|
|
78
|
-
char **copy_strings(const
|
79
|
+
char **copy_strings(const sass::vector<sass::string>& strings, char*** array, int skip) {
|
79
80
|
int num = static_cast<int>(strings.size()) - skip;
|
80
81
|
char** arr = (char**) calloc(num + 1, sizeof(char*));
|
81
82
|
if (arr == 0)
|
@@ -96,10 +97,10 @@ namespace Sass {
|
|
96
97
|
}
|
97
98
|
|
98
99
|
// read css string (handle multiline DELIM)
|
99
|
-
|
100
|
+
sass::string read_css_string(const sass::string& str, bool css)
|
100
101
|
{
|
101
102
|
if (!css) return str;
|
102
|
-
|
103
|
+
sass::string out("");
|
103
104
|
bool esc = false;
|
104
105
|
for (auto i : str) {
|
105
106
|
if (i == '\\') {
|
@@ -124,9 +125,9 @@ namespace Sass {
|
|
124
125
|
|
125
126
|
// double escape all escape sequences
|
126
127
|
// keep unescaped quotes and backslashes
|
127
|
-
|
128
|
+
sass::string evacuate_escapes(const sass::string& str)
|
128
129
|
{
|
129
|
-
|
130
|
+
sass::string out("");
|
130
131
|
bool esc = false;
|
131
132
|
for (auto i : str) {
|
132
133
|
if (i == '\\' && !esc) {
|
@@ -158,7 +159,7 @@ namespace Sass {
|
|
158
159
|
}
|
159
160
|
|
160
161
|
// bell characters are replaced with spaces
|
161
|
-
void newline_to_space(
|
162
|
+
void newline_to_space(sass::string& str)
|
162
163
|
{
|
163
164
|
std::replace(str.begin(), str.end(), '\n', ' ');
|
164
165
|
}
|
@@ -167,14 +168,14 @@ namespace Sass {
|
|
167
168
|
// 2. Replaces newlines with spaces.
|
168
169
|
//
|
169
170
|
// This method only considers LF and CRLF as newlines.
|
170
|
-
|
171
|
+
sass::string string_to_output(const sass::string& str)
|
171
172
|
{
|
172
|
-
|
173
|
+
sass::string result;
|
173
174
|
result.reserve(str.size());
|
174
175
|
std::size_t pos = 0;
|
175
176
|
while (true) {
|
176
177
|
const std::size_t newline = str.find_first_of("\n\r", pos);
|
177
|
-
if (newline ==
|
178
|
+
if (newline == sass::string::npos) break;
|
178
179
|
result.append(str, pos, newline - pos);
|
179
180
|
if (str[newline] == '\r') {
|
180
181
|
if (str[newline + 1] == '\n') {
|
@@ -190,17 +191,17 @@ namespace Sass {
|
|
190
191
|
}
|
191
192
|
result += ' ';
|
192
193
|
const std::size_t non_space = str.find_first_not_of(" \f\n\r\t\v", pos);
|
193
|
-
if (non_space !=
|
194
|
+
if (non_space != sass::string::npos) {
|
194
195
|
pos = non_space;
|
195
196
|
}
|
196
197
|
}
|
197
|
-
result.append(str, pos,
|
198
|
+
result.append(str, pos, sass::string::npos);
|
198
199
|
return result;
|
199
200
|
}
|
200
201
|
|
201
|
-
|
202
|
+
sass::string escape_string(const sass::string& str)
|
202
203
|
{
|
203
|
-
|
204
|
+
sass::string out;
|
204
205
|
out.reserve(str.size());
|
205
206
|
for (char c : str) {
|
206
207
|
switch (c) {
|
@@ -220,9 +221,9 @@ namespace Sass {
|
|
220
221
|
return out;
|
221
222
|
}
|
222
223
|
|
223
|
-
|
224
|
+
sass::string comment_to_compact_string(const sass::string& text)
|
224
225
|
{
|
225
|
-
|
226
|
+
sass::string str = "";
|
226
227
|
size_t has = 0;
|
227
228
|
char prev = 0;
|
228
229
|
bool clean = false;
|
@@ -269,10 +270,10 @@ namespace Sass {
|
|
269
270
|
return quote_mark;
|
270
271
|
}
|
271
272
|
|
272
|
-
|
273
|
+
sass::string read_hex_escapes(const sass::string& s)
|
273
274
|
{
|
274
275
|
|
275
|
-
|
276
|
+
sass::string result;
|
276
277
|
bool skipped = false;
|
277
278
|
|
278
279
|
for (size_t i = 0, L = s.length(); i < L; ++i) {
|
@@ -289,7 +290,7 @@ namespace Sass {
|
|
289
290
|
|
290
291
|
// parse as many sequence chars as possible
|
291
292
|
// ToDo: Check if ruby aborts after possible max
|
292
|
-
while (i + len < L && s[i + len] &&
|
293
|
+
while (i + len < L && s[i + len] && Util::ascii_isxdigit(static_cast<unsigned char>(s[i + len]))) ++ len;
|
293
294
|
|
294
295
|
if (len > 1) {
|
295
296
|
|
@@ -338,7 +339,7 @@ namespace Sass {
|
|
338
339
|
|
339
340
|
}
|
340
341
|
|
341
|
-
|
342
|
+
sass::string unquote(const sass::string& s, char* qd, bool keep_utf8_sequences, bool strict)
|
342
343
|
{
|
343
344
|
|
344
345
|
// not enough room for quotes
|
@@ -354,7 +355,7 @@ namespace Sass {
|
|
354
355
|
else if (*s.begin() == '\'' && *s.rbegin() == '\'') q = '\'';
|
355
356
|
else return s;
|
356
357
|
|
357
|
-
|
358
|
+
sass::string unq;
|
358
359
|
unq.reserve(s.length()-2);
|
359
360
|
|
360
361
|
for (size_t i = 1, L = s.length() - 1; i < L; ++i) {
|
@@ -375,7 +376,7 @@ namespace Sass {
|
|
375
376
|
|
376
377
|
// parse as many sequence chars as possible
|
377
378
|
// ToDo: Check if ruby aborts after possible max
|
378
|
-
while (i + len < L && s[i + len] &&
|
379
|
+
while (i + len < L && s[i + len] && Util::ascii_isxdigit(static_cast<unsigned char>(s[i + len]))) ++ len;
|
379
380
|
|
380
381
|
// hex string?
|
381
382
|
if (keep_utf8_sequences) {
|
@@ -413,7 +414,7 @@ namespace Sass {
|
|
413
414
|
// // don't be that strict
|
414
415
|
// return s;
|
415
416
|
// // this basically always means an internal error and not users fault
|
416
|
-
// error("Unescaped delimiter in string to unquote found. [" + s + "]",
|
417
|
+
// error("Unescaped delimiter in string to unquote found. [" + s + "]", SourceSpan("[UNQUOTE]"));
|
417
418
|
// }
|
418
419
|
else {
|
419
420
|
if (strict && !skipped) {
|
@@ -430,16 +431,16 @@ namespace Sass {
|
|
430
431
|
|
431
432
|
}
|
432
433
|
|
433
|
-
|
434
|
+
sass::string quote(const sass::string& s, char q)
|
434
435
|
{
|
435
436
|
|
436
437
|
// autodetect with fallback to given quote
|
437
438
|
q = detect_best_quotemark(s.c_str(), q);
|
438
439
|
|
439
440
|
// return an empty quoted string
|
440
|
-
if (s.empty()) return
|
441
|
+
if (s.empty()) return sass::string(2, q ? q : '"');
|
441
442
|
|
442
|
-
|
443
|
+
sass::string quoted;
|
443
444
|
quoted.reserve(s.length()+2);
|
444
445
|
quoted.push_back(q);
|
445
446
|
|
@@ -528,14 +529,14 @@ namespace Sass {
|
|
528
529
|
|
529
530
|
namespace Util {
|
530
531
|
|
531
|
-
bool isPrintable(
|
532
|
+
bool isPrintable(StyleRule* r, Sass_Output_Style style) {
|
532
533
|
if (r == NULL) {
|
533
534
|
return false;
|
534
535
|
}
|
535
536
|
|
536
537
|
Block_Obj b = r->block();
|
537
538
|
|
538
|
-
|
539
|
+
SelectorList* sl = r->selector();
|
539
540
|
bool hasSelectors = sl ? sl->length() > 0 : false;
|
540
541
|
|
541
542
|
if (!hasSelectors) {
|
@@ -546,11 +547,11 @@ namespace Sass {
|
|
546
547
|
bool hasPrintableChildBlocks = false;
|
547
548
|
for (size_t i = 0, L = b->length(); i < L; ++i) {
|
548
549
|
Statement_Obj stm = b->at(i);
|
549
|
-
if (Cast<
|
550
|
+
if (Cast<AtRule>(stm)) {
|
550
551
|
return true;
|
551
552
|
} else if (Declaration* d = Cast<Declaration>(stm)) {
|
552
553
|
return isPrintable(d, style);
|
553
|
-
} else if (
|
554
|
+
} else if (ParentStatement* p = Cast<ParentStatement>(stm)) {
|
554
555
|
Block_Obj pChildBlock = p->block();
|
555
556
|
if (isPrintable(pChildBlock, style)) {
|
556
557
|
hasPrintableChildBlocks = true;
|
@@ -588,13 +589,13 @@ namespace Sass {
|
|
588
589
|
|
589
590
|
bool isPrintable(Declaration* d, Sass_Output_Style style)
|
590
591
|
{
|
591
|
-
|
592
|
+
ExpressionObj val = d->value();
|
592
593
|
if (String_Quoted_Obj sq = Cast<String_Quoted>(val)) return isPrintable(sq.ptr(), style);
|
593
594
|
if (String_Constant_Obj sc = Cast<String_Constant>(val)) return isPrintable(sc.ptr(), style);
|
594
595
|
return true;
|
595
596
|
}
|
596
597
|
|
597
|
-
bool isPrintable(
|
598
|
+
bool isPrintable(SupportsRule* f, Sass_Output_Style style) {
|
598
599
|
if (f == NULL) {
|
599
600
|
return false;
|
600
601
|
}
|
@@ -605,10 +606,10 @@ namespace Sass {
|
|
605
606
|
bool hasPrintableChildBlocks = false;
|
606
607
|
for (size_t i = 0, L = b->length(); i < L; ++i) {
|
607
608
|
Statement_Obj stm = b->at(i);
|
608
|
-
if (Cast<Declaration>(stm) || Cast<
|
609
|
+
if (Cast<Declaration>(stm) || Cast<AtRule>(stm)) {
|
609
610
|
hasDeclarations = true;
|
610
611
|
}
|
611
|
-
else if (
|
612
|
+
else if (ParentStatement* b = Cast<ParentStatement>(stm)) {
|
612
613
|
Block_Obj pChildBlock = b->block();
|
613
614
|
if (!b->is_invisible()) {
|
614
615
|
if (isPrintable(pChildBlock, style)) {
|
@@ -625,36 +626,37 @@ namespace Sass {
|
|
625
626
|
return false;
|
626
627
|
}
|
627
628
|
|
628
|
-
bool isPrintable(
|
629
|
+
bool isPrintable(CssMediaRule* m, Sass_Output_Style style)
|
629
630
|
{
|
630
631
|
if (m == nullptr) return false;
|
631
632
|
Block_Obj b = m->block();
|
632
633
|
if (b == nullptr) return false;
|
634
|
+
if (m->empty()) return false;
|
633
635
|
for (size_t i = 0, L = b->length(); i < L; ++i) {
|
634
636
|
Statement_Obj stm = b->at(i);
|
635
|
-
if (Cast<
|
637
|
+
if (Cast<AtRule>(stm)) return true;
|
636
638
|
else if (Cast<Declaration>(stm)) return true;
|
637
639
|
else if (Comment* c = Cast<Comment>(stm)) {
|
638
640
|
if (isPrintable(c, style)) {
|
639
641
|
return true;
|
640
642
|
}
|
641
643
|
}
|
642
|
-
else if (
|
644
|
+
else if (StyleRule* r = Cast<StyleRule>(stm)) {
|
643
645
|
if (isPrintable(r, style)) {
|
644
646
|
return true;
|
645
647
|
}
|
646
648
|
}
|
647
|
-
else if (
|
649
|
+
else if (SupportsRule* f = Cast<SupportsRule>(stm)) {
|
648
650
|
if (isPrintable(f, style)) {
|
649
651
|
return true;
|
650
652
|
}
|
651
653
|
}
|
652
|
-
else if (
|
654
|
+
else if (CssMediaRule* mb = Cast<CssMediaRule>(stm)) {
|
653
655
|
if (isPrintable(mb, style)) {
|
654
656
|
return true;
|
655
657
|
}
|
656
658
|
}
|
657
|
-
else if (
|
659
|
+
else if (ParentStatement* b = Cast<ParentStatement>(stm)) {
|
658
660
|
if (isPrintable(b->block(), style)) {
|
659
661
|
return true;
|
660
662
|
}
|
@@ -684,7 +686,7 @@ namespace Sass {
|
|
684
686
|
|
685
687
|
for (size_t i = 0, L = b->length(); i < L; ++i) {
|
686
688
|
Statement_Obj stm = b->at(i);
|
687
|
-
if (Cast<Declaration>(stm) || Cast<
|
689
|
+
if (Cast<Declaration>(stm) || Cast<AtRule>(stm)) {
|
688
690
|
return true;
|
689
691
|
}
|
690
692
|
else if (Comment* c = Cast<Comment>(stm)) {
|
@@ -692,22 +694,22 @@ namespace Sass {
|
|
692
694
|
return true;
|
693
695
|
}
|
694
696
|
}
|
695
|
-
else if (
|
697
|
+
else if (StyleRule* r = Cast<StyleRule>(stm)) {
|
696
698
|
if (isPrintable(r, style)) {
|
697
699
|
return true;
|
698
700
|
}
|
699
701
|
}
|
700
|
-
else if (
|
702
|
+
else if (SupportsRule* f = Cast<SupportsRule>(stm)) {
|
701
703
|
if (isPrintable(f, style)) {
|
702
704
|
return true;
|
703
705
|
}
|
704
706
|
}
|
705
|
-
else if (
|
707
|
+
else if (CssMediaRule * m = Cast<CssMediaRule>(stm)) {
|
706
708
|
if (isPrintable(m, style)) {
|
707
709
|
return true;
|
708
710
|
}
|
709
711
|
}
|
710
|
-
else if (
|
712
|
+
else if (ParentStatement* b = Cast<ParentStatement>(stm)) {
|
711
713
|
if (isPrintable(b->block(), style)) {
|
712
714
|
return true;
|
713
715
|
}
|
@@ -717,9 +719,5 @@ namespace Sass {
|
|
717
719
|
return false;
|
718
720
|
}
|
719
721
|
|
720
|
-
bool isAscii(const char chr) {
|
721
|
-
return unsigned(chr) < 128;
|
722
|
-
}
|
723
|
-
|
724
722
|
}
|
725
723
|
}
|