<RefEntry id="pad-string">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename pad-string.html>

<RefMeta>
  <RefEntryTitle>pad-string</RefEntryTitle>
  <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>

<RefNameDiv>
  <RefName>pad-string</RefName>
  <RefPurpose>Pads a string, in front, to the specified length</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(pad-string string length padchar)
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Returns <literal>string</literal>, padded in front with <literal>padchar</literal> to at least <literal>length</literal>
Returns <literal>string</literal> unmodified if <literal>string</literal> is not a <literal>(string?)</literal>,
<literal>padchar</literal> is not a <literal>(string?)</literal>, <literal>padchar</literal> is the empty string, or if
<literal>string</literal> is already greater than or equal to <literal>length</literal> in length.
</para>
<variablelist>
<varlistentry><term><literal>string</literal></term>
<listitem>
<para>
The string to pad.
</para>
</listitem>
</varlistentry>
<varlistentry><term><literal>length</literal></term>
<listitem>
<para>
The desired length.
</para>
</listitem>
</varlistentry>
<varlistentry><term><literal>padchar</literal></term>
<listitem>
<para>
The character (string, actually) to use as padding.  If <literal>padchar</literal> is
longer than 1 character, the resulting string may be longer than
<literal>length</literal> when returned.
</para>
</listitem>
</varlistentry>
</variablelist>

</RefSect1>

<RefSect1><Title>Author</Title>

<para>
Norman Walsh, &lt;ndw@nwalsh.com&gt;
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>

<ProgramListing>
(define (pad-string string length padchar)
  ;; Pads a string, in front, to the specified length
  (if (and (string? string) 
	   (string? padchar) 
	   (> (string-length padchar) 0))
      (let loop ((s string) (count (- length (string-length string))))
	(if (<= count 0)
	    s
	    (loop (string-append padchar s) 
		  (- count (string-length padchar)))))
      string))
</ProgramListing>
</RefSect1>

</RefEntry>
