package com.kdanmobile.reader.screen.model

import android.graphics.RectF
import com.kdanmobile.kmpdfkit.pdfcommon.TextWord

class SearchResultInfo(var page: Int, var search: String, var rf: RectF, lines: Array<TextWord>) {
    var result: String = ""

    init {
        for (line in lines) {
            result = result + line.w + " "
        }

        val sb = StringBuilder()
        var src = result.toLowerCase()
        val seh = search.toLowerCase()
        var index = src.indexOf(seh)
        while (index >= 0) {
            sb.append(src.subSequence(0, index))
            sb.append("<font color=\"#ff0000\">")
            result = result.substring(index)
            sb.append(result.substring(0, search.length))
            sb.append("</font>")
            result = result.substring(search.length)
            src = src.substring(index + search.length)
            index = src.indexOf(seh)
        }

        sb.append(result)

        result = sb.toString()
    }
}
