package com.kdanmobile.reader.screen.model

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

class SearchResultInfo(val page: Int, val keyword: String, val rectList: Array<RectF>, var result: String) {

    init {
        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()
    }
}
