Cthulhu  0.2.10
Cthulhu compiler collection
str.c File Reference
#include "std/str.h"
#include "std/map.h"
#include "std/typed/vector.h"
#include "std/vector.h"
#include "arena/arena.h"
#include "base/util.h"
#include "base/panic.h"
#include "core/macros.h"
#include <limits.h>
#include <string.h>
#include <stdio.h>
Include dependency graph for str.c:

Go to the source code of this file.

Macros

#define CT_SPRINTF   snprintf
 
#define CT_SNPRINTF   snprintf
 
#define CT_VSNPRINTF   vsnprintf
 

Functions

STA_DECL size_t str_sprintf (char *str, size_t len, const char *fmt,...)
 
STA_DECL size_t str_vsprintf (char *str, size_t len, const char *fmt, va_list args)
 
STA_DECL text_t text_vformat (arena_t *arena, const char *fmt, va_list args)
 format a string More...
 
STA_DECL text_t text_format (arena_t *arena, const char *fmt,...)
 
STA_DECL char * str_format (arena_t *arena, const char *fmt,...)
 
STA_DECL char * str_vformat (arena_t *arena, const char *fmt, va_list args)
 format a string More...
 
STA_DECL bool char_is_any_of (char c, const char *chars)
 check if a character is any of a set of characters More...
 
STA_DECL size_t str_rfind_any (const char *str, const char *letters)
 find the first instance of a set of characters in a string More...
 
STA_DECL char * str_noext (const char *path, arena_t *arena)
 remove the last file extension from a path More...
 
STA_DECL char * str_ext (const char *path, arena_t *arena)
 get the last file extension from a path More...
 
STA_DECL char * str_directory (const char *path, arena_t *arena)
 get the directory segment of a path More...
 
STA_DECL char * str_basename (const char *path, arena_t *arena)
 get the filename from a path More...
 
STA_DECL char * str_filename (const char *path, arena_t *arena)
 get the filename from a path More...
 
STA_DECL bool str_startswith (const char *str, const char *prefix)
 see if a string starts with a prefix More...
 
STA_DECL bool str_endswith (const char *str, const char *suffix)
 check if a string ends with a substring More...
 
STA_DECL bool str_endswithn (const char *str, size_t len, const char *suffix)
 
STA_DECL char * str_join (const char *sep, const vector_t *parts, arena_t *arena)
 join strings More...
 
STA_DECL char * str_repeat (const char *str, size_t times, arena_t *arena)
 repeat a string More...
 
STA_DECL size_t str_normalize_into (char *dst, size_t dstlen, const char *src, size_t srclen)
 
STA_DECL char * str_normalize (const char *str, arena_t *arena)
 turn a string into a C string literal More...
 
STA_DECL char * str_normalizen (text_view_t text, arena_t *arena)
 turn a string with length into a C string literal More...
 
STA_DECL vector_tstr_split (const char *str, const char *sep, arena_t *arena)
 split a string into a vector by a separator More...
 
STA_DECL bool str_contains (const char *str, const char *search)
 check if a string contains a substring More...
 
STA_DECL char * str_replace (const char *str, const char *search, const char *repl, arena_t *arena)
 replace all instances of a substring in a string More...
 
STA_DECL void str_replace_inplace (text_t *text, const char *search, const char *repl)
 
STA_DECL void str_trim_back_inplace (text_t *text, const char *chars)
 
STA_DECL void str_sort_inplace (char *str, size_t len)
 
STA_DECL char * str_replace_many (const char *str, const map_t *repl, arena_t *arena)
 replace all instances of a each substring in a string with provided replacement More...
 
STA_DECL const char * str_common_prefix (const vector_t *args, arena_t *arena)
 find the longest common prefix of a vector of paths More...
 
STA_DECL size_t str_rfind (const char *str, const char *sub)
 find the last instance of a substring in a string More...
 
STA_DECL size_t str_find (const char *str, const char *sub)
 find the first instance of a substring in a string More...
 
STA_DECL CT_NOALIAS char * str_erase (char *str, size_t len, const char *letters)
 
STA_DECL char * str_upper (const char *str, arena_t *arena)
 uppercase an ascii string More...
 
STA_DECL char * str_lower (const char *str, arena_t *arena)
 lowercase an ascii string this allocates a new string in the provided arena More...
 
STA_DECL char str_tolower (char c)
 get the lowercase version of a character More...
 
STA_DECL char str_toupper (char c)
 get the uppercase version of a character More...
 
STA_DECL bool text_view_equal (text_view_t lhs, text_view_t rhs)
 check if two strings are equal More...
 

Macro Definition Documentation

◆ CT_SNPRINTF

#define CT_SNPRINTF   snprintf

Definition at line 27 of file str.c.

◆ CT_SPRINTF

#define CT_SPRINTF   snprintf

Definition at line 26 of file str.c.

◆ CT_VSNPRINTF

#define CT_VSNPRINTF   vsnprintf

Definition at line 28 of file str.c.

Function Documentation

◆ str_endswithn()

STA_DECL bool str_endswithn ( const char *  str,
size_t  len,
const char *  suffix 
)

Definition at line 259 of file str.c.

◆ str_erase()

STA_DECL CT_NOALIAS char* str_erase ( char *  str,
size_t  len,
const char *  letters 
)

Definition at line 906 of file str.c.

◆ str_format()

STA_DECL char* str_format ( arena_t arena,
const char *  fmt,
  ... 
)

Definition at line 97 of file str.c.

◆ str_normalize_into()

STA_DECL size_t str_normalize_into ( char *  dst,
size_t  dstlen,
const char *  src,
size_t  srclen 
)

Definition at line 444 of file str.c.

◆ str_replace_inplace()

STA_DECL void str_replace_inplace ( text_t text,
const char *  search,
const char *  repl 
)

Definition at line 650 of file str.c.

◆ str_sort_inplace()

STA_DECL void str_sort_inplace ( char *  str,
size_t  len 
)

Definition at line 716 of file str.c.

◆ str_sprintf()

STA_DECL size_t str_sprintf ( char *  str,
size_t  len,
const char *  fmt,
  ... 
)

Definition at line 34 of file str.c.

◆ str_trim_back_inplace()

STA_DECL void str_trim_back_inplace ( text_t text,
const char *  chars 
)

Definition at line 697 of file str.c.

◆ str_vsprintf()

STA_DECL size_t str_vsprintf ( char *  str,
size_t  len,
const char *  fmt,
va_list  args 
)

Definition at line 47 of file str.c.

◆ text_format()

STA_DECL text_t text_format ( arena_t arena,
const char *  fmt,
  ... 
)

Definition at line 81 of file str.c.