forked from sass/libsass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Newlines: Parse \f and normalize in comments
Also moves the `normalize*` functions and `rtrim` to a separate object file, so they can be unit tested quickly and easily. I'm not entirely sure if the new `normalize_newlines` method is called in the right places. Refs sass#2843
- Loading branch information
Showing
17 changed files
with
227 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ SOURCES = \ | |
bind.cpp \ | ||
file.cpp \ | ||
util.cpp \ | ||
util_string.cpp \ | ||
json.cpp \ | ||
units.cpp \ | ||
values.cpp \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
#include "parser.hpp" | ||
#include "fn_utils.hpp" | ||
#include "util_string.hpp" | ||
|
||
namespace Sass { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "util_string.hpp" | ||
|
||
#include <cstring> | ||
|
||
namespace Sass { | ||
namespace Util { | ||
|
||
std::string rtrim(const std::string &str) { | ||
std::string trimmed = str; | ||
size_t pos_ws = trimmed.find_last_not_of(" \t\n\v\f\r"); | ||
if (pos_ws != std::string::npos) { | ||
trimmed.erase(pos_ws + 1); | ||
} else { | ||
trimmed.clear(); | ||
} | ||
return trimmed; | ||
} | ||
|
||
std::string normalize_newlines(const std::string& str) { | ||
std::string result; | ||
result.reserve(str.size()); | ||
const char *cur = str.data(); | ||
std::size_t len = str.length(); | ||
while (len > 0) { | ||
const char *newline = static_cast<const char *>(std::memchr(cur, '\r', len)); | ||
const char *next; | ||
if (newline != nullptr) { | ||
next = newline + (*(newline + 1) == '\n' ? 2 : 1); | ||
} else { | ||
newline = static_cast<const char *>(std::memchr(cur, '\f', len)); | ||
if (newline == nullptr) break; | ||
next = newline + 1; | ||
} | ||
result.append(cur, newline - cur).append(1, '\n'); | ||
len -= (next - cur); | ||
cur = next; | ||
} | ||
result.append(cur, len); | ||
return result; | ||
} | ||
|
||
std::string normalize_underscores(const std::string& str) { | ||
std::string normalized = str; | ||
for(size_t i = 0, L = normalized.length(); i < L; ++i) { | ||
if(normalized[i] == '_') { | ||
normalized[i] = '-'; | ||
} | ||
} | ||
return normalized; | ||
} | ||
|
||
std::string normalize_decimals(const std::string& str) { | ||
std::string prefix = "0"; | ||
std::string normalized = str; | ||
|
||
return normalized[0] == '.' ? normalized.insert(0, prefix) : normalized; | ||
} | ||
|
||
} // namespace Sass | ||
} // namespace Util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef SASS_UTIL_STRING_H | ||
#define SASS_UTIL_STRING_H | ||
|
||
#include <string> | ||
|
||
namespace Sass { | ||
namespace Util { | ||
|
||
std::string rtrim(const std::string& str); | ||
|
||
std::string normalize_newlines(const std::string& str); | ||
std::string normalize_underscores(const std::string& str); | ||
std::string normalize_decimals(const std::string& str); | ||
|
||
} // namespace Sass | ||
} // namespace Util | ||
#endif // SASS_UTIL_STRING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.