Skip to content

Commit c8e674c

Browse files
committed
string case conversion functions
1 parent 78ef170 commit c8e674c

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

context.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ namespace Sass {
365365
register_function(ctx, str_insert_sig, str_insert, env);
366366
register_function(ctx, str_index_sig, str_index, env);
367367
register_function(ctx, str_slice_sig, str_slice, env);
368+
register_function(ctx, to_upper_case_sig, to_upper_case, env);
369+
register_function(ctx, to_lower_case_sig, to_lower_case, env);
368370
// Number Functions
369371
register_function(ctx, percentage_sig, percentage, env);
370372
register_function(ctx, round_sig, round, env);

functions.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,32 @@ namespace Sass {
800800

801801
}
802802

803+
Signature to_upper_case_sig = "to-upper-case($string)";
804+
BUILT_IN(to_upper_case)
805+
{
806+
String_Constant* s = ARG("$string", String_Constant);
807+
string str = s->value();
808+
809+
for (size_t i = 0, L = str.length(); i < L; ++i) {
810+
str[i] = std::toupper(str[i]);
811+
}
812+
813+
return new (ctx.mem) String_Constant(path, position, str);
814+
}
815+
816+
Signature to_lower_case_sig = "to-lower-case($string)";
817+
BUILT_IN(to_lower_case)
818+
{
819+
String_Constant* s = ARG("$string", String_Constant);
820+
string str = s->value();
821+
822+
for (size_t i = 0, L = str.length(); i < L; ++i) {
823+
str[i] = std::tolower(str[i]);
824+
}
825+
826+
return new (ctx.mem) String_Constant(path, position, str);
827+
}
828+
803829
///////////////////
804830
// NUMBER FUNCTIONS
805831
///////////////////

functions.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ namespace Sass {
6868
extern Signature str_insert_sig;
6969
extern Signature str_index_sig;
7070
extern Signature str_slice_sig;
71+
extern Signature to_upper_case_sig;
72+
extern Signature to_lower_case_sig;
7173
extern Signature percentage_sig;
7274
extern Signature round_sig;
7375
extern Signature ceil_sig;
@@ -123,6 +125,8 @@ namespace Sass {
123125
BUILT_IN(str_insert);
124126
BUILT_IN(str_index);
125127
BUILT_IN(str_slice);
128+
BUILT_IN(to_upper_case);
129+
BUILT_IN(to_lower_case);
126130
BUILT_IN(percentage);
127131
BUILT_IN(round);
128132
BUILT_IN(ceil);

0 commit comments

Comments
 (0)