Function in text coil-stdlib

pad_right

fn pad_right(string s, int width, string fill) -> Result<string, string>
Import
use text::{pad_right};
Source: src/text.hy

Returns s with fill added at the end until it is width bytes long. fill should be one byte; longer text is returned unchanged.

Parameters#

NameType
sstring
widthint
fillstring

Returns#

Result<string, string>

Contracts#

Checked according to --contracts (see Contracts).

ensures fill.len() != 1 || ok_len(result) == max_int(width, s.len())
ensures fill.len() == 1 || ok_len(result) == -1

Examples#

use text::{pad_right};
use tests::assert;
assert!((pad_right("ab", 4, ".") ?? "") == "ab..");

See also#

  • byte_len: Returns the length of s in bytes; the same as s.len().
  • slice: Returns the part of s from byte offset start up to (not including) end.
  • trim_start: Returns s without leading ASCII whitespace (space, tab, CR, LF).
  • trim_end: Returns s without trailing ASCII whitespace (space, tab, CR, LF).
  • trim: Returns s without leading and trailing ASCII whitespace (space, tab, CR, LF).
  • rfind: Returns the byte offset of the last needle in hay, or -1.
  • split_at: Splits s at byte offset at into the part before and the part from at on.
  • join: Returns the parts concatenated with sep between each pair.
↑ ↓ navigate ↵ open