offbrand
A collection of generic, reference counted datastructures in C for C
 All Classes Files Functions Variables Typedefs Macros Groups
Typedefs | Functions
obstring.h File Reference

obstring Public Interface More...

#include "offbrand.h"
#include "obvector.h"
#include <regex.h>

Go to the source code of this file.

Typedefs

typedef struct obstring_struct obstring
 

Functions

obstringobstring_new (const char *str)
 Creates a new obstring with the string of characters. More...
 
obstringobstring_copy_substring (const obstring *s, int64_t start, uint32_t length)
 Copies a sequence of characters from an obstring to create a new instance of obstring. More...
 
uint32_t obstring_length (const obstring *s)
 Gets the length of an obstring. More...
 
char obstring_char_at_index (const obstring *s, int64_t i)
 returns the character at the specified index More...
 
obstringobstring_concat (const obstring *s1, const obstring *s2)
 concatenates the two obstring instances into a new instance of obstring More...
 
const char * obstring_cstring (const obstring *s)
 Gets the C string representation of an obstring instance. More...
 
obvectorobstring_split (const obstring *s, const char *delim)
 Tokenizes an obstring over a character sequence. More...
 
uint8_t obstring_find_substring (const obstring *s, const char *to_find)
 Searches for an substring in an obstring. More...
 
obstringobstring_match_regex (const obstring *s, const char *regex)
 Finds the pattern matching an expression in an obstring. More...
 

Detailed Description

obstring Public Interface

Author
theck

Typedef Documentation

typedef struct obstring_struct obstring

Class type declaration

Function Documentation

char obstring_char_at_index ( const obstring s,
int64_t  i 
)

returns the character at the specified index

Parameters
sA pointer to an instance of obstring
iAn integer denoting a characters position in the string. Negative integers are accepted, with -1 indicating the final non-NUL character in the string
Returns
The character at the index within the string, '\0' if the character is out of bounds
obstring* obstring_concat ( const obstring s1,
const obstring s2 
)

concatenates the two obstring instances into a new instance of obstring

Parameters
s1A pointer to an instance of obstring
s2A pointer to an instance of obstring
Returns
A pointer to an new instance of obstring that contains string s1+s2
obstring* obstring_copy_substring ( const obstring s,
int64_t  start,
uint32_t  length 
)

Copies a sequence of characters from an obstring to create a new instance of obstring.

Parameters
sA pointer to an instance of obstring
startAn integer denoting the position of the start of the sequence to copy within the string, character at position start included. Negative integers are accepted, with -1 indicating the final non-NUL character in the string
lengthAn integer denoting the length of the string to be copied
Returns
An instance of obstring containing the seqence of characters selected from the provided obstring
Warning
If start and length combine to specify a range beyond the string bounds then any extension beyond the bounds will return only existing characters in the range, an empty string if none exist
const char* obstring_cstring ( const obstring s)

Gets the C string representation of an obstring instance.

Parameters
sA pointer to an instance of obstring
Returns
A C string containing the same sequence of characters as the obstring instance
Warning
The returned pointer is directed at an internal C string that should not be altered, a new obstring should be created if an alteration is desired
uint8_t obstring_find_substring ( const obstring s,
const char *  to_find 
)

Searches for an substring in an obstring.

Parameters
sA pointer to an instance of obstring to be searched
to_findA NUL terminated C string containing the sequence of characters to find
Return values
0The substring was not found in the search string
non-zeroThe substring was found in the search string
Warning
Function does not attempt to verify that delim is in fact NUL terminated
uint32_t obstring_length ( const obstring s)

Gets the length of an obstring.

Parameters
sA pointer to an instance of obstring
Returns
Integer length of the obstring instance
obstring* obstring_match_regex ( const obstring s,
const char *  regex 
)

Finds the pattern matching an expression in an obstring.

Parameters
sA pointer to and instance of obstring to be searched
regexA pointer to an instance of obstring containing the expression to attempt to match
Returns
An obstring containing the first matching sequence in the obstring

The POSIX Extended Regular Expression syntax is used to interpret the provided expression

Warning
Function does not attempt to verify that delim is in fact NUL terminated
obstring* obstring_new ( const char *  str)

Creates a new obstring with the string of characters.

Parameters
strA NUL terminated C string
Returns
An instance of obstring encapsulating the given C string

The provided C string is not stored directly in an instance of obstring and so can be modified and free'd without affecting the created obstring.

Warning
Constructor assumes that the input string NUL terminated with finite length, any C strings passed to the constructor should be known to meet these constraints
obvector* obstring_split ( const obstring s,
const char *  delim 
)

Tokenizes an obstring over a character sequence.

Parameters
sA pointer to an instance of obstring to be tokenized
delimA NUL terminated C string indicating the character or sequence of characters on which to break a string
Returns
An obvector containing the resulting obstrings derived from splitting the original on the delimeter string

A multicharacter obstring will not cause the the original string to be split on each character, but rather the original string will be split on complete instances of delim.

Warning
Function does not attempt to verify that delim is in fact NUL terminated