diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-10-03 20:20:02 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-10-03 20:20:02 +0400 |
commit | d6fd04521ba4c4c430286078dd56309111c180e6 (patch) | |
tree | cd02584ade5cd0c0cfa8da30da5ccb0ea7b2131c /src/RichContent | |
parent | 7c6da4babd01da31c57c5c6c827eb2957c989b1c (diff) | |
download | dokka-d6fd04521ba4c4c430286078dd56309111c180e6.tar.gz dokka-d6fd04521ba4c4c430286078dd56309111c180e6.tar.bz2 dokka-d6fd04521ba4c4c430286078dd56309111c180e6.zip |
Cross-reference links on types, relative locations.
Diffstat (limited to 'src/RichContent')
-rw-r--r-- | src/RichContent/RichString.kt | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/RichContent/RichString.kt b/src/RichContent/RichString.kt deleted file mode 100644 index 2110c47f..00000000 --- a/src/RichContent/RichString.kt +++ /dev/null @@ -1,84 +0,0 @@ -package org.jetbrains.dokka - -public class RichString { - private val sliceList = arrayListOf<RichStringSlice>() - public val slices: List<RichStringSlice> get() = sliceList - - public fun addSlice(slice: RichStringSlice) { - if (slice.text.length() > 0) - sliceList.add(slice) - } - - public fun addSlice(text: String, style: RichStringStyle) { - // TODO: decide on semantics - // empty slices makes it hard to compare rich strings - if (text.length > 0) - sliceList.add(RichStringSlice(text, style)) - } - - public fun isEmpty(): Boolean = sliceList.isEmpty() - - public fun length(): Int = sliceList.fold(0) {(acc, value) -> return acc + value.text.length } - - public override fun toString(): String { - return sliceList.joinToString("", "&") - } - - override fun equals(other: Any?): Boolean { - if (other !is RichString) - return false - if (sliceList.size != other.sliceList.size) - return false - for (index in sliceList.indices) - if (!sliceList[index].equals(other.sliceList[index])) - return false - - return true - } - - override fun hashCode(): Int { - return sliceList.map { it.hashCode() }.sum() - } - - class object { - public val empty: RichString = RichString() - } -} - -public data class RichStringSlice(public val text: String, public val style: RichStringStyle) { - public override fun toString(): String { - return text - } -} - -public trait RichStringStyle -public object NormalStyle : RichStringStyle -public object BoldStyle : RichStringStyle -public object CodeStyle : RichStringStyle -public data class LinkStyle(val link: String) : RichStringStyle - -public fun RichString.splitBy(delimiter: String): Pair<RichString, RichString> { - var index = 0 - while (index < slices.size && !slices[index].text.contains(delimiter)) index++ - if (index == slices.size) - return Pair(this, RichString.empty) - - val first = RichString() - val second = RichString() - - for (i in 0..index - 1) { - first.addSlice(slices[i]) - } - - val splitSlice = slices[index] - val firstText = splitSlice.text.substringBefore(delimiter) - val secondText = splitSlice.text.substringAfter(delimiter) - first.addSlice(firstText, splitSlice.style) - second.addSlice(secondText, splitSlice.style) - - for (i in index + 1..slices.size - 1) { - second.addSlice(slices[i]) - } - - return Pair(first, second) -} |