aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gruver <bgruv@google.com>2015-03-17 21:16:36 -0700
committerBen Gruver <bgruv@google.com>2015-03-17 21:16:36 -0700
commit32e76b181b495b407f2f9ba5b8ffcdd90f4fbf0f (patch)
tree252bec8fe1c4936c588875cfe8ce3639dd1c718b
parentd4bce2e7684624a0d915c435d7abb2e84338e307 (diff)
downloadsmali-32e76b181b495b407f2f9ba5b8ffcdd90f4fbf0f.tar.gz
Fix up the whitespace normalization in TextUtils.normalizeWhitespace
Previously, all inter-line whitespace was being removed. And it now normalizes trailing new lines as well
-rw-r--r--util/src/main/java/org/jf/util/TextUtils.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/src/main/java/org/jf/util/TextUtils.java b/util/src/main/java/org/jf/util/TextUtils.java
index 784ee097..66a1082d 100644
--- a/util/src/main/java/org/jf/util/TextUtils.java
+++ b/util/src/main/java/org/jf/util/TextUtils.java
@@ -54,7 +54,7 @@ public class TextUtils {
source = normalizeNewlines(source);
// Remove all suffix/prefix whitespace
- Pattern pattern = Pattern.compile("((^[ \t]+)|([ \t]+))");
+ Pattern pattern = Pattern.compile("((^[ \t]+)|([ \t]+$))", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(source);
source = matcher.replaceAll("");
@@ -63,6 +63,11 @@ public class TextUtils {
Matcher matcher2 = pattern2.matcher(source);
source = matcher2.replaceAll("");
+ // Remove a trailing new line, if present
+ Pattern pattern3 = Pattern.compile("\r?\n?$");
+ Matcher matcher3 = pattern3.matcher(source);
+ source = matcher3.replaceAll("");
+
// Go back to unix-style \n newlines
source = normalizeNewlines(source, "\n");
return source;