Convert Readability to Kotlin

This commit is contained in:
Billy Brawner 2019-08-17 13:28:00 -05:00 committed by William Brawner
parent 829dc11c12
commit 787c044da6
2 changed files with 29 additions and 35 deletions

View file

@ -1,35 +0,0 @@
package com.wbrawner.simplemarkdown.model;
import java.util.ArrayList;
import java.util.List;
public class Readability {
private String content;
private static final String DELIMS = ".!?\n";
public Readability(String content) {
this.content = content;
}
public List<Sentence> sentences() {
ArrayList<Sentence> list = new ArrayList<>();
int startOfSentance = 0;
StringBuilder lineBuilder = new StringBuilder();
for (int i = 0; i < content.length(); i++) {
String c = content.charAt(i) + "";
if (DELIMS.contains(c)) {
list.add(new Sentence(content, startOfSentance, i));
startOfSentance = i + 1;
lineBuilder = new StringBuilder();
} else {
lineBuilder.append(c);
}
}
String line = lineBuilder.toString();
if (!line.isEmpty()) list.add(new Sentence(content, startOfSentance, content.length()));
return list;
}
}

View file

@ -0,0 +1,29 @@
package com.wbrawner.simplemarkdown.model
import java.util.*
class Readability(private val content: String) {
fun sentences(): List<Sentence> {
val list = ArrayList<Sentence>()
var startOfSentance = 0
var lineBuilder = StringBuilder()
for (i in 0 until content.length) {
val c = content[i] + ""
if (DELIMS.contains(c)) {
list.add(Sentence(content, startOfSentance, i))
startOfSentance = i + 1
lineBuilder = StringBuilder()
} else {
lineBuilder.append(c)
}
}
val line = lineBuilder.toString()
if (line.isNotEmpty()) list.add(Sentence(content, startOfSentance, content.length))
return list
}
companion object {
private const val DELIMS = ".!?\n"
}
}