tree-sitter/test/helpers/dedent.h
Max Brunsfeld 6dc0ff359d Rename spec -> test
'Test' is a lot more straightforward of a name.
2017-03-09 20:40:01 -08:00

12 lines
426 B
C++

#include "compiler/util/string_helpers.h"
#include <string>
static std::string dedent(std::string input) {
size_t indent_level = input.find_first_not_of("\n ") - input.find_first_not_of("\n");
std::string whitespace = "\n" + std::string(indent_level, ' ');
tree_sitter::util::str_replace(&input, whitespace, "\n");
return input.substr(
input.find_first_not_of("\n "),
input.find_last_not_of("\n ") + 1
);
}