Skip to content

Commit

Permalink
HtmlGenerator.kt: Don't use Kim internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanOltmann committed May 4, 2024
1 parent 839a2f7 commit 19dbc28
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/src/commonMain/kotlin/HtmlGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
*/

import com.ashampoo.kim.common.MetadataType
import com.ashampoo.kim.common.slice
import com.ashampoo.kim.common.toFourCCTypeString
import com.ashampoo.kim.common.toHex
import com.ashampoo.kim.common.toUInt8
import com.ashampoo.kim.format.ImageMetadata
import com.ashampoo.kim.format.bmff.BoxReader
import com.ashampoo.kim.format.bmff.BoxType
Expand Down Expand Up @@ -1163,6 +1160,7 @@ private fun completeSlices(
return completedSlices
}

@OptIn(ExperimentalStdlibApi::class)
private fun generateHtmlFromSlices(
bytes: ByteArray,
slices: List<LabeledSlice>
Expand Down Expand Up @@ -1204,9 +1202,9 @@ private fun generateHtmlFromSlices(

/* Emphasis on the marker bytes. */
if (firstLineOfSegment && bytesOfLine.size <= slice.emphasisOnFirstBytes)
append("<b>" + byte.toHex().uppercase() + "</b>$SPACE")
append("<b>" + byte.toHexString(HexFormat.UpperCase) + "</b>$SPACE")
else
append(byte.toHex().uppercase() + SPACE)
append(byte.toHexString(HexFormat.UpperCase) + SPACE)

/* Extra spacing in the middle to have two pairs of 8 bytes. */
if (bytesOfLine.size == BYTES_PER_ROW / 2)
Expand Down Expand Up @@ -1331,6 +1329,13 @@ fun String.escapeHtmlSpecialChars(): String =
private fun String.escapeSpaces(): String =
this.replace(" ", SPACE)

private fun Byte.toUInt8(): Int = 0xFF and toInt()

fun ByteArray.slice(startIndex: Int, count: Int): ByteArray {
val endIndex = (startIndex + count).coerceAtMost(size)
return sliceArray(startIndex until endIndex)
}

@Suppress("MagicNumber")
private fun decodeBytesForHexView(bytes: List<Byte>): String =
buildString {
Expand Down

0 comments on commit 19dbc28

Please sign in to comment.