From 32a400396d6c36ee7523cc01ddb18eedb8dc1c0c Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Tue, 17 Mar 2015 21:16:36 -0700 Subject: [PATCH] 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 --- .../util/src/main/java/org/jf/util/TextUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/brut.apktool.smali/util/src/main/java/org/jf/util/TextUtils.java b/brut.apktool.smali/util/src/main/java/org/jf/util/TextUtils.java index 784ee097..66a1082d 100644 --- a/brut.apktool.smali/util/src/main/java/org/jf/util/TextUtils.java +++ b/brut.apktool.smali/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;