C API

stringop.c File Reference


Detailed Description

Author:
Andrea Vedaldi

Definition in file stringop.c.

#include "stringop.h"
#include <string.h>
#include <ctype.h>

Go to the source code of this file.


Functions

VL_EXPORT char * vl_string_parse_protocol (char const *str, int *prot)
 Parse string prefix for file protocol.
VL_EXPORT char const * vl_string_protocol_name (int prot)
 Get protocol name.
VL_EXPORT int vl_string_basename (char *dst, int n, char const *src, int n_ext)
 Extract base of file name.
VL_EXPORT int vl_string_replace_wildcard (char *dst, int n, char const *src, char wild, char esc, char const *repl)
 Replace wildcard by string.
VL_EXPORT int vl_string_copy (char *dst, int n, char const *src)
 Copy string.
VL_EXPORT int vl_string_copy_sub (char *dst, int n, char const *beg, char const *end)
 Copy substring.
VL_EXPORT char * vl_string_find_char_rev (char const *beg, char const *end, char c)
 Search character in reversed order.
VL_EXPORT int vl_string_length (char const *str)
 Calculate string length.
VL_EXPORT int vl_string_casei_cmp (const char *s1, const char *s2)
 Compare strings case-insensitive.

Function Documentation

VL_EXPORT int vl_string_basename ( char *  dst,
int  n,
char const *  src,
int  n_ext 
)

Parameters:
dst destination buffer.
n size of destination buffer.
src string to process.
n_ext maximum number of extensions to strip.
The function removes leading path and (at most) n_ext trailing extensions from the string src and writes the result to the buffer dst of length n.

The leading path is the suffix that ends with the last occurrence of the `\' or `/' characters. A trailing extension is the shortest suffix starting with the `.' character.

Returns:
length of the result.
See also:
vl-stringop-err.

Definition at line 145 of file stringop.c.

References vl_string_copy_sub().

VL_EXPORT int vl_string_casei_cmp ( const char *  s1,
const char *  s2 
)

Parameters:
s1 fisrt string.
s2 second string.
Returns:
0 if the strings are equal, >0 if the first string is greater (in lexicographical order) and <0 otherwise.

Definition at line 356 of file stringop.c.

VL_EXPORT int vl_string_copy ( char *  dst,
int  n,
char const *  src 
)

Parameters:
dst output buffer.
n size of output buffer.
src string to copy.
The function copies the string src to the buffer dst of size n.

Returns:
length of src.
See also:
vl-stringop-err.

Definition at line 251 of file stringop.c.

References VL_MIN.

VL_EXPORT int vl_string_copy_sub ( char *  dst,
int  n,
char const *  beg,
char const *  end 
)

Parameters:
dst output buffer.
n size of output buffer.
beg start of the source string.
end end of the source string.
The function copies the substring from at beg to end to the buffer dst of size n. The substring terminates when either a NUL is found or end is reached (the character pointed by end is not included).

Returns:
length of the result.
See also:
vl-stringop-err.

Definition at line 286 of file stringop.c.

References VL_MIN.

Referenced by vl_string_basename().

VL_EXPORT char* vl_string_find_char_rev ( char const *  beg,
char const *  end,
char  c 
)

Parameters:
beg substring beginning.
end substring ending.
c character to search for.
The function searches for the last occurrence of the character c in the substring from beg to end (the latter not being included).

Returns:
pointer to last occurrence of c, or 0 if none.

Definition at line 318 of file stringop.c.

VL_EXPORT int vl_string_length ( char const *  str  ) 

Parameters:
str string.
Returns:
string length.

Definition at line 337 of file stringop.c.

VL_EXPORT char* vl_string_parse_protocol ( char const *  str,
int *  prot 
)

Parameters:
str string.
prot protocol code (output).
The function extracts the prefix of the string str terminated by the first occurrence of the `:' character (if any). It then matches the suffix to the supported protocols. The corresponding protocol code is wrote to prot.

Returns:
A pointer to the first character after the protocol prefix. The function writes to prot the value VL_PROT_NONE if no suffix is detected and VL_PROT_UNKNOWN if there is a suffix but it cannot be recognized.

Definition at line 63 of file stringop.c.

References VL_PROT_ASCII, VL_PROT_BINARY, VL_PROT_NONE, and VL_PROT_UNKNOWN.

VL_EXPORT char const* vl_string_protocol_name ( int  prot  ) 

Parameters:
prot protocol id.
The function returns a pointer to the symbolic name of the protocol prot (see the vl-file-protocols "protocols" list).

Returns:
pointer to the protocol name. The function returns a null pointer if the protocol code is unknown.

Definition at line 108 of file stringop.c.

References VL_PROT_ASCII, VL_PROT_BINARY, and VL_PROT_NONE.

VL_EXPORT int vl_string_replace_wildcard ( char *  dst,
int  n,
char const *  src,
char  wild,
char  esc,
char const *  repl 
)

Parameters:
dst output buffer.
n size of output buffer.
src input string.
wild widcard character.
esc escape character.
repl replacement string.
The function replaces the occurrence of the specified wildcard character wild by the string repl. The result is written to the buffer dst of size n.

Wildcard characters may be escaped by preceding them by the esc character. More in general, anything following an occurrence of esc character is copied verbatim. To disable the escape characters simply set esc to 0.

Returns:
length of the result.
See also:
Detecting overflow.

Definition at line 195 of file stringop.c.

References VL_MIN.