org.clulab.wm.eidoscommon.utils.StringUtils.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eidos-eidoscommon_2.12 Show documentation
Show all versions of eidos-eidoscommon_2.12 Show documentation
Code to be shared by other Eidos subprojects and clients
The newest version!
package org.clulab.wm.eidoscommon.utils
object StringUtils {
def before(string: String, index: Int, all: Boolean, keep: Boolean): String = {
if (index < 0)
if (all) string
else ""
else string.substring(0, index + (if (keep) 1 else 0))
}
def beforeLast(string: String, char: Char, all: Boolean = true, keep: Boolean = false): String =
before(string, string.lastIndexOf(char), all, keep)
def beforeFirst(string: String, char: Char, all: Boolean = true, keep: Boolean = false): String =
before(string, string.indexOf(char), all, keep)
def after(string: String, index: Int, all: Boolean, keep: Boolean): String = {
if (index < 0)
if (all) string
else ""
else string.substring(index + (if (keep) 0 else 1))
}
def afterLast(string: String, char: Char, all: Boolean = true, keep: Boolean = false): String =
after(string, string.lastIndexOf(char), all, keep)
def afterFirst(string: String, char: Char, all: Boolean = true, keep: Boolean = false): String =
after(string, string.indexOf(char), all, keep)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy