Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-log

Structured event logging for Pudu: message templates, enrichment, filtering, formatting, and sinks

0.1.0Apache-2.01

InstallClose

Padding.pudu

Pudu30 lines950 B

GitHub ↗
1/** @Log.Domain.Padding.Module — alignment padding and case formats */2module PuduLangLog.Domain.Padding34import Std.Math as Math5import PuduLangLog as Log67/// The text padded with spaces to the alignment's width, on the right for a left alignment and on8/// the left otherwise; text already as wide is unchanged.9export fn padded(text: Str, alignment: &Option[Log.Alignment]) -> Str {10  match alignment {11    case None => text12    case Some(shape) => {13      let missing = Math.max(0, shape.width - text.length())14      if shape.left {15        text + " ".repeat(missing)16      } else {17        " ".repeat(missing) + text18      }19    }20  }21}2223/// The text in upper case for format `u`, lower case for `w`, and unchanged otherwise.24export fn cased(text: Str, format: &Option[Str]) -> Str {25  match format {26    case Some(given) => if given == "u" { text.toUpper() } else if given == "w" { text.toLower() } else { text }27    case None => text28  }29}30