[utils] string utils, file utils, contiguous arrays of strings used for storing tokenized strings, klib for generic hashtables and vectors, antirez's sds for certain types of string building, utf8proc for iterating over utf-8 strings and unicode normalization

This commit is contained in:
Al
2015-03-03 12:27:19 -05:00
parent 27269e18ca
commit 5216aba1b6
16 changed files with 16961 additions and 0 deletions

49
src/string_utils.h Normal file
View File

@@ -0,0 +1,49 @@
#ifndef STRING_UTILS_H
#define STRING_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include "collections.h"
#include "sds/sds.h"
#include "utf8proc/utf8proc.h"
#include "vector.h"
VECTOR_INIT_FREE_DATA(string_array, sds, sdsfree)
// NOTE: this particular implementation works only for ASCII strings
int string_compare_case_insensitive(const char *str1, const char *str2);
int string_compare_n_case_insensitive(const char *str1, const char *str2, size_t len);
int string_common_prefix(const char *str1, const char *str2);
void string_lower(char *str);
void string_upper(char *str);
bool string_starts_with(const char *str, const char *start);
bool string_ends_with(const char *str, const char *ending);
uint string_translate(sds str, char *word_chars, char *word_repls, size_t trans_len);
char *utf8_reversed_string(const char *s); // returns a copy, caller frees
bool utf8_is_letter(int32_t ch);
char *string_strip_whitespace(char *str);
void contiguous_string_array_add_string_unterminated(char_array *array, char *str);
void contiguous_string_array_add_string(char_array *array, char *str);
void contiguous_string_array_add_string_unterminated_len(char_array *array, char *str, size_t len);
void contiguous_string_array_add_string_len(char_array *array, char *str, size_t len);
int contiguous_string_array_next_index(char_array *string_array, int i, size_t n);
#ifdef __cplusplus
}
#endif
#endif