@@ -219,7 +219,10 @@ fun Int.isFound() = this >= 0
219219fun Int.notFound () = this == - 1
220220
221221/* *
222- * @return String with applied font params
222+ * Apply font params to string.
223+ *
224+ * @param color Color as formatter string
225+ * @return Formatted string
223226 */
224227fun String.withFontParams (color : String? ): String {
225228 val parametrizedString = StringBuilder ()
@@ -232,13 +235,13 @@ fun String.withFontParams(color: String?): String {
232235 else { // may contain multiple lines with line breaks
233236
234237 // put tag on the borders (end & start of line, ..., end of tag)
235- while (newIdx.isFound()) { // until closing tag is reached
236- val part = substring(idx.. newIdx).inFontTag(color)
238+ do { // until closing tag is reached
239+ val part = substring(idx.. newIdx - 1 ).inFontTag(color).plus( " \n " )
237240 parametrizedString.append(part)
238241
239- idx = newIdx
240- newIdx = indexOf(" \n " , idx + 1 )
241- }
242+ idx = newIdx + 1
243+ newIdx = indexOf(" \n " , idx)
244+ } while (newIdx.isFound())
242245
243246 if (idx != indexOf(" \n " )) // if not replaced only once (for multiline tag coverage)
244247 parametrizedString.append(substring(idx).inFontTag(color))
@@ -251,7 +254,7 @@ fun String.withFontParams(color: String?): String {
251254 * @return String with escaped line break at start
252255 */
253256fun String.escLineBreakAtStart () =
254- if (startsWith(" \n " ) && length >= 2 )
257+ if (startsWith(" \n " ) && length >= 1 )
255258 substring(1 )
256259 else this
257260
0 commit comments