Last active
February 3, 2019 16:25
-
-
Save MarkNjunge/5f3efb15719cc861be93a7985416e23c to your computer and use it in GitHub Desktop.
Revisions
-
MarkNjunge renamed this gist
Feb 3, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
MarkNjunge revised this gist
Feb 3, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,8 @@ while (text.contains(spoilerTag)) { // Get start and end of spoiler tags val start = text.indexOf(spoilerTag) val end = text.indexOf(spoilerTag, start + spoilerTag.length) - spoilerTag.length ranges.add(Pair(start, end)) // Remove starting spoiler tags // This is intentionally done before checking if an end tag exists to prevent an infinite loop @@ -19,6 +21,4 @@ while (text.contains(spoilerTag)) { // Remove ending spoiler tags text = text.replaceRange(end, end + spoilerTag.length, "") } -
MarkNjunge created this gist
Feb 3, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ var text = editText.text.toString() // Save the original text without the tags val original = text.replace(spoilerTag, "") // Get the character ranges val ranges = mutableListOf<Pair<Int, Int>>() while (text.contains(spoilerTag)) { // Get start and end of spoiler tags val start = text.indexOf(spoilerTag) val end = text.indexOf(spoilerTag, start + spoilerTag.length) - spoilerTag.length // Remove starting spoiler tags // This is intentionally done before checking if an end tag exists to prevent an infinite loop text = text.replaceRange(start, start + spoilerTag.length, "") // If there is no end tag, the text was badly formatted if (end <= start) continue // Remove ending spoiler tags text = text.replaceRange(end, end + spoilerTag.length, "") ranges.add(Pair(start, end)) }