Lab 5, technically working prototype. It's horrid, though.

This commit is contained in:
Rhinemann 2023-06-05 21:46:40 +03:00
parent 8e430b94ae
commit 49dfcfe457
3 changed files with 28 additions and 5 deletions

View File

@ -3,6 +3,8 @@ package OOP.Java.lab_5
class Text(textString: String) { class Text(textString: String) {
var textArray = arrayOf<Pair<Sentence, Punctuation>>() var textArray = arrayOf<Pair<Sentence, Punctuation>>()
var rawText: String = "" var rawText: String = ""
val arrayOfSentences = splitSentences(textString)
val arrayOfPunctuations: Array<Punctuation> = splitPunctuation(textString)
init { init {
val arrayOfSentences = splitSentences(textString) val arrayOfSentences = splitSentences(textString)
@ -13,6 +15,8 @@ class Text(textString: String) {
} }
this.rawText = getRawTextString(arrayOfSentences) this.rawText = getRawTextString(arrayOfSentences)
} }
private fun splitSentences(textString: String): Array<Sentence> { private fun splitSentences(textString: String): Array<Sentence> {
@ -27,6 +31,25 @@ class Text(textString: String) {
return arrayOfSentences.joinToString("") { sentence -> sentence.arrayOfWords.joinToString("") } 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 { override fun toString(): String {
var text = arrayOf<String>() var text = arrayOf<String>()
this.textArray.forEach { text += it.first.toString() + it.second.toString() } this.textArray.forEach { text += it.first.toString() + it.second.toString() }