Pack fill characters to appropriate tab characters


     TabPack( <cString>, [<nTabWidth>], [<cFillChar|nFillChar>],
             [<cNewLineCharacters>], [<cTabChar|nTabChar>],
             [<lIgnore141>] ) -> cPackedString


<cString> String to alter <nTabWidth>

<cFillChar|nFillChar> Width of tab or character to use to fill <cNewLineCharacters> string indicating new line, default is the string returned by hb_eol()

<cTabChar|nTabChar> character indicating a tab stop, default is chr(9)

<lIgnore141> .T., if the soft-CR used by MEMOEDIT() should be ignored as a newline indicator, default is .F. (functions uses chr(141))


TABPACK() returns the modified character string.


This function does not simply exchange a simple sequence of the same characters for a tab; instead, it takes into account the true tab positions. If a space (or the <cCharacter|nCharacter>) is found at a tab position, and immediately preceding it there is at least one identical character, the function replaces this sequence (maximum <nTabWidth>) with a CHR(9). With tab characters, text can be packed by individual tab widths. As with every good text editor, there is no replacement with a tab within single or double leading characters.


. For the beginning of a line, the function takes into account the “normal” carriage return (CHR(13)/CHR(10)) as well as the high bit return (CHR(141)) used by MEMOEDIT(). Previously existing tab characters are also taken into account. . If another tab already exists, this tab can be removed with TABEXPAND(). The new tab can then be inserted using TABPACK().


       We have avoided replacing spaces with tabs in the following examples to
       keep the example legible.  Tab width is 8 (default).  "*" is exchanged
       for tab characters.
       ? TABPACK("AAAAAAA*", "*")           // "AAAAAAA*"
       ? TABPACK("AAAAA***", "*")           // "AAAAA" + CHR(9)
       ? TABPACK("AAAAA*****", "*")         // "AAAAA" + CHR(9) + "**"
       crlf   :=  CHR(13) + CHR(10)
       cText  :=  "ABCD+" + crlf + "++---+++++"
       ? TABPACK(cText, 4, "+")             // "ABCD+" + crlf +
                                            // "++---" + CHR(9) + "++"


TabPack() is compatible with CT3’s TabPack(), but extended by Harbour; there are three new parameters for a better fine control of the function’s behaviour.




Source is tab.c, library is libct.



2 responses to “TabPack()

  1. Pingback: Harbour String Functions | Viva Clipper !

  2. Pingback: Harbour All Functions – T | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.