utils/encoding_utils library

Functions

base64Decode(String encoded) → String
Base64 decode string.
base64Encode(String text) → String
Base64 encode string.
containsMarkdown(String text) → bool
Check if text likely contains markdown syntax.
escapeDiffTokens(String text) → String
Escape diff tokens — the diff library has issues with & and $.
escapeXml(String text) → String
Escape text for XML tag content.
estimateMessageTokens(List<Map<String, dynamic>> messages) → int
Estimate tokens for a list of messages.
estimateTokens(String text) → int
Estimate token count from text. Uses the ~4 chars/token heuristic (accurate within ~15% for English).
formatBytes(int bytes) → String
Format bytes as human-readable string.
formatDuration(Duration duration) → String
Format duration as human-readable string.
parseXmlTag(String text, String tag) → String?
Parse content from an XML tag.
sanitizeFilename(String name) → String
Sanitize a filename (remove unsafe characters).
simpleHash(String text) → int
Generate a simple hash for cache keys.
truncate(String text, int maxLength, {String suffix = '...'}) → String
Truncate text to a maximum length with ellipsis.
truncateLines(String text, int maxLines, {String suffix = '\n...'}) → String
Truncate text to a maximum number of lines.
unescapeDiffTokens(String text) → String
Unescape diff tokens.
unescapeXml(String text) → String
Unescape XML entities.
xmlTag(String tag, String content, {Map<String, String>? attrs}) → String
Wrap text in an XML tag.