All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.specs2.text.Indent.scala Maven / Gradle / Ivy

The newest version!
package org.specs2
package text

/**
 *  various functions for working out indentation
 */
object Indent {

  def indentAllButFirstLine(text: String, spaces: String): String = {
    val lines = text.split("\n", -1)
    val firstLine = lines.headOption
    val rest = lines.drop(1)
    (firstLine.toSeq ++ rest.toList.map(spaces + _)).mkString("\n")
  }

  /** @return the spaces indenting the last line of text */
  def lastLineIndentation(text: String): String =
    text.split("\n", -1).lastOption.map(_.takeWhile(_ == ' ')).getOrElse("")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy