在 SASS 中测试 unicode 字符
Test for unicode character in SASS
如何在 SASS mixin 中测试字符是否为 unicode?
我有一个 mixin,我想接受 (1) 一个 unicode 字符,或 (2) 一个描述符字符串作为参数。如果参数是 unicode 字符,那么我只想显示它。如果参数是描述符字符串,我会查找与之匹配的 unicode 字符。
例如:
@include glyph('\f002');
@include glyph('search');
mixin 类似于:
@mixin glyph($glyph) {
@if type-of($glyph) == unicode {
content: '$glyph';
} @ else {
content: get_glyph_for($glyph);
}
}
type-of($glyph)
returnsstring
,因为没有"unicode"类型。
我没有在 SASS 中找到正则表达式功能,也没有找到分离单个 Unicode 字符的方法。
有什么方法可以 运行 一个带有 SASS 的正则表达式,或者将字符分开?
您可以使用 str-slice 来检测第一个字符是否为“\”。为了将 unicode 字符转换为字符串,首先你必须在 "inspect".
中 运行 它
str-slice(inspect(\f002),0,1) => "\"
http://sass-lang.com/documentation/Sass/Script/Functions.html#str_slice-instance_method
如何在 SASS mixin 中测试字符是否为 unicode?
我有一个 mixin,我想接受 (1) 一个 unicode 字符,或 (2) 一个描述符字符串作为参数。如果参数是 unicode 字符,那么我只想显示它。如果参数是描述符字符串,我会查找与之匹配的 unicode 字符。
例如:
@include glyph('\f002');
@include glyph('search');
mixin 类似于:
@mixin glyph($glyph) {
@if type-of($glyph) == unicode {
content: '$glyph';
} @ else {
content: get_glyph_for($glyph);
}
}
type-of($glyph)
returnsstring
,因为没有"unicode"类型。
我没有在 SASS 中找到正则表达式功能,也没有找到分离单个 Unicode 字符的方法。
有什么方法可以 运行 一个带有 SASS 的正则表达式,或者将字符分开?
您可以使用 str-slice 来检测第一个字符是否为“\”。为了将 unicode 字符转换为字符串,首先你必须在 "inspect".
中 运行 它str-slice(inspect(\f002),0,1) => "\"
http://sass-lang.com/documentation/Sass/Script/Functions.html#str_slice-instance_method