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

org.geneontology.owl.differ.Util.scala Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package org.geneontology.owl.differ

import com.google.common.base.Optional

object Util {

  implicit class StringOps(val self: String) extends AnyVal {

    def replaceLast(target: Char, replacement: String): String = {
      val lastIndex = self.lastIndexOf(target)
      if (lastIndex > -1) {
        val prefix = self.substring(0, lastIndex)
        val suffix = if (self.length > lastIndex + 1) self.substring(lastIndex + 1)
        else ""
        s"$prefix$replacement$suffix"
      } else self
    }

  }

  implicit class OptionalOption[T](val self: Optional[T]) extends AnyVal {

    def toOption: Option[T] = if (self.isPresent) Option(self.get) else None

  }

  def replaceNewlines(text: String): String = text.replaceAll("\\n", "\\\\n")

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy