notes: name the UTF-8 masks in the share-name cap so detekt passes (#913)
- Commit
6eeb9c3b1a9fb972202d6669037998e7e4e44fe1- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-12 19:31 UTC (23 days ago)
- Parents
76cb092
`./check notes` (detekt) was red on main before the #913 tags work:
aaa5da238 ("cap share filename bytes to fix ENAMETOOLONG") added
truncateUtf8Bytes with two bare literals, 0xC0 and 0x80, which detekt's
MagicNumber rule rejects outside ui/ and domain/. notes is one of the
detekt-clean reference modules and must stay green, and the tags change
(#913) cannot verify clean without this.
Fix the code, not detekt.yml: the literals become two named private
constants, UTF8_CONTINUATION_MASK (0xC0) and UTF8_CONTINUATION_BITS
(0x80), with a one-line KDoc saying what they test (a continuation
byte is 10xxxxxx). The expression is unchanged, so behaviour is
identical: the cut still backs up past continuation bytes so a long
title is never split mid-character.
User-visible effect: none.
Verification: :notes:detekt now passes in the builder container; the
existing NoteStoresTest share-name cases pass under
:notes:testDevUnitTest.Diff
notes/src/main/java/com/vayunmathur/notes/platform/NoteMarkdownExporter.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/platform/NoteMarkdownExporter.kt b/notes/src/main/java/com/vayunmathur/notes/platform/NoteMarkdownExporter.ktindex 8f12c8258a..5a3d98ffbd 100644--- a/notes/src/main/java/com/vayunmathur/notes/platform/NoteMarkdownExporter.kt+++ b/notes/src/main/java/com/vayunmathur/notes/platform/NoteMarkdownExporter.kt@@ -25,6 +25,10 @@ private const val RED_SHIFT = 16 private const val GREEN_SHIFT = 8 private const val MAX_COLOR_COMPONENT = 255f +/** A UTF-8 continuation byte is `10xxxxxx`: (b and MASK) == BITS. */+private const val UTF8_CONTINUATION_MASK = 0xC0+private const val UTF8_CONTINUATION_BITS = 0x80+ /** * Exports a note as a SINGLE self-contained Markdown document: * - text blocks are emitted verbatim,@@ -77,7 +81,7 @@ private fun truncateUtf8Bytes(s: String, maxBytes: Int): String { val bytes = s.toByteArray() if (bytes.size <= maxBytes) return s var end = maxBytes- while (end > 0 && bytes[end].toInt() and 0xC0 == 0x80) end--+ while (end > 0 && bytes[end].toInt() and UTF8_CONTINUATION_MASK == UTF8_CONTINUATION_BITS) end-- return String(bytes, 0, end, Charsets.UTF_8) }