26 std::string
prettify(
const std::string&
string) {
32 fInParseUntilNewline =
false;
33 fInParseUntil =
false;
39 fLength =
string.length();
40 fInput =
string.c_str();
42 while (fLength > fIndex) {
72 if (fInParseUntilNewline) {
73 this->parseUntilNewline();
77 this->parseUntil(fInParseUntilToken);
80 if (this->hasToken(
"#") || this->hasToken(
"//")) {
81 this->parseUntilNewline();
84 if (this->hasToken(
"/*")) {
85 this->parseUntil(
"*/");
88 if (fInput[fIndex] ==
'{') {
90 this->appendChar(
'{');
95 if (fInput[fIndex] ==
'}') {
98 this->appendChar(
'}');
102 if (fFreshline && fInput[fIndex] ==
';') {
103 this->undoNewlineAfter(
'}');
104 this->appendChar(fInput[fIndex]);
108 if (fFreshline && fInput[fIndex] ==
',') {
109 this->undoNewlineAfter(
'}');
110 this->appendChar(fInput[fIndex]);
113 if (this->hasToken(
")")) {
117 if (this->hasToken(
"(")) {
121 if (this->hasToken(
")")) {
125 if (!parensDepth && this->hasToken(
";")) {
129 if (fInput[fIndex] ==
'\t' || fInput[fIndex] ==
'\n' ||
130 (fFreshline && fInput[fIndex] ==
' ')) {
135 this->appendChar(fInput[fIndex]);
142 void appendChar(
char c) {
144 fPretty += fInput[fIndex++];
150 bool hasToken(
const char* token) {
152 for (
size_t j = 0; token[j] && fLength >
i;
i++, j++) {
153 if (token[j] != fInput[
i]) {
159 fPretty.append(token);
164 void parseUntilNewline() {
165 while (fLength > fIndex) {
166 if (fInput[fIndex] ==
'\n') {
169 fInParseUntilNewline =
false;
172 fPretty += fInput[fIndex++];
173 fInParseUntilNewline =
true;
180 void parseUntil(
const char* token) {
181 while (fLength > fIndex) {
185 if (fInput[fIndex] ==
'\n') {
190 if (this->hasToken(token)) {
191 fInParseUntil =
false;
195 fPretty += fInput[fIndex++];
196 fInParseUntil =
true;
197 fInParseUntilToken = token;
204 for (
int t = 0; t < fTabs; t++) {
221 void undoNewlineAfter(
char c) {
223 if (fPretty.size() >= 2 && fPretty.rbegin()[0] ==
'\n' && fPretty.rbegin()[1] == c) {
232 size_t fIndex, fLength;
237 bool fInParseUntilNewline;
239 const char* fInParseUntilToken;
248 const std::function<
void(
int lineNumber,
const char* lineText)>& visitFn) {
251 for (
int i = 0;
i <
lines.size(); ++
i) {
252 visitFn(
i + 1,
lines[
i].c_str());
257 std::string abortText{
"Shader compilation error\n"
258 "------------------------\n"};
267 const char* typeName =
"Unknown";
271 typeName =
"Fragment";
273 SkDebugf(
"---- %s shader ----------------------------------------------------\n", typeName);
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
void SkStrSplit(const char *str, const char *delimiters, SkStrSplitMode splitMode, TArray< SkString > *out)
std::string prettify(const std::string &string)
Dart_NativeFunction function
std::string void appendf(std::string *str, const char *fmt,...) SK_PRINTF_LIKE(2
std::string PrettyPrint(const std::string &string)
void VisitLineByLine(const std::string &text, const std::function< void(int lineNumber, const char *lineText)> &visitFn)
void PrintShaderBanner(SkSL::ProgramKind programKind)
std::string BuildShaderErrorMessage(const char *shader, const char *errors)
static bool IsVertex(ProgramKind kind)
static bool IsFragment(ProgramKind kind)