From d8226bf658e84fba7a3bd150dd21d221819a5ae3 Mon Sep 17 00:00:00 2001 From: snapdgn Date: Mon, 12 Sep 2022 18:35:30 +0530 Subject: [PATCH] add: documentation to refactored macros->functions --- src/uu/stat/src/stat.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 883bf66d2..ed1cba694 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -26,6 +26,8 @@ use std::os::unix::prelude::OsStrExt; use std::path::Path; use std::{cmp, fs, iter}; +/// checks if the string is within the specified bound +/// fn check_bound(slice: &str, bound: usize, beg: usize, end: usize) -> UResult<()> { if end >= bound { return Err(USimpleError::new( @@ -36,6 +38,9 @@ fn check_bound(slice: &str, bound: usize, beg: usize, end: usize) -> UResult<()> Ok(()) } +/// pads the string with zeroes if supplied min is greater +/// then the length of the string, else returns the original string +/// fn extend_digits(string: &str, min: usize) -> Cow<'_, str> { if min > string.len() { let mut pad = String::with_capacity(min); @@ -55,6 +60,16 @@ enum Padding { Space, } +/// pads the string with zeroes or spaces and prints it +/// +/// # Example +/// ```ignore +/// uu_stat::pad_and_print("1", false, 5, Padding::Zero) == "00001"; +/// ``` +/// currently only supports '0' & ' ' as the padding character +/// because the format specification of print! does not support general +/// fill characters +/// fn pad_and_print(result: &str, left: bool, width: usize, padding: Padding) { match (left, padding) { (false, Padding::Zero) => print!("{result:0>width$}"), @@ -64,6 +79,8 @@ fn pad_and_print(result: &str, left: bool, width: usize, padding: Padding) { }; } +/// prints the adjusted string after padding +/// fn print_adjusted( s: &str, left: bool,