FrostWing
A lightweight raw-control operating system.
Loading...
Searching...
No Matches
strings.h File Reference

The header file for strings.c. More...

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <basics.h>
Include dependency graph for strings.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_WORDS   30
#define MAX_WORD_LEN   40
#define CONCAT(...)

Functions

int strlen (char s[])
 Calculate the length of a null-terminated string.
string strcpy (string dest, cstring src)
 Copies a string from src to dest.
string strncpy (string dest, cstring src, size_t n)
 Copies n characters from src to dest.
int strcmp (cstring s1, cstring s2)
 Compares two strings lexicographically.
int strncmp (cstring s1, cstring s2, size_t n)
 Compares two strings, up to a specified number of characters.
bool contains (cstring str, cstring substr)
 Check if a substring is found within a string.
void string_transport_front (char *str, int x)
 Move the last x characters of a string to the front and delete the rest.
string trim (cstring str)
 Creates a new string without spaces from a C-style string.
string strcat (string dest, cstring src)
 Concatenate two strings.
void remove_last_char (string str)
 Removes the last char.
long strtol (const char *str, char **endptr, int base)
 Converts a string to a long integer.
char * uint_to_string (unsigned int num)
 Converts an uint to string.
char * hex_to_string (signed int num, bool caps)
 Prints Hexadecimal number.
char * leading_trailing_trim (const char *str)
 Removes the leading and trailing spaces.
char ** splitf (const char *str, char delim, int *num_tokens)
 Splits a string into tokens based on a delimiter.
int isspace (char c)
 Implemented for sh.c.
char * trim_inplace (char *s)
char * strrchr (const char *s, int c)

Detailed Description

The header file for strings.c.

Author
Pradosh (prado.nosp@m.shga.nosp@m.me@gm.nosp@m.ail..nosp@m.com)
Version
0.1
Date
2023-10-21

Definition in file strings.h.

Macro Definition Documentation

◆ CONCAT

#define CONCAT ( ...)
Value:
str_concat_impl(sizeof((const char*[]){__VA_ARGS__}) / sizeof(const char*), __VA_ARGS__)

Definition at line 19 of file strings.h.

◆ MAX_WORD_LEN

#define MAX_WORD_LEN   40

Definition at line 17 of file strings.h.

◆ MAX_WORDS

#define MAX_WORDS   30

Definition at line 16 of file strings.h.

Function Documentation

◆ contains()

bool contains ( cstring str,
cstring substr )

Check if a substring is found within a string.

This function searches for the presence of a substring within a given string.

Parameters
strThe string to search within.
substrThe substring to search for.
Returns
true if the substring is found in the string, false otherwise.

◆ hex_to_string()

char * hex_to_string ( signed int num,
bool caps )

Prints Hexadecimal number.

Parameters
hexthe hexadecimal number to be printed.

◆ isspace()

int isspace ( char c)

Implemented for sh.c.

Parameters
c
Returns
int

◆ leading_trailing_trim()

char * leading_trailing_trim ( const char * str)

Removes the leading and trailing spaces.

Parameters
str
Returns
char*

◆ remove_last_char()

void remove_last_char ( string str)

Removes the last char.

Parameters
str

◆ splitf()

char ** splitf ( const char * str,
char delim,
int * num_tokens )

Splits a string into tokens based on a delimiter.

Parameters
strThe input string to be split.
delimThe delimiter character.
num_tokensThe number of tokens found.
Returns
char** Returns an array of strings containing the tokens.

◆ strcat()

string strcat ( string dest,
cstring src )

Concatenate two strings.

This function concatenates the source string src to the end of the destination string dest. It assumes that dest has enough space to accommodate the concatenated result.

Parameters
destThe destination string.
srcThe source string to be concatenated.
Returns
A pointer to the destination string.

◆ strcmp()

int strcmp ( cstring s1,
cstring s2 )

Compares two strings lexicographically.

This function compares two strings s1 and s2 lexicographically. It returns a negative value if s1 is less than s2, a positive value if s1 is greater than s2, and zero if they are equal.

Parameters
s1The first string to be compared.
s2The second string to be compared.
Returns
An integer less than, equal to, or greater than zero, depending on the comparison result.

◆ strcpy()

string strcpy ( string dest,
cstring src )

Copies a string from src to dest.

Parameters
destPointer to the destination
srcSource string
Returns
The resulting copy of the string src

◆ string_transport_front()

void string_transport_front ( char * str,
int x )

Move the last x characters of a string to the front and delete the rest.

This function takes a null-terminated C string and moves the last x characters to the beginning of the string while deleting the remaining characters. If x is greater than or equal to the length of the string, the function does nothing.

Parameters
strThe input string.
xThe number of characters to move to the front.
Note
This function modifies the input string in place.

◆ strlen()

int strlen ( char s[])

Calculate the length of a null-terminated string.

This function calculates the length of the input null-terminated string by iterating through the characters until it reaches the null terminator.

Parameters
sThe input string.
Returns
The length of the string.

◆ strncmp()

int strncmp ( cstring s1,
cstring s2,
size_t n )

Compares two strings, up to a specified number of characters.

This function compares the first n characters of two strings s1 and s2. It returns a negative value if s1 is less than s2, a positive value if s1 is greater than s2, and zero if they are equal.

Parameters
s1The first string to be compared.
s2The second string to be compared.
nThe maximum number of characters to compare.
Returns
An integer less than, equal to, or greater than zero, depending on the comparison result.

◆ strncpy()

string strncpy ( string dest,
cstring src,
size_t n )

Copies n characters from src to dest.

Parameters
destPointer to the destination
srcSource string
nNumber of characters that will be copies
Returns
The resulting copy of the string src

◆ strtol()

long strtol ( const char * str,
char ** endptr,
int base )

Converts a string to a long integer.

/**

Parameters
strThe input string to be converted.
endptrReference to a pointer that will be updated to point to the character after the last valid character.
baseThe base of the number.
Returns
long

◆ trim()

string trim ( cstring str)

Creates a new string without spaces from a C-style string.

This function allocates memory for a new string without spaces and returns the result. It is the caller's responsibility to free the allocated memory.

Parameters
strThe input string to be trimmed.
Returns
A dynamically allocated string without spaces.

◆ uint_to_string()

char * uint_to_string ( unsigned int num)

Converts an uint to string.

Parameters
num
Returns
char*