Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • justJanne/libquassel
1 result
Select Git revision
Show changes
Showing
with 750 additions and 608 deletions
......@@ -17,124 +17,141 @@ import kotlin.math.min
* color and format codes
*/
object IrcFormatDeserializer {
fun parse(content: String) =
sequence {
var i = 0
var lastProcessed = 0
var current = IrcFormat.Style()
suspend fun SequenceScope<IrcFormat.Span>.emit() {
if (lastProcessed != i) {
yield(IrcFormat.Span(content.substring(lastProcessed, i), current))
lastProcessed = i
}
}
fun parse(content: String) = sequence {
var i = 0
var lastProcessed = 0
var current = IrcFormat.Style()
suspend fun SequenceScope<IrcFormat.Span>.emit() {
if (lastProcessed != i) {
yield(IrcFormat.Span(content.substring(lastProcessed, i), current))
lastProcessed = i
suspend fun SequenceScope<IrcFormat.Span>.processFlag(flag: IrcFormat.Flag) {
emit()
current = current.flipFlag(flag)
lastProcessed = ++i
}
}
suspend fun SequenceScope<IrcFormat.Span>.processFlag(flag: IrcFormat.Flag) {
emit()
current = current.flipFlag(flag)
lastProcessed = ++i
}
suspend fun SequenceScope<IrcFormat.Span>.processColor(
length: Int,
radix: Int = 10,
range: IntRange? = null,
matcher: (Char) -> Boolean,
): Pair<Int, Int?>? {
emit()
suspend fun SequenceScope<IrcFormat.Span>.processColor(
length: Int,
radix: Int = 10,
range: IntRange? = null,
matcher: (Char) -> Boolean
): Pair<Int, Int?>? {
emit()
// Skip Color Code
lastProcessed = ++i
val foregroundData = content.substring(i, min(i + length, content.length))
.takeWhile(matcher)
val foreground = foregroundData.toIntOrNull(radix)
?.takeIf { range == null || it in range }
?: return null
// Skip foreground
i += foregroundData.length
val backgroundData =
if (i < content.length && content[i] == ',')
content.substring(i + 1, min(i + length + 1, content.length))
// Skip Color Code
lastProcessed = ++i
val foregroundData =
content.substring(i, min(i + length, content.length))
.takeWhile(matcher)
else null
val background = backgroundData
?.toIntOrNull(radix)
?.takeIf { range == null || it in range }
if (background != null) {
// Skip background and separator
i += backgroundData.length + 1
}
val foreground =
foregroundData.toIntOrNull(radix)
?.takeIf { range == null || it in range }
?: return null
// Skip foreground
i += foregroundData.length
val backgroundData =
if (i < content.length && content[i] == ',') {
content.substring(i + 1, min(i + length + 1, content.length))
.takeWhile(matcher)
} else {
null
}
val background =
backgroundData
?.toIntOrNull(radix)
?.takeIf { range == null || it in range }
if (background != null) {
// Skip background and separator
i += backgroundData.length + 1
}
lastProcessed = i
lastProcessed = i
return Pair(foreground, background)
}
return Pair(foreground, background)
}
while (i < content.length) {
when (content[i]) {
CODE_BOLD -> processFlag(IrcFormat.Flag.BOLD)
CODE_ITALIC -> processFlag(IrcFormat.Flag.ITALIC)
CODE_UNDERLINE -> processFlag(IrcFormat.Flag.UNDERLINE)
CODE_STRIKETHROUGH -> processFlag(IrcFormat.Flag.STRIKETHROUGH)
CODE_MONOSPACE -> processFlag(IrcFormat.Flag.MONOSPACE)
CODE_SWAP, CODE_SWAP_KVIRC -> processFlag(IrcFormat.Flag.INVERSE)
CODE_COLOR -> {
val color = processColor(length = 2, range = 0..99) {
it in '0'..'9'
while (i < content.length) {
when (content[i]) {
CODE_BOLD -> processFlag(IrcFormat.Flag.BOLD)
CODE_ITALIC -> processFlag(IrcFormat.Flag.ITALIC)
CODE_UNDERLINE -> processFlag(IrcFormat.Flag.UNDERLINE)
CODE_STRIKETHROUGH -> processFlag(IrcFormat.Flag.STRIKETHROUGH)
CODE_MONOSPACE -> processFlag(IrcFormat.Flag.MONOSPACE)
CODE_SWAP, CODE_SWAP_KVIRC -> processFlag(IrcFormat.Flag.INVERSE)
CODE_COLOR -> {
val color =
processColor(length = 2, range = 0..99) {
it in '0'..'9'
}
current =
if (color == null) {
current.copy(foreground = null, background = null)
} else {
val (foreground, background) = color
current.copy(
foreground = foreground.takeUnless { it == 99 }?.let { IrcFormat.Color.Mirc(it) },
background =
if (background == null) {
current.background
} else {
background.takeUnless { it == 99 }?.let { IrcFormat.Color.Mirc(it) }
},
)
}
}
current = if (color == null) {
current.copy(foreground = null, background = null)
} else {
val (foreground, background) = color
current.copy(
foreground = foreground.takeUnless { it == 99 }?.let { IrcFormat.Color.Mirc(it) },
background = if (background == null) current.background
else background.takeUnless { it == 99 }?.let { IrcFormat.Color.Mirc(it) }
)
CODE_HEXCOLOR -> {
val color =
processColor(length = 6, radix = 16) {
it in '0'..'9' || it in 'a'..'f' || it in 'A'..'F'
}
current =
if (color == null) {
current.copy(foreground = null, background = null)
} else {
val (foreground, background) = color
current.copy(
foreground = IrcFormat.Color.Hex(foreground),
background =
background?.let {
IrcFormat.Color.Hex(it)
} ?: current.background,
)
}
}
}
CODE_HEXCOLOR -> {
val color = processColor(length = 6, radix = 16) {
it in '0'..'9' || it in 'a'..'f' || it in 'A'..'F'
CODE_RESET -> {
emit()
current = IrcFormat.Style()
lastProcessed = ++i
}
current = if (color == null) {
current.copy(foreground = null, background = null)
} else {
val (foreground, background) = color
current.copy(
foreground = IrcFormat.Color.Hex(foreground),
background = background?.let {
IrcFormat.Color.Hex(it)
} ?: current.background
)
else -> {
// Regular Character
i++
}
}
CODE_RESET -> {
emit()
current = IrcFormat.Style()
lastProcessed = ++i
}
else -> {
// Regular Character
i++
}
}
}
if (lastProcessed != content.length) {
yield(IrcFormat.Span(content.substring(lastProcessed), current))
if (lastProcessed != content.length) {
yield(IrcFormat.Span(content.substring(lastProcessed), current))
}
}.collapse { prev, current ->
if (prev.style == current.style) {
prev.copy(content = prev.content + current.content)
} else {
null
}
}
}.collapse { prev, current ->
if (prev.style == current.style) prev.copy(content = prev.content + current.content)
else null
}
private const val CODE_BOLD = 0x02.toChar()
private const val CODE_COLOR = 0x03.toChar()
......
......@@ -5,22 +5,24 @@ import java.io.Serializable
internal class StringJoiner(
private val delimiter: String,
private val prefix: String = "",
private val suffix: String = ""
private val suffix: String = "",
) : Serializable, Appendable {
private val builder = StringBuilder()
override fun append(data: CharSequence?, start: Int, end: Int): StringJoiner =
this.apply { prepareBuilder().append(data, start, end) }
override fun append(
data: CharSequence?,
start: Int,
end: Int,
): StringJoiner = this.apply { prepareBuilder().append(data, start, end) }
override fun append(data: CharSequence?): StringJoiner =
this.apply { prepareBuilder().append(data) }
override fun append(data: CharSequence?): StringJoiner = this.apply { prepareBuilder().append(data) }
override fun append(data: Char): StringJoiner =
this.apply { prepareBuilder().append(data) }
override fun append(data: Char): StringJoiner = this.apply { prepareBuilder().append(data) }
private fun prepareBuilder(): StringBuilder = builder.apply {
append(if (isEmpty()) prefix else delimiter)
}
private fun prepareBuilder(): StringBuilder =
builder.apply {
append(if (isEmpty()) prefix else delimiter)
}
override fun toString(): String =
if (builder.isEmpty()) {
......@@ -34,6 +36,9 @@ internal class StringJoiner(
}
fun length(): Int =
if (builder.isEmpty()) prefix.length + suffix.length
else builder.length + suffix.length
if (builder.isEmpty()) {
prefix.length + suffix.length
} else {
builder.length + suffix.length
}
}
......@@ -9,22 +9,23 @@
package de.justjanne.libquassel.irc.extensions
internal fun <T> Sequence<T>.collapse(callback: (T, T) -> T?) = sequence<T> {
var prev: T? = null
for (item in iterator()) {
if (prev != null) {
val collapsed = callback(prev, item)
if (collapsed == null) {
yield(prev)
prev = item
internal fun <T> Sequence<T>.collapse(callback: (T, T) -> T?) =
sequence<T> {
var prev: T? = null
for (item in iterator()) {
if (prev != null) {
val collapsed = callback(prev, item)
if (collapsed == null) {
yield(prev)
prev = item
} else {
prev = collapsed
}
} else {
prev = collapsed
prev = item
}
} else {
prev = item
}
if (prev != null) {
yield(prev)
}
}
if (prev != null) {
yield(prev)
}
}
......@@ -6,7 +6,7 @@ internal inline fun joinString(
delimiter: String = "",
prefix: String = "",
suffix: String = "",
builderAction: StringJoiner.() -> Unit
builderAction: StringJoiner.() -> Unit,
): String {
return StringJoiner(delimiter, prefix, suffix).apply(builderAction).toString()
}
......@@ -9,44 +9,44 @@ class IrcFormatDeserializerTest {
assertEquals(
emptyList(),
IrcFormatDeserializer.parse(
"\u000f"
).toList()
"\u000f",
).toList(),
)
assertEquals(
emptyList(),
IrcFormatDeserializer.parse(
"\u0003\u000f"
).toList()
"\u0003\u000f",
).toList(),
)
assertEquals(
listOf(
IrcFormat.Span(
"["
"[",
),
IrcFormat.Span(
"hdf-us",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.ITALIC),
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"] ["
"] [",
),
IrcFormat.Span(
"nd",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
"] blah blah blah"
"] blah blah blah",
),
),
IrcFormatDeserializer.parse(
"[\u001d\u000304hdf-us\u0003\u000f] [\u000307nd\u0003] blah blah blah"
).toList()
"[\u001d\u000304hdf-us\u0003\u000f] [\u000307nd\u0003] blah blah blah",
).toList(),
)
assertEquals(
......@@ -54,93 +54,93 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"New Break set to: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2)
)
foreground = IrcFormat.Color.Mirc(2),
),
),
IrcFormat.Span(
"Target: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span("388 "),
IrcFormat.Span(
"| ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2)
)
foreground = IrcFormat.Color.Mirc(2),
),
),
IrcFormat.Span(
"Type: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span("GS | "),
IrcFormat.Span(
"Break: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span("58,000 "),
IrcFormat.Span(
"| ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2)
)
foreground = IrcFormat.Color.Mirc(2),
),
),
IrcFormat.Span(
"120%: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span("48,000 | "),
IrcFormat.Span(
"135%: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span("43,000 "),
IrcFormat.Span(
"| ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2)
)
foreground = IrcFormat.Color.Mirc(2),
),
),
IrcFormat.Span(
"145%: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span("40,000 "),
IrcFormat.Span(
"| ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2)
)
foreground = IrcFormat.Color.Mirc(2),
),
),
IrcFormat.Span(
"180%: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span("32,000"),
IrcFormat.Span(
" | ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2)
)
foreground = IrcFormat.Color.Mirc(2),
),
),
IrcFormat.Span(
"Pop: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span("73819"),
),
......@@ -148,8 +148,8 @@ class IrcFormatDeserializerTest {
"\u000302New Break set to: \u000303Target: \u000399388 \u000302| \u000303Type: " +
"\u000399GS | \u000303Break: \u00039958,000 \u000302| \u000303120%: \u00039948,000 | " +
"\u000303135%: \u00039943,000 \u000302| \u000303145%: \u00039940,000 \u000302| " +
"\u000303180%: \u00039932,000\u000302 | \u000303Pop: \u00039973819\u000f"
).toList()
"\u000303180%: \u00039932,000\u000302 | \u000303Pop: \u00039973819\u000f",
).toList(),
)
}
......@@ -161,14 +161,14 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"Strikethrough",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.STRIKETHROUGH)
)
flags = setOf(IrcFormat.Flag.STRIKETHROUGH),
),
),
IrcFormat.Span("Normal")
IrcFormat.Span("Normal"),
),
IrcFormatDeserializer.parse(
"Normal\u001eStrikethrough\u001eNormal"
).toList()
"Normal\u001eStrikethrough\u001eNormal",
).toList(),
)
}
......@@ -180,30 +180,30 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"Second",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.INVERSE)
)
flags = setOf(IrcFormat.Flag.INVERSE),
),
),
IrcFormat.Span(
"Red/Green",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.INVERSE),
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(3)
)
background = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"Green/Red",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(3)
)
background = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"Green/Magenta",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(6),
background = IrcFormat.Color.Mirc(3)
)
background = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"Magenta/Green",
......@@ -211,12 +211,12 @@ class IrcFormatDeserializerTest {
flags = setOf(IrcFormat.Flag.INVERSE),
foreground = IrcFormat.Color.Mirc(6),
background = IrcFormat.Color.Mirc(3),
)
),
),
),
IrcFormatDeserializer.parse(
"First\u0016Second\u00034,3Red/Green\u0016Green/Red\u00036Green/Magenta\u0016Magenta/Green"
).toList()
"First\u0016Second\u00034,3Red/Green\u0016Green/Red\u00036Green/Magenta\u0016Magenta/Green",
).toList(),
)
assertEquals(
......@@ -225,50 +225,50 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"Second",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.INVERSE)
)
flags = setOf(IrcFormat.Flag.INVERSE),
),
),
IrcFormat.Span(
"Third",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.INVERSE),
foreground = IrcFormat.Color.Mirc(2)
)
foreground = IrcFormat.Color.Mirc(2),
),
),
IrcFormat.Span(
"Red/Green",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(3)
)
background = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"Green/Red",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.INVERSE),
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(3)
)
background = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"Green/Magenta",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.INVERSE),
foreground = IrcFormat.Color.Mirc(6),
background = IrcFormat.Color.Mirc(3)
)
background = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"Magenta/Green",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(6),
background = IrcFormat.Color.Mirc(3),
)
),
),
),
IrcFormatDeserializer.parse(
"First\u0012Second\u00032Third\u0012\u00034,3Red/Green\u0012Green/Red\u00036Green/Magenta\u0016Magenta/Green"
).toList()
"First\u0012Second\u00032Third\u0012\u00034,3Red/Green\u0012Green/Red\u00036Green/Magenta\u0016Magenta/Green",
).toList(),
)
}
......@@ -279,40 +279,40 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"test ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"test",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.MONOSPACE),
foreground = IrcFormat.Color.Mirc(4)
)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
),
IrcFormatDeserializer.parse(
"\u00034test \u0011test"
).toList()
"\u00034test \u0011test",
).toList(),
)
assertEquals(
listOf(
IrcFormat.Span(
"test ",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.MONOSPACE)
)
flags = setOf(IrcFormat.Flag.MONOSPACE),
),
),
IrcFormat.Span(
"test",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.MONOSPACE),
foreground = IrcFormat.Color.Mirc(4)
)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
),
IrcFormatDeserializer.parse(
"\u0011test \u00034test"
).toList()
"\u0011test \u00034test",
).toList(),
)
assertEquals(
......@@ -321,13 +321,13 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"test`",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
),
IrcFormatDeserializer.parse(
"`test \u00034test`"
).toList()
"`test \u00034test`",
).toList(),
)
assertEquals(
......@@ -335,26 +335,26 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"[test ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"nick`name",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
flags = setOf(IrcFormat.Flag.BOLD)
)
flags = setOf(IrcFormat.Flag.BOLD),
),
),
IrcFormat.Span(
"] [nick`name]",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
),
IrcFormatDeserializer.parse(
"\u00034[test \u0002nick`name\u0002] [nick`name]"
).toList()
"\u00034[test \u0002nick`name\u0002] [nick`name]",
).toList(),
)
}
......@@ -367,56 +367,56 @@ class IrcFormatDeserializerTest {
"[",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(
"6,7,3,9,10,4,8,10,5",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(6)
)
foreground = IrcFormat.Color.Mirc(6),
),
),
IrcFormat.Span(
"]",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"Test2: ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(14)
)
foreground = IrcFormat.Color.Mirc(14),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(14)
)
foreground = IrcFormat.Color.Mirc(14),
),
),
IrcFormat.Span(
"[",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span("2,9"),
IrcFormat.Span(
"]",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
),
IrcFormatDeserializer.parse(
"Test 1: \u0002\u000312[\u00036\u00026,7,3,9,10,4,8,10,5\u0002\u000312]" +
"\u0003\u0002 \u000314Test2: \u0002 \u000312[\u0003\u00022,9\u0002\u000312]\u0003\u0002"
).toList()
"\u0003\u0002 \u000314Test2: \u0002 \u000312[\u0003\u00022,9\u0002\u000312]\u0003\u0002",
).toList(),
)
assertEquals(
......@@ -425,13 +425,13 @@ class IrcFormatDeserializerTest {
"Extended colors",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(55),
background = IrcFormat.Color.Mirc(25)
)
)
background = IrcFormat.Color.Mirc(25),
),
),
),
IrcFormatDeserializer.parse(
"\u000355,25Extended colors\u0003"
).toList()
"\u000355,25Extended colors\u0003",
).toList(),
)
assertEquals(
......@@ -441,41 +441,41 @@ class IrcFormatDeserializerTest {
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE),
foreground = IrcFormat.Color.Mirc(55),
background = IrcFormat.Color.Mirc(25)
)
background = IrcFormat.Color.Mirc(25),
),
),
IrcFormat.Span(
" cleared fg",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE),
background = IrcFormat.Color.Mirc(25)
)
background = IrcFormat.Color.Mirc(25),
),
),
IrcFormat.Span(
" cleared bg",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE),
foreground = IrcFormat.Color.Mirc(55)
)
foreground = IrcFormat.Color.Mirc(55),
),
),
IrcFormat.Span(
" cleared both",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE)
)
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE),
),
),
IrcFormat.Span(
" cleared bold",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.UNDERLINE)
)
flags = setOf(IrcFormat.Flag.UNDERLINE),
),
),
IrcFormat.Span(" cleared all")
IrcFormat.Span(" cleared all"),
),
IrcFormatDeserializer.parse(
"\u001f\u0002\u000355,25Transparent extended colors\u000399,25 cleared fg\u000355,99 cleared bg" +
"\u000399,99 cleared both\u0002 cleared bold\u000f cleared all",
).toList()
).toList(),
)
assertEquals(
......@@ -485,27 +485,27 @@ class IrcFormatDeserializerTest {
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(0),
background = IrcFormat.Color.Mirc(1)
)
background = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"(1)",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(0),
background = IrcFormat.Color.Mirc(1)
)
background = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(":"),
IrcFormat.Span(
" kokote",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2)
)
)
foreground = IrcFormat.Color.Mirc(2),
),
),
),
IrcFormatDeserializer.parse(
"\u00030,1\u0002Sniper_ShooterCZ\u0002(1)\u000f:\u00032 kokote"
).toList()
"\u00030,1\u0002Sniper_ShooterCZ\u0002(1)\u000f:\u00032 kokote",
).toList(),
)
assertEquals(
......@@ -513,42 +513,42 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"uncurry",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(9)
)
foreground = IrcFormat.Color.Mirc(9),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"Vect",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(" : "),
IrcFormat.Span(
"(Nat,",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"Type)",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(" -> "),
IrcFormat.Span(
"Type",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
),
IrcFormatDeserializer.parse(
"\u000309uncurry\u000f \u000312Vect\u000f : \u000312(\u000f\u000312Nat\u000f\u000312," +
"\u000f \u000312Type\u000f\u000312)\u000f -> \u000312Type\u000f"
).toList()
"\u000f \u000312Type\u000f\u000312)\u000f -> \u000312Type\u000f",
).toList(),
)
assertEquals(
......@@ -557,8 +557,8 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"ACTIVITIES",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD)
)
flags = setOf(IrcFormat.Flag.BOLD),
),
),
IrcFormat.Span("): Mugging: "),
IrcFormat.Span(
......@@ -566,28 +566,28 @@ class IrcFormatDeserializerTest {
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3),
background = IrcFormat.Color.Mirc(3),
)
),
),
IrcFormat.Span(
"||",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(
"34%",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(0),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(
"||||||||",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(" | [under dev] Piracy: "),
IrcFormat.Span(
......@@ -595,23 +595,23 @@ class IrcFormatDeserializerTest {
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(
"0.9%",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(0),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(
"||||||||",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(" (exploring) | At this rate, you will get: Fined")
IrcFormat.Span(" (exploring) | At this rate, you will get: Fined"),
),
IrcFormatDeserializer.parse(
"*** (\u0002ACTIVITIES\u000f): Mugging: \u000303,03|\u000303,03|\u000303,03|\u000303,03|" +
......@@ -622,7 +622,7 @@ class IrcFormatDeserializerTest {
"\u000300,049\u000300,04%\u000304,04|\u000304,04|\u000304,04|\u000304,04|\u000304,04|" +
"\u000304,04|\u000304,04|\u000304,04|\u000300,04\u000f (exploring) | At this rate, you " +
"will get: Fined",
).toList()
).toList(),
)
assertEquals(
......@@ -630,59 +630,59 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"\\u000308 ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(8)
)
foreground = IrcFormat.Color.Mirc(8),
),
),
IrcFormat.Span(
"\\u000310 ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(10)
)
foreground = IrcFormat.Color.Mirc(10),
),
),
IrcFormat.Span(
"\\u0002 ",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(10)
)
foreground = IrcFormat.Color.Mirc(10),
),
),
IrcFormat.Span(
"\\u000304 ",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"\\u0002 ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"\\u000309 ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(9)
)
foreground = IrcFormat.Color.Mirc(9),
),
),
IrcFormat.Span(
"\\u0002 ",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(9)
)
foreground = IrcFormat.Color.Mirc(9),
),
),
IrcFormat.Span(
"\\u0002",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(9)
)
foreground = IrcFormat.Color.Mirc(9),
),
),
),
IrcFormatDeserializer.parse(
"\u000308\\u000308 \u000310\\u000310 \u0002\\u0002 \u000304\\u000304 \u0002\\u0002 " +
"\u000309\\u000309 \u0002\\u0002 \u0002\\u0002"
).toList()
"\u000309\\u000309 \u0002\\u0002 \u0002\\u0002",
).toList(),
)
assertEquals(
......@@ -690,33 +690,33 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"teal",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(10)
)
foreground = IrcFormat.Color.Mirc(10),
),
),
IrcFormat.Span(
"boldteal",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(10)
)
foreground = IrcFormat.Color.Mirc(10),
),
),
IrcFormat.Span(
"boldred",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"red",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
),
IrcFormatDeserializer.parse(
"\u000310teal\u0002boldteal\u000304boldred\u0002red",
).toList()
).toList(),
)
assertEquals(
......@@ -724,73 +724,73 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"The channel for help with general IRC things such as ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"clients",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(13)
)
foreground = IrcFormat.Color.Mirc(13),
),
),
IrcFormat.Span(
", ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"BNCs",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
", ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"bots",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
", ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
"scripting",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(6)
)
foreground = IrcFormat.Color.Mirc(6),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(6)
)
foreground = IrcFormat.Color.Mirc(6),
),
),
IrcFormat.Span(
"etc.",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
),
IrcFormatDeserializer.parse(
"\u00033The channel for help with general IRC things such as \u0002\u000313clients" +
"\u0002\u00033, \u0002\u00037BNCs\u0002\u00033, \u0002\u00034bots\u0002\u00033, " +
"\u0002\u00036scripting\u0002 \u00033etc.",
).toList()
).toList(),
)
assertEquals(
......@@ -799,19 +799,19 @@ class IrcFormatDeserializerTest {
"hi ",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(10)
)
foreground = IrcFormat.Color.Mirc(10),
),
),
IrcFormat.Span(
"hola",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(10)
)
)
foreground = IrcFormat.Color.Mirc(10),
),
),
),
IrcFormatDeserializer.parse(
"\u0002\u000310hi \u0002hola"
).toList()
"\u0002\u000310hi \u0002hola",
).toList(),
)
assertEquals(
......@@ -820,19 +820,19 @@ class IrcFormatDeserializerTest {
"hi ",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(10)
)
foreground = IrcFormat.Color.Mirc(10),
),
),
IrcFormat.Span(
"hola",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD)
)
)
flags = setOf(IrcFormat.Flag.BOLD),
),
),
),
IrcFormatDeserializer.parse(
"\u000310\u0002hi \u0003hola"
).toList()
"\u000310\u0002hi \u0003hola",
).toList(),
)
assertEquals(
......@@ -841,26 +841,26 @@ class IrcFormatDeserializerTest {
"h",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(10)
)
foreground = IrcFormat.Color.Mirc(10),
),
),
IrcFormat.Span(
"i ",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"hola",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
),
IrcFormatDeserializer.parse(
"\u0002\u000310h\u00034i \u0002hola"
).toList()
"\u0002\u000310h\u00034i \u0002hola",
).toList(),
)
assertEquals(
......@@ -870,42 +870,42 @@ class IrcFormatDeserializerTest {
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(
"(",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3),
background = IrcFormat.Color.Mirc(0),
)
),
),
IrcFormat.Span(
"✰",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(8),
background = IrcFormat.Color.Mirc(0),
)
),
),
IrcFormat.Span(
")",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3),
background = IrcFormat.Color.Mirc(0),
)
),
),
IrcFormat.Span(
"__",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2),
background = IrcFormat.Color.Mirc(2),
)
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(0),
background = IrcFormat.Color.Mirc(1),
)
),
),
IrcFormat.Span(
"Ejercito Paraguayo",
......@@ -913,49 +913,49 @@ class IrcFormatDeserializerTest {
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(0),
background = IrcFormat.Color.Mirc(1),
)
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(0),
background = IrcFormat.Color.Mirc(1),
)
),
),
IrcFormat.Span(
"__",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(
"(",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3),
background = IrcFormat.Color.Mirc(0),
)
),
),
IrcFormat.Span(
"✰",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(8),
background = IrcFormat.Color.Mirc(0),
)
),
),
IrcFormat.Span(
")",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3),
background = IrcFormat.Color.Mirc(0),
)
),
),
IrcFormat.Span(
"__",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(2),
background = IrcFormat.Color.Mirc(2),
)
),
),
IrcFormat.Span("***** Lord Commander: mdmg - Sub-Comandantes: Sgto_Galleta ***** "),
IrcFormat.Span(
......@@ -963,7 +963,7 @@ class IrcFormatDeserializerTest {
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(0),
background = IrcFormat.Color.Mirc(4),
)
),
),
IrcFormat.Span(" https://i.imgur.com/bTWzTuA.jpg"),
),
......@@ -972,31 +972,31 @@ class IrcFormatDeserializerTest {
"\u0002 \u00034,4__\u00033,0(\u00038,0✰\u00033,0)\u00032,2__" +
"\u00031\u0003***** Lord Commander: mdmg - Sub-Comandantes: Sgto_Galleta ***** " +
"\u00030,4 Vencer o Morir!!! Que alguien pase una nueva xd" +
"\u0003 https://i.imgur.com/bTWzTuA.jpg"
).toList()
"\u0003 https://i.imgur.com/bTWzTuA.jpg",
).toList(),
)
assertEquals(
emptyList(),
IrcFormatDeserializer.parse(
"\u00034\u000f"
).toList()
"\u00034\u000f",
).toList(),
)
assertEquals(
listOf(
IrcFormat.Span("hello")
IrcFormat.Span("hello"),
),
IrcFormatDeserializer.parse(
"\u00034\u000fhello"
).toList()
"\u00034\u000fhello",
).toList(),
)
assertEquals(
emptyList(),
IrcFormatDeserializer.parse(
"\u00031"
).toList()
"\u00031",
).toList(),
)
assertEquals(
......@@ -1005,14 +1005,14 @@ class IrcFormatDeserializerTest {
">bold",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span("test")
IrcFormat.Span("test"),
),
IrcFormatDeserializer.parse(
"\u000304\u0002>bold\u0002\u0003test"
).toList()
"\u000304\u0002>bold\u0002\u0003test",
).toList(),
)
assertEquals(
......@@ -1020,48 +1020,48 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"P",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span("layers"),
IrcFormat.Span(
"(",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
"1/12",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(14)
)
foreground = IrcFormat.Color.Mirc(14),
),
),
IrcFormat.Span(
")",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"Kenzi",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(15)
)
foreground = IrcFormat.Color.Mirc(15),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"C",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span("urrent votewinner: none | ?? help for all the commands | www.no1gaming.eu | #no1"),
),
IrcFormatDeserializer.parse(
"\u00037P\u000flayers\u00037(\u0003141/12\u00037)\u000f \u000315Kenzi\u0003 \u00037C" +
"\u000furrent votewinner: none | ?? help for all the commands | www.no1gaming.eu | #no1",
).toList()
).toList(),
)
assertEquals(
......@@ -1070,25 +1070,25 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"Red ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"Green",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(3)
)
foreground = IrcFormat.Color.Mirc(3),
),
),
IrcFormat.Span(
" Bold",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD)
)
)
flags = setOf(IrcFormat.Flag.BOLD),
),
),
),
IrcFormatDeserializer.parse(
"First \u00034Red \u00033Green\u0003\u0002 Bold\u0002\u000f",
).toList()
).toList(),
)
assertEquals(
......@@ -1097,49 +1097,49 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"Color",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
" Bold",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD)
)
flags = setOf(IrcFormat.Flag.BOLD),
),
),
IrcFormat.Span(" unnecessary: "),
IrcFormat.Span(
"Color",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span("\u0000 plain "),
IrcFormat.Span(
"Color",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"Bold",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD)
)
flags = setOf(IrcFormat.Flag.BOLD),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"No space color New color",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
),
IrcFormatDeserializer.parse(
"First \u00034Color\u0003\u0002 Bold\u0002 unnecessary:\u0003 \u00034Color" +
"\u0003\u0000 plain \u00034Color\u0003\u000f \u0002Bold\u000f \u00034No space color" +
"\u0003\u00034 New color\u000f",
).toList()
).toList(),
)
assertEquals(
......@@ -1148,90 +1148,90 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"Visit us at ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"www.dalnethelpdesk.com",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.UNDERLINE),
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(" for scripting info, forums, and searchable logs/stats "),
IrcFormat.Span(
"Looking for a script/bot/addon?",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"mircscripts.org",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE)
)
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"or",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
"mirc.net",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE)
)
flags = setOf(IrcFormat.Flag.BOLD, IrcFormat.Flag.UNDERLINE),
),
),
IrcFormat.Span(" "),
IrcFormat.Span(
" Writing your own?",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(
" Ask ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"here.",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(" - "),
IrcFormat.Span(
"m",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(
"IR",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
"Casdsaa",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(8)
)
foreground = IrcFormat.Color.Mirc(8),
),
),
IrcFormat.Span("asdasd v7.14 has been released")
IrcFormat.Span("asdasd v7.14 has been released"),
),
IrcFormatDeserializer.parse(
"DALnet's recommended mIRC scripting & bot help channel. \u00034Visit us at " +
......@@ -1240,7 +1240,7 @@ class IrcFormatDeserializerTest {
"\u000f \u00034or\u000f \u0002\u001fmirc.net\u000f \u000312 Writing your own?\u0003" +
"\u00034 Ask \u0002here.\u0002 \u000f - \u000312m\u00034IR\u00038Casdsaa\u0003asdasd" +
"\u000f v7.14 has been released",
).toList()
).toList(),
)
assertEquals(
......@@ -1249,206 +1249,207 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"test^",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"._",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
" '--' ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(14)
)
foreground = IrcFormat.Color.Mirc(14),
),
),
IrcFormat.Span(
"'-.\\__/ ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(
"_",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(14)
)
foreground = IrcFormat.Color.Mirc(14),
),
),
IrcFormat.Span(
"l",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(12)
)
foreground = IrcFormat.Color.Mirc(12),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"\\",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"\\",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"||",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(13)
)
foreground = IrcFormat.Color.Mirc(13),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"/",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"test",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD), foreground = IrcFormat.Color.Mirc(4)
)
flags = setOf(IrcFormat.Flag.BOLD),
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"^",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
")",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(9)
)
foreground = IrcFormat.Color.Mirc(9),
),
),
IrcFormat.Span(
"\\",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(14)
)
foreground = IrcFormat.Color.Mirc(14),
),
),
IrcFormat.Span(
"((((",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(15)
)
foreground = IrcFormat.Color.Mirc(15),
),
),
IrcFormat.Span(
"\\",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
".",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(7)
)
foreground = IrcFormat.Color.Mirc(7),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
" :;;,,",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(8)
)
foreground = IrcFormat.Color.Mirc(8),
),
),
IrcFormat.Span(
"'-._",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
IrcFormat.Span(
"\\",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4)
)
foreground = IrcFormat.Color.Mirc(4),
),
),
IrcFormat.Span(
" ",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(1)
)
foreground = IrcFormat.Color.Mirc(1),
),
),
),
IrcFormatDeserializer.parse(
......@@ -1465,8 +1466,8 @@ class IrcFormatDeserializerTest {
"\u00031 \u00031 \u00038 :;;,,\u00034'-._\u00031 \u00031 \u00034\\\u00031 \u00031 " +
"\u00031 \u00031 \u00031 \u00031 \u00031 \u00031 \u00031 \u00031 \u00031 \u00031 " +
"\u00031 \u00031 \u00031 \u00031 \u00031 \u00031 \u00031 \u00031 \u00031 \u00031 " +
"\u00031 \u00031 \u00031"
).toList()
"\u00031 \u00031 \u00031",
).toList(),
)
}
......@@ -1477,13 +1478,13 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
"some text in 55ee22 rgb",
IrcFormat.Style(
foreground = IrcFormat.Color.Hex(0x55ee22)
)
)
foreground = IrcFormat.Color.Hex(0x55ee22),
),
),
),
IrcFormatDeserializer.parse(
"\u000455ee22some text in 55ee22 rgb\u0004"
).toList()
"\u000455ee22some text in 55ee22 rgb\u0004",
).toList(),
)
assertEquals(
......@@ -1491,13 +1492,13 @@ class IrcFormatDeserializerTest {
IrcFormat.Span(
",some text in 55ee22 rgb",
IrcFormat.Style(
foreground = IrcFormat.Color.Hex(0x55ee22)
)
)
foreground = IrcFormat.Color.Hex(0x55ee22),
),
),
),
IrcFormatDeserializer.parse(
"\u000455ee22,some text in 55ee22 rgb\u0004"
).toList()
"\u000455ee22,some text in 55ee22 rgb\u0004",
).toList(),
)
assertEquals(
......@@ -1506,13 +1507,13 @@ class IrcFormatDeserializerTest {
"some text in 55ee22 rgb on aaaaaa bg",
IrcFormat.Style(
foreground = IrcFormat.Color.Hex(0x55ee22),
background = IrcFormat.Color.Hex(0xaaaaaa)
)
)
background = IrcFormat.Color.Hex(0xaaaaaa),
),
),
),
IrcFormatDeserializer.parse(
"\u000455ee22,aaaaaasome text in 55ee22 rgb on aaaaaa bg\u0004"
).toList()
"\u000455ee22,aaaaaasome text in 55ee22 rgb on aaaaaa bg\u0004",
).toList(),
)
assertEquals(
......@@ -1521,13 +1522,13 @@ class IrcFormatDeserializerTest {
",some text in 55ee22 rgb on aaaaaa bg",
IrcFormat.Style(
foreground = IrcFormat.Color.Hex(0x55ee22),
background = IrcFormat.Color.Hex(0xaaaaaa)
)
)
background = IrcFormat.Color.Hex(0xaaaaaa),
),
),
),
IrcFormatDeserializer.parse(
"\u000455ee22,aaaaaa,some text in 55ee22 rgb on aaaaaa bg\u0004",
).toList()
).toList(),
)
assertEquals(
......@@ -1536,19 +1537,19 @@ class IrcFormatDeserializerTest {
",some text in 55ee22 rgb on aaaaaa bg",
IrcFormat.Style(
foreground = IrcFormat.Color.Hex(0x55ee22),
background = IrcFormat.Color.Hex(0xaaaaaa)
)
background = IrcFormat.Color.Hex(0xaaaaaa),
),
),
IrcFormat.Span(
" Bold",
IrcFormat.Style(
flags = setOf(IrcFormat.Flag.BOLD)
)
)
flags = setOf(IrcFormat.Flag.BOLD),
),
),
),
IrcFormatDeserializer.parse(
"\u000455ee22,aaaaaa,some text in 55ee22 rgb on aaaaaa bg\u0004\u0002 Bold\u0002",
).toList()
).toList(),
)
assertEquals(
......@@ -1557,14 +1558,14 @@ class IrcFormatDeserializerTest {
",some text in 55ee22 rgb on aaaaaa bg",
IrcFormat.Style(
foreground = IrcFormat.Color.Hex(0x55ee22),
background = IrcFormat.Color.Hex(0xaaaaaa)
)
background = IrcFormat.Color.Hex(0xaaaaaa),
),
),
IrcFormat.Span("\u0000")
IrcFormat.Span("\u0000"),
),
IrcFormatDeserializer.parse(
"\u000455ee22,aaaaaa,some text in 55ee22 rgb on aaaaaa bg\u0004\u0000",
).toList()
).toList(),
)
assertEquals(
......@@ -1573,19 +1574,19 @@ class IrcFormatDeserializerTest {
",some text in 55ee22 rgb on aaaaaa bg",
IrcFormat.Style(
foreground = IrcFormat.Color.Hex(0x55ee22),
background = IrcFormat.Color.Hex(0xaaaaaa)
)
background = IrcFormat.Color.Hex(0xaaaaaa),
),
),
IrcFormat.Span(
" Red",
IrcFormat.Style(
foreground = IrcFormat.Color.Mirc(4),
)
)
),
),
),
IrcFormatDeserializer.parse(
"\u000455ee22,aaaaaa,some text in 55ee22 rgb on aaaaaa bg\u0004\u00034 Red\u0003",
).toList()
).toList(),
)
}
}
/*
* libquassel
* Copyright (c) 2022 Janne Mareike Koschinski
* Copyright (c) 2024 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
......@@ -8,5 +8,24 @@
*/
plugins {
id("org.jlleitschuh.gradle.ktlint")
id("justjanne.kotlin")
id("justjanne.publication")
}
repositories {
google()
mavenCentral()
}
dependencies {
api(project(":libquassel-protocol"))
api(project(":libquassel-api"))
implementation(libs.dagger.core)
ksp(libs.dagger.compiler)
implementation(libs.room.runtime)
ksp(libs.room.compiler)
implementation(libs.slf4j)
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2024 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.util
package de.justjanne.libquassel.persistence
import kotlinx.coroutines.flow.MutableStateFlow
import androidx.room.Database
import androidx.room.RoomDatabase
inline fun <T> MutableStateFlow<T>.update(function: T.() -> T) {
value = function(value)
@Database(entities = [TodoEntity::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun getDao(): TodoDao
}
/*
* libquassel
* Copyright (c) 2024 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.persistence
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
@Dao
interface TodoDao {
@Insert
suspend fun insert(item: TodoEntity)
@Query("SELECT count(*) FROM TodoEntity")
suspend fun count(): Int
@Query("SELECT * FROM TodoEntity")
fun getAllAsFlow(): Flow<List<TodoEntity>>
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2024 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.models.alias
package de.justjanne.libquassel.persistence
import de.justjanne.libquassel.protocol.models.BufferInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
data class Command(
val buffer: BufferInfo,
val message: String
@Entity
data class TodoEntity(
@PrimaryKey(autoGenerate = true) val id: Long = 0,
val title: String,
val content: String
)
......@@ -13,8 +13,6 @@ plugins {
}
dependencies {
api(project(":libquassel-annotations"))
ksp(project(":libquassel-generator"))
implementation(project(":libquassel-irc"))
api(libs.threetenbp)
api(libs.kotlin.bitflags)
......
......@@ -20,5 +20,5 @@ data class ClientHeader(
/**
* Supported protocol version/meta pairs
*/
val versions: List<ProtocolMeta>
val versions: List<ProtocolMeta>,
)
......@@ -23,25 +23,23 @@ import java.nio.ByteBuffer
*/
object ClientHeaderSerializer : PrimitiveSerializer<ClientHeader> {
override val javaType: Class<out ClientHeader> = ClientHeader::class.java
private const val magic: UInt = 0x42b3_3f00u
private const val featureMask: UInt = 0x0000_00ffu
private const val lastMagic: UByte = 0x80u
private const val MAGIC: UInt = 0x42b3_3f00u
private const val FEATURE_MASK: UInt = 0x0000_00ffu
private const val LAST_MAGIC: UByte = 0x80u
private fun addMagic(data: UByte): UInt =
magic or data.toUInt()
private fun addMagic(data: UByte): UInt = MAGIC or data.toUInt()
private fun removeMagic(data: UInt): UByte =
(data and featureMask).toUByte()
private fun removeMagic(data: UInt): UByte = (data and FEATURE_MASK).toUByte()
private fun <T> writeList(
buffer: ChainedByteBuffer,
list: List<T>,
featureSet: FeatureSet,
f: (T) -> Unit
f: (T) -> Unit,
) {
for (index in list.indices) {
val isLast = index + 1 == list.size
val magic = if (isLast) lastMagic else 0x00u
val magic = if (isLast) LAST_MAGIC else 0x00u
UByteSerializer.serialize(buffer, magic, featureSet)
f(list[index])
}
......@@ -50,7 +48,7 @@ object ClientHeaderSerializer : PrimitiveSerializer<ClientHeader> {
private fun <T> readList(
buffer: ByteBuffer,
featureSet: FeatureSet,
f: () -> T
f: () -> T,
): List<T> {
val list = mutableListOf<T>()
while (true) {
......@@ -63,19 +61,28 @@ object ClientHeaderSerializer : PrimitiveSerializer<ClientHeader> {
return list
}
override fun serialize(buffer: ChainedByteBuffer, data: ClientHeader, featureSet: FeatureSet) {
override fun serialize(
buffer: ChainedByteBuffer,
data: ClientHeader,
featureSet: FeatureSet,
) {
UIntSerializer.serialize(buffer, addMagic(data.features.toBits()), featureSet)
writeList(buffer, data.versions, featureSet) {
ProtocolMetaSerializer.serialize(buffer, it, featureSet)
}
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet) = ClientHeader(
features = ProtocolFeature.of(
removeMagic(UIntSerializer.deserialize(buffer, featureSet))
),
versions = readList(buffer, featureSet) {
ProtocolMetaSerializer.deserialize(buffer, featureSet)
}
override fun deserialize(
buffer: ByteBuffer,
featureSet: FeatureSet,
) = ClientHeader(
features =
ProtocolFeature.of(
removeMagic(UIntSerializer.deserialize(buffer, featureSet)),
),
versions =
readList(buffer, featureSet) {
ProtocolMetaSerializer.deserialize(buffer, featureSet)
},
)
}
......@@ -23,13 +23,20 @@ import java.nio.ByteBuffer
object CoreHeaderSerializer : PrimitiveSerializer<CoreHeader> {
override val javaType: Class<out CoreHeader> = CoreHeader::class.java
override fun serialize(buffer: ChainedByteBuffer, data: CoreHeader, featureSet: FeatureSet) {
override fun serialize(
buffer: ChainedByteBuffer,
data: CoreHeader,
featureSet: FeatureSet,
) {
UByteSerializer.serialize(buffer, data.features.toBits(), featureSet)
ProtocolMetaSerializer.serialize(buffer, data.version, featureSet)
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet) = CoreHeader(
override fun deserialize(
buffer: ByteBuffer,
featureSet: FeatureSet,
) = CoreHeader(
ProtocolFeature.of(UByteSerializer.deserialize(buffer, featureSet)),
ProtocolMetaSerializer.deserialize(buffer, featureSet)
ProtocolMetaSerializer.deserialize(buffer, featureSet),
)
}
......@@ -23,10 +23,12 @@ enum class ProtocolFeature(
* Model representing whether TLS is supported
*/
TLS(0x01u),
/**
* Model representing whether DEFLATE compression is supported
*/
Compression(0x02u);
Compression(0x02u),
;
companion object : Flags<UByte, ProtocolFeature> {
private val values = values().associateBy(ProtocolFeature::value)
......
......@@ -20,5 +20,5 @@ data class ProtocolMeta(
/**
* Protocol metadata
*/
val data: UShort
val data: UShort,
)
......@@ -22,13 +22,20 @@ import java.nio.ByteBuffer
object ProtocolMetaSerializer : PrimitiveSerializer<ProtocolMeta> {
override val javaType: Class<out ProtocolMeta> = ProtocolMeta::class.java
override fun serialize(buffer: ChainedByteBuffer, data: ProtocolMeta, featureSet: FeatureSet) {
override fun serialize(
buffer: ChainedByteBuffer,
data: ProtocolMeta,
featureSet: FeatureSet,
) {
UShortSerializer.serialize(buffer, data.data, featureSet)
UByteSerializer.serialize(buffer, data.version.value, featureSet)
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet) = ProtocolMeta(
override fun deserialize(
buffer: ByteBuffer,
featureSet: FeatureSet,
) = ProtocolMeta(
data = UShortSerializer.deserialize(buffer, featureSet),
version = ProtocolVersion.of(UByteSerializer.deserialize(buffer, featureSet))
version = ProtocolVersion.of(UByteSerializer.deserialize(buffer, featureSet)),
)
}
......@@ -26,7 +26,8 @@ enum class ProtocolVersion(
/**
* Datastream protocol, introduced in Quassel 0.10.
*/
Datastream(0x02u);
Datastream(0x02u),
;
companion object {
private val values = values().associateBy(ProtocolVersion::value)
......@@ -34,7 +35,8 @@ enum class ProtocolVersion(
/**
* Obtain the protocol version for a protocol version id
*/
fun of(value: UByte): ProtocolVersion = values[value]
?: throw IllegalArgumentException("Protocol not supported: $value")
fun of(value: UByte): ProtocolVersion =
values[value]
?: throw IllegalArgumentException("Protocol not supported: $value")
}
}
......@@ -11,6 +11,8 @@ package de.justjanne.libquassel.protocol.exceptions
sealed class HandshakeException(message: String) : Exception(message) {
class InitException(message: String) : HandshakeException(message)
class SetupException(message: String) : HandshakeException(message)
class LoginException(message: String) : HandshakeException(message)
}
......@@ -13,21 +13,21 @@ import java.lang.Exception
sealed class RpcInvocationFailedException(message: String) : Exception(message) {
data class InvokerNotFoundException(
val className: String
val className: String,
) : RpcInvocationFailedException("Could not find invoker for $className")
data class SyncableNotFoundException(
val className: String,
val objectName: String
val objectName: String,
) : RpcInvocationFailedException("Could not find syncable $objectName for type $className")
data class UnknownMethodException(
val className: String,
val methodName: String
val methodName: String,
) : RpcInvocationFailedException("Could not find method $methodName for type $className")
data class WrongObjectTypeException(
val obj: Any?,
val type: String
val type: String,
) : RpcInvocationFailedException("Wrong type for invoker, expected $type but got $obj")
}
......@@ -17,7 +17,7 @@ import de.justjanne.bitflags.of
*/
data class FeatureSet internal constructor(
private val features: Set<QuasselFeature>,
private val additional: Set<QuasselFeatureName> = emptySet()
private val additional: Set<QuasselFeatureName> = emptySet(),
) {
/**
* Check whether a certain feature is supported
......@@ -27,14 +27,12 @@ data class FeatureSet internal constructor(
/**
* List of features with their name, for serialization
*/
fun featureList(): List<QuasselFeatureName> =
features.map(QuasselFeature::feature) + additional
fun featureList(): List<QuasselFeatureName> = features.map(QuasselFeature::feature) + additional
/**
* Set of supported [LegacyFeature]s
*/
fun legacyFeatures(): LegacyFeatures =
LegacyFeature.of(features.mapNotNull(LegacyFeature.Companion::get))
fun legacyFeatures(): LegacyFeatures = LegacyFeature.of(features.mapNotNull(LegacyFeature.Companion::get))
companion object {
/**
......@@ -43,10 +41,10 @@ data class FeatureSet internal constructor(
*/
fun build(
legacy: LegacyFeatures,
features: Collection<QuasselFeatureName>
features: Collection<QuasselFeatureName>,
) = FeatureSet(
features = parseFeatures(legacy) + parseFeatures(features),
additional = unknownFeatures(features)
additional = unknownFeatures(features),
)
/**
......@@ -69,8 +67,7 @@ data class FeatureSet internal constructor(
*/
fun none() = build()
private fun parseFeatures(features: LegacyFeatures) =
features.map(LegacyFeature::feature).toSet()
private fun parseFeatures(features: LegacyFeatures) = features.map(LegacyFeature::feature).toSet()
private fun parseFeatures(features: Collection<QuasselFeatureName>) =
features.mapNotNull(QuasselFeature.Companion::valueOf).toSet()
......