diff options
author | scria1000 <91804886+scria1000@users.noreply.github.com> | 2022-09-21 05:02:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-21 05:02:45 +0000 |
commit | 76c7e9e5451b973749c3ffa3ef1cf9e7895584a4 (patch) | |
tree | 0b5082fc899b8cb8ff762a8a09ab82e1c9336338 | |
parent | 269a01ed42916153e5c5e777e07724c08774c40f (diff) | |
download | infinity-for-reddit-76c7e9e5451b973749c3ffa3ef1cf9e7895584a4.tar infinity-for-reddit-76c7e9e5451b973749c3ffa3ef1cf9e7895584a4.tar.gz infinity-for-reddit-76c7e9e5451b973749c3ffa3ef1cf9e7895584a4.tar.bz2 infinity-for-reddit-76c7e9e5451b973749c3ffa3ef1cf9e7895584a4.tar.lz infinity-for-reddit-76c7e9e5451b973749c3ffa3ef1cf9e7895584a4.tar.xz infinity-for-reddit-76c7e9e5451b973749c3ffa3ef1cf9e7895584a4.tar.zst infinity-for-reddit-76c7e9e5451b973749c3ffa3ef1cf9e7895584a4.zip |
Don't trim leading whitespaces (#1072)
Co-authored-by: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>
6 files changed, 24 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java index 39b8e2b5..90102d41 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedComment.java @@ -106,7 +106,7 @@ public class FetchRemovedComment { private static Comment parseRemovedComment(@NonNull JSONObject result, Comment comment) throws JSONException { String id = result.getString(JSONUtils.ID_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); if (id.equals(comment.getId()) && diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java index ab9c9c5a..82222caa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchRemovedCommentReveddit.java @@ -54,7 +54,7 @@ public class FetchRemovedCommentReveddit { private static Comment parseRemovedComment(JSONObject result, Comment comment) throws JSONException { String id = result.getString(JSONUtils.ID_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); if (id.equals(comment.getId()) && (!author.equals(comment.getAuthor()) || !body.equals(comment.getCommentRawText()))) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java index 245c9e60..0a341ff3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java @@ -200,7 +200,7 @@ public class ParseComment { String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY); String commentMarkdown = ""; 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)) { JSONObject mediaMetadataObject = singleCommentData.getJSONObject(JSONUtils.MEDIA_METADATA_KEY); commentMarkdown = Utils.parseInlineEmotes(commentMarkdown, mediaMetadataObject); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java index e49ffa7e..07ded976 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java @@ -45,7 +45,7 @@ public class FetchRemovedPost { String id = result.getString(JSONUtils.ID_KEY); String author = result.getString(JSONUtils.AUTHOR_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()) && (!author.equals(post.getAuthor()) || diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index 71f131d3..9374ba75 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -306,7 +306,7 @@ public class ParsePost { if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } 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); @@ -480,7 +480,7 @@ public class ParsePost { if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } 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); @@ -549,7 +549,7 @@ public class ParsePost { if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } 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); @@ -696,7 +696,7 @@ public class ParsePost { if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } 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); if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { post.setSelfTextPlainTrimmed(""); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index ff65b536..a663cfb4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -208,6 +208,22 @@ public final class Utils { 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) { if (source == null) { |