SplitString

Defines a string which can store two substrings.  Used for scanning noncontiguous (double) buffers.

Summary
SplitStringDefines a string which can store two substrings.
CopyrightThis program is free software.
Files
C-kern/api/string/splitstring.hHeader file SplitString.
C-kern/string/splitstring.cImplementation file SplitString impl.
Types
struct splitstring_tExport splitstring_t into global namespace.
Functions
test
unittest_string_splitstringTest splitstring_t functionality.
splitstring_tStores two contiguous sub strings.
stringpartThe array of noncontinuous parts the string is composed of.
nrofpartsThe number of noncontinuous parts the string is composed of.
lifetime
splitstring_FREEStatic initializer.
free_splitstringSets all data members to 0.
query
isfree_splitstringReturns true if spstr equals splitstring_FREE.
nrofparts_splitstringReturns the nr of parts the string is composed of.
addr_splitstringReturns the start address of a part of the string at index stridx.
size_splitstringReturns size of a part of the string at index stridx.
setter
setnrofparts_splitstringSets the nr of parts the string is composed of.
setstring_splitstringSets the stringaddr and stringsize of a part of the string at index stridx.
setsize_splitstringChanges the size of the a part of the string at index stridx.
inline implementation
Functions
free_splitstringImplements splitstring_t.free_splitstring.
addr_splitstringImplements splitstring_t.addr_splitstring.
size_splitstringImplements splitstring_t.size_splitstring.
nrofparts_splitstringImplements splitstring_t.nrofparts_splitstring.
setnrofparts_splitstringImplements splitstring_t.setnrofparts_splitstring.
setstring_splitstringImplements splitstring_t.setstring_splitstring.
setsize_splitstringImplements <splitstring_t.setfirstsize_splitstring>.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2013 Jörg Seebohn

Files

C-kern/api/string/splitstring.h

Header file SplitString.

C-kern/string/splitstring.c

Implementation file SplitString impl.

Types

struct splitstring_t

typedef struct splitstring_t splitstring_t

Export splitstring_t into global namespace.

Functions

test

unittest_string_splitstring

int unittest_string_splitstring(void)

Test splitstring_t functionality.

splitstring_t

struct splitstring_t

Stores two contiguous sub strings.  The first string (at index 0) stores the first part of the combined non-contiguous string and the last string (at index 1) stores the last part of the non-contiguous string.

Summary
stringpartThe array of noncontinuous parts the string is composed of.
nrofpartsThe number of noncontinuous parts the string is composed of.
lifetime
splitstring_FREEStatic initializer.
free_splitstringSets all data members to 0.
query
isfree_splitstringReturns true if spstr equals splitstring_FREE.
nrofparts_splitstringReturns the nr of parts the string is composed of.
addr_splitstringReturns the start address of a part of the string at index stridx.
size_splitstringReturns size of a part of the string at index stridx.
setter
setnrofparts_splitstringSets the nr of parts the string is composed of.
setstring_splitstringSets the stringaddr and stringsize of a part of the string at index stridx.
setsize_splitstringChanges the size of the a part of the string at index stridx.

stringpart

string_t stringpart[2]

The array of noncontinuous parts the string is composed of.  The maximum number of strings is 2.

nrofparts

uint8_t nrofparts

The number of noncontinuous parts the string is composed of.  The maximum supported value is 2.  See also array stringpart.

lifetime

splitstring_FREE

#define splitstring_FREE { { string_FREE, string_FREE }, 0 }

Static initializer.

free_splitstring

void free_splitstring(splitstring_t *spstr)

Sets all data members to 0.

query

isfree_splitstring

bool isfree_splitstring(const splitstring_t *spstr)

Returns true if spstr equals splitstring_FREE.

nrofparts_splitstring

uint8_t nrofparts_splitstring(const splitstring_t *spstr)

Returns the nr of parts the string is composed of.

Returns

0No part is valid and therefore the empty string.
1Only the first part is valid.
2The first and the last part are valid.

addr_splitstring

const uint8_t * addr_splitstring(const splitstring_t *spstr,
uint8_t stridx)

Returns the start address of a part of the string at index stridx.  The returned value is only valid if nrofparts_splitstring is > stridx.

size_splitstring

size_t size_splitstring(const splitstring_t *spstr,
uint8_t stridx)

Returns size of a part of the string at index stridx.  The returned value is only valid if nrofparts_splitstring is > stridx.

setter

setnrofparts_splitstring

void setnrofparts_splitstring(splitstring_t *spstr,
uint8_t number_of_parts)

Sets the nr of parts the string is composed of.  Use the value 0 if the string is empty.  Use the value 1 if only the first part is valid.  Use value 2 if the first and last part are valid.  A value > 2 is wrong and results in undefined behaviour.

setstring_splitstring

void setstring_splitstring(splitstring_t *spstr,
uint8_t stridx,
size_t stringsize,
const uint8_t stringaddr[stringsize])

Sets the stringaddr and stringsize of a part of the string at index stridx.  The behaviour is undefined if stridx > 2.

setsize_splitstring

void setsize_splitstring(splitstring_t *spstr,
uint8_t stridx,
size_t stringsize)

Changes the size of the a part of the string at index stridx.  The behaviour is undefined if stridx > 2.

Functions

free_splitstring

addr_splitstring

size_splitstring

nrofparts_splitstring

setnrofparts_splitstring

setstring_splitstring

setsize_splitstring

Implements <splitstring_t.setfirstsize_splitstring>.

Defines a string which can store two substrings.
Implements SplitString.
typedef struct splitstring_t splitstring_t
Export splitstring_t into global namespace.
struct splitstring_t
Stores two contiguous sub strings.
int unittest_string_splitstring(void)
Test splitstring_t functionality.
string_t stringpart[2]
The array of noncontinuous parts the string is composed of.
uint8_t nrofparts
The number of noncontinuous parts the string is composed of.
#define splitstring_FREE { { string_FREE, string_FREE }, 0 }
Static initializer.
void free_splitstring(splitstring_t *spstr)
Sets all data members to 0.
bool isfree_splitstring(const splitstring_t *spstr)
Returns true if spstr equals splitstring_FREE.
uint8_t nrofparts_splitstring(const splitstring_t *spstr)
Returns the nr of parts the string is composed of.
const uint8_t * addr_splitstring(const splitstring_t *spstr,
uint8_t stridx)
Returns the start address of a part of the string at index stridx.
size_t size_splitstring(const splitstring_t *spstr,
uint8_t stridx)
Returns size of a part of the string at index stridx.
void setnrofparts_splitstring(splitstring_t *spstr,
uint8_t number_of_parts)
Sets the nr of parts the string is composed of.
void setstring_splitstring(splitstring_t *spstr,
uint8_t stridx,
size_t stringsize,
const uint8_t stringaddr[stringsize])
Sets the stringaddr and stringsize of a part of the string at index stridx.
void setsize_splitstring(splitstring_t *spstr,
uint8_t stridx,
size_t stringsize)
Changes the size of the a part of the string at index stridx.
Close