1 | #ifndef SASS_UTIL_STRING_H |
2 | #define SASS_UTIL_STRING_H |
3 | |
4 | #include "sass.hpp" |
5 | #include <string> |
6 | |
7 | namespace Sass { |
8 | namespace Util { |
9 | |
10 | // ########################################################################## |
11 | // Special case insensitive string matcher. We can optimize |
12 | // the more general compare case quite a bit by requiring |
13 | // consumers to obey some rules (lowercase and no space). |
14 | // - `literal` must only contain lower case ascii characters |
15 | // there is one edge case where this could give false positives |
16 | // test could contain a (non-ascii) char exactly 32 below literal |
17 | // ########################################################################## |
18 | bool equalsLiteral(const char* lit, const sass::string& test); |
19 | |
20 | // ########################################################################### |
21 | // Returns [name] without a vendor prefix. |
22 | // If [name] has no vendor prefix, it's returned as-is. |
23 | // ########################################################################### |
24 | sass::string unvendor(const sass::string& name); |
25 | |
26 | sass::string rtrim(sass::string str); |
27 | sass::string normalize_newlines(const sass::string& str); |
28 | sass::string normalize_underscores(const sass::string& str); |
29 | sass::string normalize_decimals(const sass::string& str); |
30 | char opening_bracket_for(char closing_bracket); |
31 | char closing_bracket_for(char opening_bracket); |
32 | |
33 | // Locale-independent ASCII character routines. |
34 | |
35 | inline bool ascii_isalpha(unsigned char c) { |
36 | return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); |
37 | } |
38 | |
39 | inline bool ascii_isdigit(unsigned char c) { |
40 | return (c >= '0' && c <= '9'); |
41 | } |
42 | |
43 | inline bool ascii_isalnum(unsigned char c) { |
44 | return ascii_isalpha(c) || ascii_isdigit(c); |
45 | } |
46 | |
47 | inline bool ascii_isascii(unsigned char c) { return c < 128; } |
48 | |
49 | inline bool ascii_isxdigit(unsigned char c) { |
50 | return ascii_isdigit(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); |
51 | } |
52 | |
53 | inline bool ascii_isspace(unsigned char c) { |
54 | return c == ' ' || c == '\t' || c == '\v' || c == '\f' || c == '\r' || c == '\n'; |
55 | } |
56 | |
57 | inline char ascii_tolower(unsigned char c) { |
58 | if (c >= 'A' && c <= 'Z') return c + 32; |
59 | return c; |
60 | } |
61 | |
62 | void ascii_str_tolower(sass::string* s); |
63 | |
64 | inline char ascii_toupper(unsigned char c) { |
65 | if (c >= 'a' && c <= 'z') return c - 32; |
66 | return c; |
67 | } |
68 | |
69 | void ascii_str_toupper(sass::string* s); |
70 | |
71 | } // namespace Sass |
72 | } // namespace Util |
73 | #endif // SASS_UTIL_STRING_H |
74 | |