1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-22 08:22:04 +03:00

PreProcessor now replace every single char with a space, without collapsing multiline matches

This commit is contained in:
Federico Fissore
2013-11-18 10:59:51 +01:00
parent 7902fc2591
commit d0758af29a
14 changed files with 1672 additions and 504 deletions

View File

@ -257,9 +257,23 @@ public class PdePreprocessor {
// pre-processor directive
p += "|" + "(^\\s*#.*?$)";
StringBuilder sb = new StringBuilder(in);
Pattern pattern = Pattern.compile(p, Pattern.MULTILINE | Pattern.DOTALL);
Matcher matcher = pattern.matcher(in);
return matcher.replaceAll(" ");
Matcher matcher = pattern.matcher(sb);
while (matcher.find()) {
String replacement = composeReplacementString(new StringBuilder(sb.subSequence(matcher.start(), matcher.end())));
sb.replace(matcher.start(), matcher.end(), replacement);
}
return sb.toString();
}
private String composeReplacementString(StringBuilder sb) {
for (int i = 0; i < sb.length(); i++) {
if (sb.charAt(i) != '\n') {
sb.setCharAt(i, ' ');
}
}
return sb.toString();
}
/**
@ -388,7 +402,10 @@ public class PdePreprocessor {
} else {
// continue blanking this area
p[index++] = ' ';
if (p[index] != '\n') {
p[index] = ' ';
}
index++;
}
}
if (!endOfRainbow) {