Lab 5, technically working prototype. It's horrid, though.
This commit is contained in:
parent
8e430b94ae
commit
49dfcfe457
|
@ -3,6 +3,8 @@ package OOP.Java.lab_5
|
|||
class Text(textString: String) {
|
||||
var textArray = arrayOf<Pair<Sentence, Punctuation>>()
|
||||
var rawText: String = ""
|
||||
val arrayOfSentences = splitSentences(textString)
|
||||
val arrayOfPunctuations: Array<Punctuation> = splitPunctuation(textString)
|
||||
|
||||
init {
|
||||
val arrayOfSentences = splitSentences(textString)
|
||||
|
@ -13,6 +15,8 @@ class Text(textString: String) {
|
|||
}
|
||||
|
||||
this.rawText = getRawTextString(arrayOfSentences)
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun splitSentences(textString: String): Array<Sentence> {
|
||||
|
@ -27,6 +31,25 @@ class Text(textString: String) {
|
|||
return arrayOfSentences.joinToString("") { sentence -> sentence.arrayOfWords.joinToString("") }
|
||||
}
|
||||
|
||||
fun palindromeSearch(): String {
|
||||
var results = arrayOf<String>()
|
||||
for (leftBoundary in 0 until this.rawText.length) {
|
||||
for (rightBoundary in this.rawText.length downTo leftBoundary + 1) {
|
||||
val subToC = this.rawText.substring(leftBoundary, rightBoundary)
|
||||
|
||||
if (subToC.first().equals(subToC.last(), true) && subToC.equals(subToC.reversed(), true) && subToC.length >= 3) {
|
||||
// println(subToC)
|
||||
results += subToC
|
||||
}
|
||||
}
|
||||
}
|
||||
return results.maxBy { it.length }
|
||||
}
|
||||
|
||||
fun checkStringInBoundaries(stringToCheck: String): Boolean {
|
||||
return stringToCheck.equals(stringToCheck.reversed(), true)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
var text = arrayOf<String>()
|
||||
this.textArray.forEach { text += it.first.toString() + it.second.toString() }
|
||||
|
|
Loading…
Reference in New Issue