aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimePath <[email protected]>2014-12-28 20:40:06 +1100
committerShevek <[email protected]>2014-12-30 19:05:54 -0800
commitf511c467c74077d4254ebc69656edf2d818030dc (patch)
tree896b2a4b2ae655b95f27a59b34827e5ac09be442
parenta3306f269ec75a617f7bf4ee6a292a961ba2c1f5 (diff)
Trim whitespace from macro parameters when a new line is detected. Fixes #25
Signed-off-by: Shevek <[email protected]>
-rw-r--r--src/main/java/org/anarres/cpp/MacroTokenSource.java6
-rw-r--r--src/test/java/org/anarres/cpp/PreprocessorTest.java2
2 files changed, 7 insertions, 1 deletions
diff --git a/src/main/java/org/anarres/cpp/MacroTokenSource.java b/src/main/java/org/anarres/cpp/MacroTokenSource.java
index 5874584..07c388c 100644
--- a/src/main/java/org/anarres/cpp/MacroTokenSource.java
+++ b/src/main/java/org/anarres/cpp/MacroTokenSource.java
@@ -78,9 +78,13 @@ import static org.anarres.cpp.Token.*;
private void concat(StringBuilder buf, Argument arg) {
Iterator<Token> it = arg.iterator();
+ boolean newline = false;
while (it.hasNext()) {
Token tok = it.next();
- buf.append(tok.getText());
+ String text = tok.getText();
+ if (text.contains("\n")) newline = true;
+ if (newline) text = text.trim();
+ buf.append(text);
}
}
diff --git a/src/test/java/org/anarres/cpp/PreprocessorTest.java b/src/test/java/org/anarres/cpp/PreprocessorTest.java
index e55b568..80d0cba 100644
--- a/src/test/java/org/anarres/cpp/PreprocessorTest.java
+++ b/src/test/java/org/anarres/cpp/PreprocessorTest.java
@@ -102,6 +102,8 @@ public class PreprocessorTest {
testInput("#define _CONCAT3(x, y, z) x ## y ## z\n", NL);
testInput("_CONCAT3(a, b, c)\n", NL, I("abc"));
testInput("_CONCAT3(A, B, C)\n", NL, I("ABC"));
+ testInput("_CONCAT(test_, inline)\n", NL, I("test_inline"));
+ testInput("_CONCAT(test_, \nnewline)\n", NL, I("test_newline"));
/* Redefinitions, undefinitions. */
testInput("#define two three\n", NL);