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: 1. Moves the `normalize*` functions and `rtrim` to a separate object file, so that they can be unit tested quickly and easily. 2. Changes `string_to_output` to also replace `\r\n`, fixing Windows tests. 3. Improves other `normalize_*` functions and adds tests. Refs sass#2843
- Loading branch information
Showing
17 changed files
with
280 additions
and
73 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "util_string.hpp" | ||
|
||
#include <algorithm> | ||
|
||
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()); | ||
std::size_t pos = 0; | ||
while (true) { | ||
const std::size_t newline = str.find_first_of("\n\f\r", pos); | ||
if (newline == std::string::npos) break; | ||
result.append(str, pos, newline - pos); | ||
result += '\n'; | ||
if (str[newline] == '\r' && str[newline + 1] == '\n') { | ||
pos = newline + 2; | ||
} else { | ||
pos = newline + 1; | ||
} | ||
} | ||
result.append(str, pos, std::string::npos); | ||
return result; | ||
} | ||
|
||
std::string normalize_underscores(const std::string& str) { | ||
std::string normalized = str; | ||
std::replace(normalized.begin(), normalized.end(), '_', '-'); | ||
return normalized; | ||
} | ||
|
||
std::string normalize_decimals(const std::string& str) { | ||
std::string normalized; | ||
if (!str.empty() && str[0] == '.') { | ||
normalized.reserve(str.size() + 1); | ||
normalized += '0'; | ||
normalized += str; | ||
} else { | ||
normalized = str; | ||
} | ||
return 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.