package com.kdanmobile.reader.screen.model

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

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

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

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

        sb.append(result)

        result = sb.toString()
    }
}
