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
  • api-redesign
  • main
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.7.0
  • 0.8.0
  • 0.8.1
  • 0.9.0
  • 0.9.1
  • 0.9.2
11 results

Target

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