Description Usage Arguments Details Value
Implements variants of strlcpy
, strnlen
, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
str |
character string to measure or manipulate, should be scalar for
|
maxlen |
integer(1L) size limit to truncate to, or to limit tokens to |
format |
character(1L) string to use as format template |
a |
character(1L) another string |
b |
character(1L) another string |
bullet |
character(1L) a string to use as the bullet symbol |
ctd |
character(1L) a string preferably the same number of characters as
|
sep |
character(1L) a separator to use when collapsing character vectors
with |
These functions are intended to be used directly from C but are exposed here for testing purposes. They differ from similar existing versions in these respects:
Input strings are never modified; if changes are required to comply
with length limits a copy that is R_alloc
ed is returned
Only C99 code is used
Function specific details follow. Pay attention, the interfaces are not
exactly the same as the C
functions they intend to replace. For
example smprintf
does not have a str
parameter like
snprintf
, and strmcpy
returns a new character string instead of
modifying one passed as an argument.).
strmlen
: roughly equivalent to POSIX strnlen
, but
should be fully portable
strmcpy
: if strmlen(str)
is greater than maxlen
,
returns a copy of str
with '\0'
as the maxlen + 1
th
character (note return character array is not allocated beyond this NULL),
otherwise returns a copy of str
.
smprintf2
: returns a newly R_alloc
ed string that is just
large enough to fit the combination of the format string and the tokens
to sub in (note that tokens must be character so only "
as a formatting element). To achieve this without overflow, ensures that
format
and each token is limited to maxlen - 1
characters.
Fails if result string is longer than a size_t
could index. Note
that internally we define smprintf1
- smprintf6
, but we are
only exporting the one function directly to R for testing.
strbullet
ads a bullet at front of string and padding after
each new line
collapse
is essentially the same as paste0(x,
collapse=sep
integer(1L) for strmlen
, character(1L) for strmcpy
and smprintf2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.