Convert Readability to Kotlin
This commit is contained in:
parent
829dc11c12
commit
787c044da6
2 changed files with 29 additions and 35 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue