Skip to content

File syn_str.c

FileList > src > syntropic > util > syn_str.c

Go to the source code of this file

Zero-allocation string parsing, trimming, and tokenization utilities.

  • #include "syn_str.h"
  • #include "syn_assert.h"
  • #include <ctype.h>
  • #include <stdlib.h>
  • #include <string.h>

Public Functions

Type Name
size_t syn_str_split (char * str, char delimiter, char * tokens, size_t max_tokens)
Split a string in-place by a delimiter character into a token array.
bool syn_str_to_i32 (const char * str, int32_t * out_val)
Parse a signed 32-bit integer from a string safely.
bool syn_str_to_u32 (const char * str, uint32_t * out_val)
Parse an unsigned 32-bit integer from a string safely.
char * syn_str_trim (char * str)
Trim leading and trailing whitespace characters in-place.

Public Functions Documentation

function syn_str_split

Split a string in-place by a delimiter character into a token array.

size_t syn_str_split (
    char * str,
    char delimiter,
    char * tokens,
    size_t max_tokens
) 

Replaces occurrences of delimiter with '\0' and populates the tokens array. Zero-allocation. Modifies the input string.

Parameters:

  • str Null-terminated input string (modified in-place).
  • delimiter Character to split on (e.g. ',' or ' ').
  • tokens Array of char pointers to store token starts.
  • max_tokens Maximum capacity of tokens array.

Returns:

Number of tokens stored in tokens array.


function syn_str_to_i32

Parse a signed 32-bit integer from a string safely.

bool syn_str_to_i32 (
    const char * str,
    int32_t * out_val
) 

Parameters:

  • str Input string to parse.
  • out_val Pointer to store parsed int32_t result.

Returns:

true if successfully parsed, false on error or empty string.


function syn_str_to_u32

Parse an unsigned 32-bit integer from a string safely.

bool syn_str_to_u32 (
    const char * str,
    uint32_t * out_val
) 

Parameters:

  • str Input string to parse.
  • out_val Pointer to store parsed uint32_t result.

Returns:

true if successfully parsed, false on error or empty string.


function syn_str_trim

Trim leading and trailing whitespace characters in-place.

char * syn_str_trim (
    char * str
) 

Parameters:

  • str Null-terminated input string (modified in-place).

Returns:

Pointer to the first non-whitespace character in str.



The documentation for this class was generated from the following file src/syntropic/util/syn_str.c