aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-02-22 15:36:27 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-02-22 15:36:27 +0000
commitfea59bc66df35664029f3dca14de4b444ba6ef9e (patch)
tree3b44e1a71bee43f820810d30ec546edc83e78123 /app/src/main/java
parent5b831aafbc58f70a44d3df8a7aaf27a81bfd2dac (diff)
downloadinfinity-for-reddit-fea59bc66df35664029f3dca14de4b444ba6ef9e.tar
infinity-for-reddit-fea59bc66df35664029f3dca14de4b444ba6ef9e.tar.gz
infinity-for-reddit-fea59bc66df35664029f3dca14de4b444ba6ef9e.tar.bz2
infinity-for-reddit-fea59bc66df35664029f3dca14de4b444ba6ef9e.tar.lz
infinity-for-reddit-fea59bc66df35664029f3dca14de4b444ba6ef9e.tar.xz
infinity-for-reddit-fea59bc66df35664029f3dca14de4b444ba6ef9e.tar.zst
infinity-for-reddit-fea59bc66df35664029f3dca14de4b444ba6ef9e.zip
Try to fix superscript rendering.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java60
1 files changed, 59 insertions, 1 deletions
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 c0abde00..13ae3a79 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
@@ -48,8 +48,9 @@ public class Utils {
.replaceAll("(^|^ *|\\n *)#####(?!($|\\s|#))", "$0 ")
.replaceAll("(^|^ *|\\n *)######(?!($|\\s|#))", "$0 "));
+ return fixSuperScript(regexed);
//Fix superscript
- int startIndex = regexed.indexOf("^");
+ /*int startIndex = regexed.indexOf("^");
while (startIndex >= 0 && startIndex + 1 < regexed.length()) {
char currentChar = regexed.charAt(startIndex + 1);
if (currentChar == '^') {
@@ -58,6 +59,11 @@ public class Utils {
} else if (currentChar == ' ' || currentChar == '\n') {
regexed.insert(startIndex + 1, '^');
startIndex = regexed.indexOf("^", startIndex + 2);
+ } else if (currentChar == '(') {
+ int closeBracketIndex = regexed.indexOf(")", startIndex + 2);
+ if (closeBracketIndex > 0) {
+
+ }
} else {
if (startIndex + 1 == regexed.length() - 1) {
regexed.append('^');
@@ -66,6 +72,58 @@ public class Utils {
startIndex++;
}
}
+ return regexed.toString();*/
+ }
+
+ public static String fixSuperScript(StringBuilder regexed) {
+ int newestCaretIndex = regexed.indexOf("^");
+ if (newestCaretIndex >= 0) {
+ boolean hasBracket = false;
+ int caretWithLeftBracketIndex = -1;
+ for (int i = newestCaretIndex + 1; i < regexed.length(); i++) {
+ char currentChar = regexed.charAt(i);
+ if (currentChar == '^') {
+ if (!(i > 0 && regexed.charAt(i - 1) == '\\')) {
+ if (newestCaretIndex < 0) {
+ newestCaretIndex = i;
+ } else {
+ regexed.insert(i, '^');
+ newestCaretIndex = i + 1;
+ i++;
+ if (newestCaretIndex == regexed.length() - 1) {
+ regexed.deleteCharAt(regexed.length() - 1);
+ newestCaretIndex = -1;
+ break;
+ }
+ }
+ }
+ } else if (currentChar == ' ' || currentChar == '\n') {
+ if (newestCaretIndex >= 0) {
+ regexed.insert(i, '^');
+ newestCaretIndex = -1;
+ i++;
+ }
+ } else if (currentChar == '(') {
+ if (newestCaretIndex >= 0 && i == newestCaretIndex + 1) {
+ hasBracket = true;
+ newestCaretIndex = -1;
+ caretWithLeftBracketIndex = i - 1;
+ }
+ } else if (currentChar == ')') {
+ if (hasBracket) {
+ hasBracket = false;
+ regexed.setCharAt(i, '^');
+ regexed.replace(caretWithLeftBracketIndex, caretWithLeftBracketIndex + 2, "^");
+ caretWithLeftBracketIndex = -1;
+ i--;
+ }
+ }
+ }
+ if (newestCaretIndex >=0 || caretWithLeftBracketIndex >= 0) {
+ regexed.insert(regexed.length(), '^');
+ }
+ }
+
return regexed.toString();
}