Don't trim leading whitespaces (#1072)

Co-authored-by: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>
This commit is contained in:
scria1000 2022-09-21 08:02:45 +03:00 committed by GitHub
parent 269a01ed42
commit 76c7e9e545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 8 deletions

View File

@ -106,7 +106,7 @@ public class FetchRemovedComment {
private static Comment parseRemovedComment(@NonNull JSONObject result, Comment comment) throws JSONException { private static Comment parseRemovedComment(@NonNull JSONObject result, Comment comment) throws JSONException {
String id = result.getString(JSONUtils.ID_KEY); String id = result.getString(JSONUtils.ID_KEY);
String author = result.getString(JSONUtils.AUTHOR_KEY); String author = result.getString(JSONUtils.AUTHOR_KEY);
String body = Utils.modifyMarkdown(result.optString(JSONUtils.BODY_KEY).trim()); String body = Utils.modifyMarkdown(Utils.trimTrailingWhitespace(result.optString(JSONUtils.BODY_KEY)));
boolean isSubmitter = result.getBoolean(JSONUtils.IS_SUBMITTER_KEY); boolean isSubmitter = result.getBoolean(JSONUtils.IS_SUBMITTER_KEY);
if (id.equals(comment.getId()) && if (id.equals(comment.getId()) &&

View File

@ -54,7 +54,7 @@ public class FetchRemovedCommentReveddit {
private static Comment parseRemovedComment(JSONObject result, Comment comment) throws JSONException { private static Comment parseRemovedComment(JSONObject result, Comment comment) throws JSONException {
String id = result.getString(JSONUtils.ID_KEY); String id = result.getString(JSONUtils.ID_KEY);
String author = result.getString(JSONUtils.AUTHOR_KEY); String author = result.getString(JSONUtils.AUTHOR_KEY);
String body = Utils.modifyMarkdown(result.optString(JSONUtils.BODY_KEY).trim()); String body = Utils.modifyMarkdown(Utils.trimTrailingWhitespace(result.optString(JSONUtils.BODY_KEY)));
boolean isSubmitter = result.getBoolean(JSONUtils.IS_SUBMITTER_KEY); boolean isSubmitter = result.getBoolean(JSONUtils.IS_SUBMITTER_KEY);
if (id.equals(comment.getId()) && (!author.equals(comment.getAuthor()) || !body.equals(comment.getCommentRawText()))) { if (id.equals(comment.getId()) && (!author.equals(comment.getAuthor()) || !body.equals(comment.getCommentRawText()))) {

View File

@ -200,7 +200,7 @@ public class ParseComment {
String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY); String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY);
String commentMarkdown = ""; String commentMarkdown = "";
if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) { if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) {
commentMarkdown = Utils.parseInlineGifInComments(Utils.modifyMarkdown(singleCommentData.getString(JSONUtils.BODY_KEY).trim())); commentMarkdown = Utils.parseInlineGifInComments(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(singleCommentData.getString(JSONUtils.BODY_KEY))));
if (!singleCommentData.isNull(JSONUtils.MEDIA_METADATA_KEY)) { if (!singleCommentData.isNull(JSONUtils.MEDIA_METADATA_KEY)) {
JSONObject mediaMetadataObject = singleCommentData.getJSONObject(JSONUtils.MEDIA_METADATA_KEY); JSONObject mediaMetadataObject = singleCommentData.getJSONObject(JSONUtils.MEDIA_METADATA_KEY);
commentMarkdown = Utils.parseInlineEmotes(commentMarkdown, mediaMetadataObject); commentMarkdown = Utils.parseInlineEmotes(commentMarkdown, mediaMetadataObject);

View File

@ -45,7 +45,7 @@ public class FetchRemovedPost {
String id = result.getString(JSONUtils.ID_KEY); String id = result.getString(JSONUtils.ID_KEY);
String author = result.getString(JSONUtils.AUTHOR_KEY); String author = result.getString(JSONUtils.AUTHOR_KEY);
String title = result.getString(JSONUtils.TITLE_KEY); String title = result.getString(JSONUtils.TITLE_KEY);
String body = Utils.modifyMarkdown(result.getString(JSONUtils.SELFTEXT_KEY).trim()); String body = Utils.modifyMarkdown(Utils.trimTrailingWhitespace(result.getString(JSONUtils.SELFTEXT_KEY)));
if ( id.equals(post.getId()) && if ( id.equals(post.getId()) &&
(!author.equals(post.getAuthor()) || (!author.equals(post.getAuthor()) ||

View File

@ -306,7 +306,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim())); post.setSelfText(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))));
} }
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
@ -480,7 +480,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim())); post.setSelfText(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))));
} }
post.setPreviews(previews); post.setPreviews(previews);
@ -549,7 +549,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim())); post.setSelfText(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))));
} }
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
@ -696,7 +696,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
String selfText = Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()); String selfText = Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY)));
post.setSelfText(selfText); post.setSelfText(selfText);
if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
post.setSelfTextPlainTrimmed(""); post.setSelfTextPlainTrimmed("");

View File

@ -208,6 +208,22 @@ public final class Utils {
return markdown; return markdown;
} }
public static String trimTrailingWhitespace(String source) {
if (source == null) {
return "";
}
int i = source.length();
// loop back to the first non-whitespace character
do {
i--;
} while (i >= 0 && Character.isWhitespace(source.charAt(i)));
return source.substring(0, i + 1);
}
public static CharSequence trimTrailingWhitespace(CharSequence source) { public static CharSequence trimTrailingWhitespace(CharSequence source) {
if (source == null) { if (source == null) {