EVOLUTION-MANAGER
Edit File: strtrim_ctl.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: ANSI Control Sequence Aware Version of strtrim</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for strtrim_ctl {fansi}"><tr><td>strtrim_ctl {fansi}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>ANSI Control Sequence Aware Version of strtrim</h2> <h3>Description</h3> <p>One difference with <a href="../../base/html/strtrim.html">base::strtrim</a> is that all C0 control characters such as newlines, carriage returns, etc., are treated as zero width. </p> <h3>Usage</h3> <pre> strtrim_ctl(x, width, warn = getOption("fansi.warn"), ctl = "all") strtrim2_ctl(x, width, warn = getOption("fansi.warn"), tabs.as.spaces = getOption("fansi.tabs.as.spaces"), tab.stops = getOption("fansi.tab.stops"), ctl = "all") strtrim_sgr(x, width, warn = getOption("fansi.warn")) strtrim2_sgr(x, width, warn = getOption("fansi.warn"), tabs.as.spaces = getOption("fansi.tabs.as.spaces"), tab.stops = getOption("fansi.tab.stops")) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a character vector, or an object which can be coerced to a character vector by <code><a href="../../base/html/character.html">as.character</a></code>.</p> </td></tr> <tr valign="top"><td><code>width</code></td> <td> <p>Positive integer values: recycled to the length of <code>x</code>.</p> </td></tr> <tr valign="top"><td><code>warn</code></td> <td> <p>TRUE (default) or FALSE, whether to warn when potentially problematic <em>Control Sequences</em> are encountered. These could cause the assumptions <code>fansi</code> makes about how strings are rendered on your display to be incorrect, for example by moving the cursor (see <a href="fansi.html">fansi</a>).</p> </td></tr> <tr valign="top"><td><code>ctl</code></td> <td> <p>character, which <em>Control Sequences</em> should be treated specially. See the "_ctl vs. _sgr" section for details. </p> <ul> <li><p> "nl": newlines. </p> </li> <li><p> "c0": all other "C0" control characters (i.e. 0x01-0x1f, 0x7F), except for newlines and the actual ESC (0x1B) character. </p> </li> <li><p> "sgr": ANSI CSI SGR sequences. </p> </li> <li><p> "csi": all non-SGR ANSI CSI sequences. </p> </li> <li><p> "esc": all other escape sequences. </p> </li> <li><p> "all": all of the above, except when used in combination with any of the above, in which case it means "all but". </p> </li></ul> </td></tr> <tr valign="top"><td><code>tabs.as.spaces</code></td> <td> <p>FALSE (default) or TRUE, whether to convert tabs to spaces. This can only be set to TRUE if <code>strip.spaces</code> is FALSE.</p> </td></tr> <tr valign="top"><td><code>tab.stops</code></td> <td> <p>integer(1:n) indicating position of tab stops to use when converting tabs to spaces. If there are more tabs in a line than defined tab stops the last tab stop is re-used. For the purposes of applying tab stops, each input line is considered a line and the character count begins from the beginning of the input line.</p> </td></tr> </table> <h3>Details</h3> <p><code>strtrim2_ctl</code> adds the option of converting tabs to spaces before trimming. This is the only difference between <code>strtrim_ctl</code> and <code>strtrim2_ctl</code>. </p> <h3>_ctl vs. _sgr</h3> <p>The <code>*_ctl</code> versions of the functions treat all <em>Control Sequences</em> specially by default. Special treatment is context dependent, and may include detecting them and/or computing their display/character width as zero. For the SGR subset of the ANSI CSI sequences, <code>fansi</code> will also parse, interpret, and reapply the text styles they encode if needed. You can modify whether a <em>Control Sequence</em> is treated specially with the <code>ctl</code> parameter. You can exclude a type of <em>Control Sequence</em> from special treatment by combining "all" with that type of sequence (e.g. <code>ctl=c("all", "nl")</code> for special treatment of all <em>Control Sequences</em> <strong>but</strong> newlines). The <code>*_sgr</code> versions only treat ANSI CSI SGR sequences specially, and are equivalent to the <code>*_ctl</code> versions with the <code>ctl</code> parameter set to "sgr". </p> <h3>Note</h3> <p>Non-ASCII strings are converted to and returned in UTF-8 encoding. Width calculations will not work correctly with R < 3.2.2. </p> <h3>See Also</h3> <p><a href="fansi.html">fansi</a> for details on how <em>Control Sequences</em> are interpreted, particularly if you are getting unexpected results. <a href="strwrap_ctl.html">strwrap_ctl</a> is used internally by this function. </p> <h3>Examples</h3> <pre> strtrim_ctl("\033[42mHello world\033[m", 6) </pre> <hr /><div style="text-align: center;">[Package <em>fansi</em> version 0.4.1 <a href="00Index.html">Index</a>]</div> </body></html>