Top |
int count_fields (const char *s
,const char *sep
);
int
is_greek_letter (const char *s
);
Checks for the case where s
contains a greek letter,
followed by a nul byte or an ascii character that cannot
occur in a gretl identifier.
int
gretl_namechar_spn (const char *s
);
the length of the initial segment of s
which
consists of characters that are valid in a gretl
variable or object name, namely a-z, A-Z, 0-9 and _,
starting with a letter, up to a maximum of VNAMELEN
- 1.
char * gretl_trunc (char *str
,size_t n
);
Truncates the given str
to the specified length.
char * gretl_delete (char *str
,int idx
,int count
);
Deletes count
characters from str
, starting at position idx
.
char * gretl_unquote (char *str
,int *err
);
If str
begins with the ASCII double-quote character, checks
that the last character is also a double-quote, and in that
case trims the quotes from both ends. If the first character
is a double quote but the last is not, flags an error. If
the string is not quoted at all, returns the original
string.
char * gretl_strdup_printf (const char *format
,...
);
Print the arguments according to format
.
char * gretl_word_strdup (const char *src
,const char **ptr
,gretlopt opt
,int *err
);
Copies the first 'word' found in src
, where a word
is defined as consisting of alphanumeric characters
and the underscore. If ptr
is not NULL, on exit it
points at the next position in src
after the copied
word.
src |
the source string. |
|
ptr |
location to receive end of word pointer, or NULL. |
|
opt |
can include OPT_S for "strict" operation: in this
case an error is flagged if |
|
err |
location to receive error code. |
char * gretl_quoted_string_strdup (const char *s
,const char **ptr
);
If s
starts with a quote (double or single), return a copy of
the portion of s
that is enclosed in quotes. That is,
from s
+ 1 up to but not including the next matching quote.
If ptr
is not NULL, on output it receives a pointer to
the next byte in s
after the closing quote.
char ** gretl_string_split (const char *s
,int *n
,const char *sep
);
Parses s
into a set of zero or more substrings and
creates an array of those substrings. On sucessful exit
n
holds the number of substrings.
char ** gretl_string_split_quoted (const char *s
,int *n
,const char *sep
,int *err
);
Similar to gretl_string_split()
, except that this variant
allows for the presence of double-quoted substrings
which may contain spaces. The quotes are removed in the
members of the returned array.
char ** gretl_string_split_lines (const char *s
,int *n
);
Parses s
into a set of zero or more substrings, one per
complete line of s
, and creates an array of those substrings.
On sucessful exit n
holds the number of substrings.
char * gretl_str_expand (char **orig
,const char *add
,const char *sep
);
Creates a newly allocated string built by concatenating
orig
and add
, with sep
interpolated unless sep
is
NULL, and replaces the content of orig
with the new string.
As a special case, if orig
is NULL, or if the content of
orig
is NULL, we just duplicate add
.
char * gretl_charsub (char *str
,char find
,char repl
);
Replaces all occurrences of find
with repl
in str
.
char * gretl_substring (const char *str
,int first
,int last
,int *err
);
char *
comma_separate_numbers (char *s
);
Given a string which contains two or more numbers separated by spaces and/or commas, revise the string to ensure that all the numbers are comma-separated.
char * shift_string_left (char *str
,size_t move
);
Shifts the content of str
left by move
places, dropping
leading bytes as needed.
char *
gretl_lower (char *str
);
Converts any upper case characters in str
to lower case.
char *
gretl_strstrip (char *str
);
Removes leading and trailing white space from a string.
char * switch_ext (char *targ
,const char *src
,const char *ext
);
For processing filenames: copies src
to targ
, minus any existing
filename extension, and adds to targ
the specified extension.
char * switch_ext_in_place (char *fname
,const char *ext
);
For processing filenames: removes any existing dot-extension on
fname
and appends a dot followed by ext
.
char * switch_ext_new (const char *src
,const char *ext
);
For processing filenames: creates a copy of src
in which
any existing dot-extension is removed and ext
is appended
(with a dot automatically inserted).
int equation_get_lhs_and_rhs (const char *s
,char **plh
,char **prh
);
Given a string s
, parse it into a left-hand side and a right-hand
side, separated by an equals sign. Return in plh
and prh
allocated copies of the respective sides, with any leading or trailing
white space trimmed.
int top_n_tail (char *str
,size_t maxlen
,int *err
);
Drop leading space and trailing space and newline from string,
then replace a trailing backslash (if any) with a space.
If str
does not end with a newline within the limit set by
maxlen
, and err
is not NULL, then E_TOOLONG is written
to err
.
char *
compress_spaces (char *s
);
Reduce multiple contiguous space characters to single spaces
within s
.
char **
strings_array_new (int nstrs
);
Allocates storage for nstrs
strings and initializes all
to NULL.
char ** strings_array_realloc_with_length (char ***pS
,int oldn
,int newn
,int len
);
Adjusts the storage in pS
to a size of newn
strings, each of them len
bytes long. The first
byte of any additional strings is initialized to 0.
This function may be used either to expand or to
shrink an existing array of strings.
int strings_array_add (char ***pS
,int *n
,const char *p
);
Allocates storage for an extra member of S
and adds a
copy of string p
in the last position. On success,
the content of n
is incremented by 1.
int strings_array_donate (char ***pS
,int *n
,char *p
);
Allocates storage for an extra member of S
and adds
string p
in the last position. Unlike strings_array_add()
,
the array takes ownnership of p
rather than copying it.
On success, the content of n
is incremented by 1.
int strings_array_add_uniq (char ***pS
,int *n
,const char *p
,int *pos
);
If the array does not already include a copy of p
,
allocates storage for an extra member of pS
and adds a
copy of string p
in the last position. On successful
addition the content of n
is incremented by 1.
int strings_array_prepend_uniq (char ***pS
,int *n
,const char *p
);
If p
is already present in the array at location pS
,
moves it into first position if it is not already there.
Otherwise allocates storage for an extra member of the
array and pushes p
into first position, in which case
the content of n
is incremented by 1.
char ** strings_array_new_with_length (int nstrs
,int len
);
Allocates storage for nstrs
strings, each of them
len
bytes long. The first byte of each string is
initialized to 0.
int strings_array_sort (char ***pS
,int *n
,gretlopt opt
);
Sorts an array of strings in ascending lexicographical
order. If OPT_U
is given, n
holds the number of unique
strings on exit. It is assumed that storage for the
strings array was obtained via strings_array_new()
or
a similar libgretl function.
pS |
location of array of strings. |
|
n |
location of the number of strings in the array. |
|
opt |
may contain |
int strings_array_cmp (char **strs1
,char **strs2
,int n
);
Compares for equality two arrays of strings, each of
which must contain at least n
elements. Equality
of the arrays means that strcmp returns 0 for
each pair of strings strs1
[i], strs2
[i], for i
equals 0 to n
- 1.
int strings_array_diff (char **strs1
,int n1
,char **strs2
,int n2
,char ***extra
,int *n_extra
);
Fills out extra
with any strings present in strs2
but not in strs1
.
void strings_array_free (char **strs
,int nstrs
);
Frees each allocated string in strs
, then frees strs
itself.
Checks that strs
is not NULL before proceeding.
char * get_obs_string (char *obs
,int t
,const DATASET *dset
);
obs |
char array big enough to hold the observation (OBSLEN). |
|
t |
zero-based observation number. |
|
dset |
pointer to dataset information. |
int
gretl_xml_validate (const char *s
);
1 if s
is acceptable for insertion into an XML file
as is, 0 if it contains special characters that need to be
escaped. See also gretl_xml_encode()
.
char *
gretl_xml_encode (const char *str
);
an allocated re-write of str
, with characters that are
special in XML encoded as character entities. See also
gretl_xml_validate()
.
int gretl_xml_encode_to_buf (char *targ
,const char *src
,int n
);
Writes into targ
a version of src
in which characters that are
special in XML are encoded as character entities. See also
gretl_xml_encode()
for the case where the encoding of src
is
of unknown size at compile time.
char * make_varname_unique (char *vname
,int v
,DATASET *dset
);
Given a tentative name for a new variable, check that it
is not a duplicate of an existing varname. If it is,
modify the new name so that it becomes unique. The ID
number v
is required so that, if the variable has already
been added to the dataset, its name does not appear to
conflict with itself! If the name to be tested is not
associated with an existing variable, pass 0 for v
.
void get_column_widths (const char **strs
,int *widths
,int n
);
If need be, increases the column widths in widths
to
accomodate the current translations of strs
.
char * gretl_utf8_strncat (char *dest
,const char *src
,size_t n
);
Works just like strncat()
, except that it ensures that we
don't end up with an incomplete UTF-8 character preceding
the terminating NUL byte.
char * gretl_utf8_strncat_trim (char *dest
,const char *src
,size_t n
);
The same as gretl_utf8_strncat()
, except that any leading and/or
trailing white space is trimmed from dest
.
char * gretl_utf8_truncate (char *s
,size_t nmax
);
Truncates s
to a maximum length of nmax
UTF-8 characters,
ensuring that we don't end up with an incomplete UTF-8
character preceding the terminating NUL byte.
char * gretl_utf8_truncate_b (char *s
,size_t bmax
);
Truncates s
to a maximum length of bmax
bytes,
ensuring that we don't end up with an incomplete UTF-8
character preceding the terminating NUL byte.
char * gretl_utf8_replace_char (char *targ
,char *src
,int pos
);
Notes: pos
must be prechecked as within bounds, and
src
must be prechecked for containing a single character.
char * gretl_utf8_select (const char *s
,const int *list
);
Constructs a string composed of the selected characters from s
,
which do not have to be contiguous or in order.
int gretl_scan_varname (const char *src
,char *targ
);
Performs sscanf()
on src
, using a conversion specifier
which allows for writing up to VNAMELEN-1 bytes into
targ
(stopping at white space); targ
therefore be at
least VNAMELEN bytes long. No checking is done for the
validity of the scanned string as a gretl identifier.
int gretl_normalize_varname (char *targ
,const char *src
,int underscore
,int seq
);
Writes a valid gretl identifier to targ
, which must be
at least VNAMELEN bytes in length, taking src
as basis
and replacing any illegal characters as described in the
documentation for the userland fixname function.
char * gretl_regexp_replace (const char *orig
,const char *match
,const char *repl
,int *err
);
Builds a string based on orig
but in which all
occurrences of match
(which is interpreted as a
regular expression of the Perl type) are replaced
by means of repl
(also interpreted as a regular
expression).
char * gretl_literal_replace (const char *orig
,const char *match
,const char *repl
,int *err
);
Builds a string based on orig
but in which all
occurrences of match
(which is interpreted as a
straight string literal) are replaced by repl
(also
a straight string literal).