def addHeaders()

in nlpcraft/src/main/scala/org/apache/nlpcraft/internal/ascii/NCAsciiTable.scala [250:305]


    def addHeaders(cells: List[Any]): NCAsciiTable =
        cells.foreach(addHeaderCell(_))
        this

    /**
      * Adds headers with the given `style`.
      *
      * @param style Style top use.
      * @param cells Header cells.
      */
    def addStyledHeaders(style: String, cells: List[Any]): NCAsciiTable =
        cells.foreach(addHeaderCell(style, _))
        this

    // Handles the 'null' strings.
    private def x(s: Any): String = s match
        case null => "<null>"
        case _ => s.toString

    /**
      *
      * @param maxWidth
      * @param lines
      */
    private def breakUpByNearestSpace(maxWidth: Int, lines: Seq[String]): Seq[String] =
        lines.flatMap(line => {
            if line.isEmpty then
                mutable.Buffer("")
            else
                val leader = line.indexWhere(_ != ' ') // Number of leading spaces.

                val buf = mutable.Buffer.empty[String]

                var start = 0
                var lastSpace = -1
                var curr = 0
                val len = line.length

                def addLine(s: String): Unit = buf += (if buf.isEmpty then s else s"${space(leader)}$s")

                while (curr < len)
                    if curr - start > maxWidth then
                        val end = if lastSpace == -1 then curr else lastSpace + 1 /* Keep space at the end of the line. */
                        addLine(line.substring(start, end))
                        start = end
                    if line.charAt(curr) == ' ' then
                        lastSpace = curr

                    curr += 1

                if start < len then
                    val lastLine = line.substring(start)
                    if lastLine.trim.nonEmpty then addLine(lastLine)

                buf
        })