Skip to content

Commit

Permalink
Perl: 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_perl_runtime@66262b7
  • Loading branch information
generalmimon committed Aug 7, 2024
1 parent d25a689 commit 7b1bd69
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,12 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
case _: BytesEosType =>
s"$io->read_bytes_full()"
case BytesTerminatedType(terminator, include, consume, eosError, _) =>
val term = terminator.head & 0xff
s"$io->read_bytes_term($term, ${boolLiteral(include)}, ${boolLiteral(consume)}, ${boolLiteral(eosError)})"
if (terminator.length == 1) {
val term = terminator.head & 0xff
s"$io->read_bytes_term($term, ${boolLiteral(include)}, ${boolLiteral(consume)}, ${boolLiteral(eosError)})"
} else {
s"$io->read_bytes_term_multi(${translator.doByteArrayLiteral(terminator)}, ${boolLiteral(include)}, ${boolLiteral(consume)}, ${boolLiteral(eosError)})"
}
case BitsType1(bitEndian) =>
s"$io->read_bits_int_${bitEndian.toSuffix}(1)"
case BitsType(width: Int, bitEndian) =>
Expand Down Expand Up @@ -328,8 +332,12 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}
val expr2 = terminator match {
case Some(term) =>
val t = term.head & 0xff
s"$kstreamName::bytes_terminate($expr1, $t, ${boolLiteral(include)})"
if (term.length == 1) {
val t = term.head & 0xff
s"$kstreamName::bytes_terminate($expr1, $t, ${boolLiteral(include)})"
} else {
s"$kstreamName::bytes_terminate_multi($expr1, ${translator.doByteArrayLiteral(term)}, ${boolLiteral(include)})"
}
case None => expr1
}
expr2
Expand Down

0 comments on commit 7b1bd69

Please sign in to comment.