Skip to content

Commit

Permalink
Nim: add UTF-16 and UTF-32 support to type: strz
Browse files Browse the repository at this point in the history
See kaitai-io/kaitai_struct#187

The new methods used in this commit have been implemented in
kaitai-io/kaitai_struct_nim_runtime@f42f323
  • Loading branch information
generalmimon committed Aug 7, 2024
1 parent 7b1bd69 commit 9fb3a2f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,12 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}
val expr2 = terminator match {
case Some(term) =>
val t = term.head & 0xff
s"$expr1.bytesTerminate($t, $include)"
if (term.length == 1) {
val t = term.head & 0xff
s"$expr1.bytesTerminate($t, $include)"
} else {
s"$expr1.bytesTerminateMulti(${translator.doByteArrayLiteral(term)}, $include)"
}
case None => expr1
}
expr2
Expand Down Expand Up @@ -396,8 +400,12 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
case _: BytesEosType =>
s"$io.readBytesFull()"
case BytesTerminatedType(terminator, include, consume, eosError, _) =>
val term = terminator.head & 0xff
s"$io.readBytesTerm($term, $include, $consume, $eosError)"
if (terminator.length == 1) {
val term = terminator.head & 0xff
s"$io.readBytesTerm($term, $include, $consume, $eosError)"
} else {
s"$io.readBytesTermMulti(${translator.doByteArrayLiteral(terminator)}, $include, $consume, $eosError)"
}
case BitsType1(bitEndian) =>
s"$io.readBitsInt${camelCase(bitEndian.toSuffix, true)}(1) != 0"
case BitsType(width: Int, bitEndian) =>
Expand Down

0 comments on commit 9fb3a2f

Please sign in to comment.