2017-01-23 06:19:43 +00:00
|
|
|
/*
|
2018-06-10 02:28:22 +00:00
|
|
|
4coder_string.h - Version 1.0.114
|
2017-01-23 06:19:43 +00:00
|
|
|
no warranty implied; use at your own risk
|
|
|
|
|
|
|
|
This software is in the public domain. Where that dedication is not
|
|
|
|
recognized, you are granted a perpetual, irrevocable license to copy,
|
|
|
|
distribute, and modify this file as you see fit.
|
|
|
|
|
|
|
|
To include implementation: #define FSTRING_IMPLEMENTATION
|
|
|
|
To use in C mode: #define FSTRING_C
|
|
|
|
*/
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2017-06-27 02:47:00 +00:00
|
|
|
// 4tech_standard_preamble.h
|
|
|
|
#if !defined(FTECH_INTEGERS)
|
|
|
|
#define FTECH_INTEGERS
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef int8_t i8_4tech;
|
|
|
|
typedef int16_t i16_4tech;
|
|
|
|
typedef int32_t i32_4tech;
|
|
|
|
typedef int64_t i64_4tech;
|
|
|
|
|
|
|
|
typedef uint8_t u8_4tech;
|
|
|
|
typedef uint16_t u16_4tech;
|
|
|
|
typedef uint32_t u32_4tech;
|
|
|
|
typedef uint64_t u64_4tech;
|
|
|
|
|
|
|
|
#if defined(FTECH_32_BIT)
|
|
|
|
typedef u32_4tech umem_4tech;
|
|
|
|
#else
|
|
|
|
typedef u64_4tech umem_4tech;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef float f32_4tech;
|
|
|
|
typedef double f64_4tech;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2017-06-27 02:47:00 +00:00
|
|
|
typedef int8_t b8_4tech;
|
|
|
|
typedef int32_t b32_4tech;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(Assert)
|
|
|
|
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
|
|
|
|
#endif
|
2017-11-09 18:30:24 +00:00
|
|
|
// standard preamble end
|
2016-06-07 16:26:11 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#if !defined(FSTRING_LINK)
|
2016-05-27 14:51:12 +00:00
|
|
|
# define FSTRING_LINK static
|
|
|
|
#endif
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#if !defined(FSTRING_INLINE)
|
|
|
|
# if defined(FSTRING_C)
|
|
|
|
# define FSTRING_INLINE static
|
|
|
|
# else
|
|
|
|
# define FSTRING_INLINE inline
|
|
|
|
# endif
|
2016-05-27 14:51:12 +00:00
|
|
|
#endif
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
|
|
|
#define literal(s) (s), (sizeof(s)-1)
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
typedef struct String{
|
2016-02-01 05:03:42 +00:00
|
|
|
char *str;
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech size;
|
|
|
|
i32_4tech memory_size;
|
2016-08-28 04:31:06 +00:00
|
|
|
} String;
|
2016-02-20 18:23:46 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
static String null_string = {};
|
2016-06-07 16:26:11 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FCODER_STRING_H)
|
2016-07-06 19:18:10 +00:00
|
|
|
#define FCODER_STRING_H
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_slash(char c);
|
|
|
|
FSTRING_INLINE b32_4tech char_is_upper(char c);
|
2017-03-27 22:36:42 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_upper_utf8(char c);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_lower(char c);
|
2017-03-27 22:36:42 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_lower_utf8(u8_4tech c);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_INLINE char char_to_upper(char c);
|
|
|
|
FSTRING_INLINE char char_to_lower(char c);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_whitespace(char c);
|
|
|
|
FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c);
|
2017-03-27 22:36:42 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_alpha_numeric_utf8(u8_4tech c);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c);
|
2017-03-27 22:36:42 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_alpha_numeric_true_utf8(u8_4tech c);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_alpha(char c);
|
2017-03-27 22:36:42 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_alpha_utf8(u8_4tech c);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_alpha_true(char c);
|
2017-03-27 22:36:42 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_alpha_true_utf8(u8_4tech c);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_hex(char c);
|
2017-03-27 22:36:42 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_hex_utf8(u8_4tech c);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_numeric(char c);
|
2017-03-27 22:36:42 +00:00
|
|
|
FSTRING_INLINE b32_4tech char_is_numeric_utf8(u8_4tech c);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE String make_string_cap(void *str, i32_4tech size, i32_4tech mem_size);
|
|
|
|
FSTRING_INLINE String make_string(void *str, i32_4tech size);
|
2016-07-06 19:18:10 +00:00
|
|
|
#ifndef make_lit_string
|
2016-09-04 05:08:36 +00:00
|
|
|
# define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s)))
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2018-03-26 05:19:08 +00:00
|
|
|
#ifndef lit
|
|
|
|
# define lit(s) make_lit_string(s)
|
|
|
|
#endif
|
2016-07-06 19:18:10 +00:00
|
|
|
#ifndef make_fixed_width_string
|
2016-09-04 05:08:36 +00:00
|
|
|
# define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s)))
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
#ifndef expand_str
|
2016-09-04 05:08:36 +00:00
|
|
|
# define expand_str(s) ((s).str), ((s).size)
|
2016-08-28 04:31:06 +00:00
|
|
|
#endif
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK i32_4tech str_size(char *str);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_INLINE String make_string_slowly(void *str);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE String substr_tail(String str, i32_4tech start);
|
|
|
|
FSTRING_INLINE String substr(String str, i32_4tech start, i32_4tech size);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_LINK String skip_whitespace(String str);
|
2017-01-29 00:03:23 +00:00
|
|
|
FSTRING_LINK String skip_whitespace_measure(String str, i32_4tech *skip_length);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_LINK String chop_whitespace(String str);
|
|
|
|
FSTRING_LINK String skip_chop_whitespace(String str);
|
2017-01-29 00:03:23 +00:00
|
|
|
FSTRING_LINK String skip_chop_whitespace_measure(String str, i32_4tech *skip_length);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_INLINE String tailstr(String str);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK b32_4tech match_cc(char *a, char *b);
|
|
|
|
FSTRING_LINK b32_4tech match_sc(String a, char *b);
|
|
|
|
FSTRING_INLINE b32_4tech match_cs(char *a, String b);
|
|
|
|
FSTRING_LINK b32_4tech match_ss(String a, String b);
|
|
|
|
FSTRING_LINK b32_4tech match_part_ccl(char *a, char *b, i32_4tech *len);
|
|
|
|
FSTRING_LINK b32_4tech match_part_scl(String a, char *b, i32_4tech *len);
|
|
|
|
FSTRING_INLINE b32_4tech match_part_cc(char *a, char *b);
|
|
|
|
FSTRING_INLINE b32_4tech match_part_sc(String a, char *b);
|
|
|
|
FSTRING_LINK b32_4tech match_part_cs(char *a, String b);
|
|
|
|
FSTRING_LINK b32_4tech match_part_ss(String a, String b);
|
|
|
|
FSTRING_LINK b32_4tech match_insensitive_cc(char *a, char *b);
|
|
|
|
FSTRING_LINK b32_4tech match_insensitive_sc(String a, char *b);
|
|
|
|
FSTRING_INLINE b32_4tech match_insensitive_cs(char *a, String b);
|
|
|
|
FSTRING_LINK b32_4tech match_insensitive_ss(String a, String b);
|
|
|
|
FSTRING_LINK b32_4tech match_part_insensitive_ccl(char *a, char *b, i32_4tech *len);
|
|
|
|
FSTRING_LINK b32_4tech match_part_insensitive_scl(String a, char *b, i32_4tech *len);
|
|
|
|
FSTRING_INLINE b32_4tech match_part_insensitive_cc(char *a, char *b);
|
|
|
|
FSTRING_INLINE b32_4tech match_part_insensitive_sc(String a, char *b);
|
|
|
|
FSTRING_LINK b32_4tech match_part_insensitive_cs(char *a, String b);
|
|
|
|
FSTRING_LINK b32_4tech match_part_insensitive_ss(String a, String b);
|
|
|
|
FSTRING_LINK i32_4tech compare_cc(char *a, char *b);
|
|
|
|
FSTRING_LINK i32_4tech compare_sc(String a, char *b);
|
|
|
|
FSTRING_INLINE i32_4tech compare_cs(char *a, String b);
|
|
|
|
FSTRING_LINK i32_4tech compare_ss(String a, String b);
|
|
|
|
FSTRING_LINK i32_4tech find_c_char(char *str, i32_4tech start, char character);
|
|
|
|
FSTRING_LINK i32_4tech find_s_char(String str, i32_4tech start, char character);
|
|
|
|
FSTRING_LINK i32_4tech rfind_s_char(String str, i32_4tech start, char character);
|
|
|
|
FSTRING_LINK i32_4tech find_c_chars(char *str, i32_4tech start, char *characters);
|
|
|
|
FSTRING_LINK i32_4tech find_s_chars(String str, i32_4tech start, char *characters);
|
|
|
|
FSTRING_LINK i32_4tech find_substr_c(char *str, i32_4tech start, String seek);
|
|
|
|
FSTRING_LINK i32_4tech find_substr_s(String str, i32_4tech start, String seek);
|
|
|
|
FSTRING_LINK i32_4tech rfind_substr_s(String str, i32_4tech start, String seek);
|
|
|
|
FSTRING_LINK i32_4tech find_substr_insensitive_c(char *str, i32_4tech start, String seek);
|
|
|
|
FSTRING_LINK i32_4tech find_substr_insensitive_s(String str, i32_4tech start, String seek);
|
|
|
|
FSTRING_INLINE b32_4tech has_substr_c(char *s, String seek);
|
|
|
|
FSTRING_INLINE b32_4tech has_substr_s(String s, String seek);
|
|
|
|
FSTRING_INLINE b32_4tech has_substr_insensitive_c(char *s, String seek);
|
|
|
|
FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String seek);
|
|
|
|
FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src);
|
|
|
|
FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src);
|
|
|
|
FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src);
|
2017-03-13 23:48:11 +00:00
|
|
|
FSTRING_LINK b32_4tech copy_checked_cs(char *dest, i32_4tech dest_cap, String src);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src);
|
|
|
|
FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src);
|
2017-03-13 23:48:11 +00:00
|
|
|
FSTRING_LINK b32_4tech copy_partial_cs(char *dest, i32_4tech dest_cap, String src);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_INLINE void copy_ss(String *dest, String src);
|
|
|
|
FSTRING_INLINE void copy_sc(String *dest, char *src);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK b32_4tech append_checked_ss(String *dest, String src);
|
|
|
|
FSTRING_LINK b32_4tech append_partial_sc(String *dest, char *src);
|
|
|
|
FSTRING_LINK b32_4tech append_partial_ss(String *dest, String src);
|
|
|
|
FSTRING_LINK b32_4tech append_s_char(String *dest, char c);
|
|
|
|
FSTRING_INLINE b32_4tech append_ss(String *dest, String src);
|
|
|
|
FSTRING_INLINE b32_4tech append_sc(String *dest, char *src);
|
|
|
|
FSTRING_LINK b32_4tech terminate_with_null(String *str);
|
|
|
|
FSTRING_LINK b32_4tech append_padding(String *dest, char c, i32_4tech target_size);
|
2018-05-08 07:14:23 +00:00
|
|
|
FSTRING_LINK void string_interpret_escapes(String src, char *dst);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_LINK void replace_char(String *str, char replace, char with);
|
2017-11-09 18:30:24 +00:00
|
|
|
FSTRING_LINK void replace_str_ss(String *str, String replace, String with);
|
|
|
|
FSTRING_LINK void replace_str_sc(String *str, String replace, char *with);
|
|
|
|
FSTRING_LINK void replace_str_cs(String *str, char *replace, String with);
|
|
|
|
FSTRING_LINK void replace_str_cc(String *str, char *replace, char *with);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_LINK void to_lower_cc(char *src, char *dst);
|
|
|
|
FSTRING_LINK void to_lower_ss(String *dst, String src);
|
|
|
|
FSTRING_LINK void to_lower_s(String *str);
|
|
|
|
FSTRING_LINK void to_upper_cc(char *src, char *dst);
|
|
|
|
FSTRING_LINK void to_upper_ss(String *dst, String src);
|
|
|
|
FSTRING_LINK void to_upper_s(String *str);
|
|
|
|
FSTRING_LINK void to_camel_cc(char *src, char *dst);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x);
|
|
|
|
FSTRING_LINK b32_4tech int_to_str(String *dest, i32_4tech x);
|
|
|
|
FSTRING_LINK b32_4tech append_int_to_str(String *dest, i32_4tech x);
|
|
|
|
FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x);
|
|
|
|
FSTRING_LINK b32_4tech u64_to_str(String *dest, uint64_t x);
|
|
|
|
FSTRING_LINK b32_4tech append_u64_to_str(String *dest, uint64_t x);
|
|
|
|
FSTRING_LINK i32_4tech float_to_str_size(float x);
|
|
|
|
FSTRING_LINK b32_4tech append_float_to_str(String *dest, float x);
|
|
|
|
FSTRING_LINK b32_4tech float_to_str(String *dest, float x);
|
|
|
|
FSTRING_LINK i32_4tech str_is_int_c(char *str);
|
|
|
|
FSTRING_LINK b32_4tech str_is_int_s(String str);
|
|
|
|
FSTRING_LINK i32_4tech str_to_int_c(char *str);
|
|
|
|
FSTRING_LINK i32_4tech str_to_int_s(String str);
|
|
|
|
FSTRING_LINK i32_4tech hexchar_to_int(char c);
|
|
|
|
FSTRING_LINK char int_to_hexchar(i32_4tech x);
|
|
|
|
FSTRING_LINK u32_4tech hexstr_to_int(String str);
|
|
|
|
FSTRING_LINK b32_4tech color_to_hexstr(String *s, u32_4tech color);
|
|
|
|
FSTRING_LINK b32_4tech hexstr_to_color(String s, u32_4tech *out);
|
|
|
|
FSTRING_LINK i32_4tech reverse_seek_slash_pos(String str, i32_4tech pos);
|
|
|
|
FSTRING_INLINE i32_4tech reverse_seek_slash(String str);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_INLINE String front_of_directory(String dir);
|
|
|
|
FSTRING_INLINE String path_of_directory(String dir);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK b32_4tech set_last_folder_sc(String *dir, char *folder_name, char slash);
|
|
|
|
FSTRING_LINK b32_4tech set_last_folder_ss(String *dir, String folder_name, char slash);
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_LINK String file_extension(String str);
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK b32_4tech remove_extension(String *str);
|
|
|
|
FSTRING_LINK b32_4tech remove_last_folder(String *str);
|
|
|
|
FSTRING_LINK b32_4tech string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index);
|
|
|
|
FSTRING_LINK b32_4tech string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index);
|
2016-11-05 02:59:35 +00:00
|
|
|
FSTRING_LINK String get_first_double_line(String source);
|
|
|
|
FSTRING_LINK String get_next_double_line(String source, String line);
|
|
|
|
FSTRING_LINK String get_next_word(String source, String prev_word);
|
|
|
|
FSTRING_LINK String get_first_word(String source);
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(FSTRING_C) && !defined(FSTRING_GUARD)
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE String make_string(void *str, i32_4tech size, i32_4tech mem_size){return(make_string_cap(str,size,mem_size));}
|
|
|
|
FSTRING_INLINE String substr(String str, i32_4tech start){return(substr_tail(str,start));}
|
2017-01-29 00:03:23 +00:00
|
|
|
FSTRING_LINK String skip_whitespace(String str, i32_4tech *skip_length){return(skip_whitespace_measure(str,skip_length));}
|
|
|
|
FSTRING_LINK String skip_chop_whitespace(String str, i32_4tech *skip_length){return(skip_chop_whitespace_measure(str,skip_length));}
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK b32_4tech match(char *a, char *b){return(match_cc(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match(String a, char *b){return(match_sc(a,b));}
|
|
|
|
FSTRING_INLINE b32_4tech match(char *a, String b){return(match_cs(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match(String a, String b){return(match_ss(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_part(char *a, char *b, i32_4tech *len){return(match_part_ccl(a,b,len));}
|
|
|
|
FSTRING_LINK b32_4tech match_part(String a, char *b, i32_4tech *len){return(match_part_scl(a,b,len));}
|
|
|
|
FSTRING_INLINE b32_4tech match_part(char *a, char *b){return(match_part_cc(a,b));}
|
|
|
|
FSTRING_INLINE b32_4tech match_part(String a, char *b){return(match_part_sc(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_part(char *a, String b){return(match_part_cs(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_part(String a, String b){return(match_part_ss(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));}
|
|
|
|
FSTRING_INLINE b32_4tech match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_insensitive(String a, String b){return(match_insensitive_ss(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_part_insensitive(char *a, char *b, i32_4tech *len){return(match_part_insensitive_ccl(a,b,len));}
|
|
|
|
FSTRING_LINK b32_4tech match_part_insensitive(String a, char *b, i32_4tech *len){return(match_part_insensitive_scl(a,b,len));}
|
|
|
|
FSTRING_INLINE b32_4tech match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));}
|
|
|
|
FSTRING_INLINE b32_4tech match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));}
|
|
|
|
FSTRING_LINK b32_4tech match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));}
|
|
|
|
FSTRING_LINK i32_4tech compare(char *a, char *b){return(compare_cc(a,b));}
|
|
|
|
FSTRING_LINK i32_4tech compare(String a, char *b){return(compare_sc(a,b));}
|
|
|
|
FSTRING_INLINE i32_4tech compare(char *a, String b){return(compare_cs(a,b));}
|
|
|
|
FSTRING_LINK i32_4tech compare(String a, String b){return(compare_ss(a,b));}
|
|
|
|
FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char character){return(find_c_char(str,start,character));}
|
|
|
|
FSTRING_LINK i32_4tech find(String str, i32_4tech start, char character){return(find_s_char(str,start,character));}
|
|
|
|
FSTRING_LINK i32_4tech rfind(String str, i32_4tech start, char character){return(rfind_s_char(str,start,character));}
|
|
|
|
FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char *characters){return(find_c_chars(str,start,characters));}
|
|
|
|
FSTRING_LINK i32_4tech find(String str, i32_4tech start, char *characters){return(find_s_chars(str,start,characters));}
|
|
|
|
FSTRING_LINK i32_4tech find_substr(char *str, i32_4tech start, String seek){return(find_substr_c(str,start,seek));}
|
|
|
|
FSTRING_LINK i32_4tech find_substr(String str, i32_4tech start, String seek){return(find_substr_s(str,start,seek));}
|
|
|
|
FSTRING_LINK i32_4tech rfind_substr(String str, i32_4tech start, String seek){return(rfind_substr_s(str,start,seek));}
|
|
|
|
FSTRING_LINK i32_4tech find_substr_insensitive(char *str, i32_4tech start, String seek){return(find_substr_insensitive_c(str,start,seek));}
|
|
|
|
FSTRING_LINK i32_4tech find_substr_insensitive(String str, i32_4tech start, String seek){return(find_substr_insensitive_s(str,start,seek));}
|
|
|
|
FSTRING_INLINE b32_4tech has_substr(char *s, String seek){return(has_substr_c(s,seek));}
|
|
|
|
FSTRING_INLINE b32_4tech has_substr(String s, String seek){return(has_substr_s(s,seek));}
|
|
|
|
FSTRING_INLINE b32_4tech has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));}
|
|
|
|
FSTRING_INLINE b32_4tech has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));}
|
|
|
|
FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));}
|
|
|
|
FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));}
|
|
|
|
FSTRING_LINK b32_4tech copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));}
|
2017-03-13 23:48:11 +00:00
|
|
|
FSTRING_LINK b32_4tech copy_checked(char *dest, i32_4tech dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));}
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK b32_4tech copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));}
|
|
|
|
FSTRING_LINK b32_4tech copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));}
|
2017-03-13 23:48:11 +00:00
|
|
|
FSTRING_LINK b32_4tech copy_partial(char *dest, i32_4tech dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));}
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_INLINE i32_4tech copy(char *dest, char *src){return(copy_cc(dest,src));}
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));}
|
|
|
|
FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));}
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK b32_4tech append_checked(String *dest, String src){return(append_checked_ss(dest,src));}
|
|
|
|
FSTRING_LINK b32_4tech append_partial(String *dest, char *src){return(append_partial_sc(dest,src));}
|
|
|
|
FSTRING_LINK b32_4tech append_partial(String *dest, String src){return(append_partial_ss(dest,src));}
|
|
|
|
FSTRING_LINK b32_4tech append(String *dest, char c){return(append_s_char(dest,c));}
|
|
|
|
FSTRING_INLINE b32_4tech append(String *dest, String src){return(append_ss(dest,src));}
|
|
|
|
FSTRING_INLINE b32_4tech append(String *dest, char *src){return(append_sc(dest,src));}
|
2017-11-09 18:30:24 +00:00
|
|
|
FSTRING_LINK void replace_str(String *str, String replace, String with){return(replace_str_ss(str,replace,with));}
|
|
|
|
FSTRING_LINK void replace_str(String *str, String replace, char *with){return(replace_str_sc(str,replace,with));}
|
|
|
|
FSTRING_LINK void replace_str(String *str, char *replace, String with){return(replace_str_cs(str,replace,with));}
|
|
|
|
FSTRING_LINK void replace_str(String *str, char *replace, char *with){return(replace_str_cc(str,replace,with));}
|
2016-11-02 03:27:51 +00:00
|
|
|
FSTRING_LINK void to_lower(char *src, char *dst){return(to_lower_cc(src,dst));}
|
|
|
|
FSTRING_LINK void to_lower(String *dst, String src){return(to_lower_ss(dst,src));}
|
|
|
|
FSTRING_LINK void to_lower(String *str){return(to_lower_s(str));}
|
|
|
|
FSTRING_LINK void to_upper(char *src, char *dst){return(to_upper_cc(src,dst));}
|
|
|
|
FSTRING_LINK void to_upper(String *dst, String src){return(to_upper_ss(dst,src));}
|
|
|
|
FSTRING_LINK void to_upper(String *str){return(to_upper_s(str));}
|
|
|
|
FSTRING_LINK void to_camel(char *src, char *dst){return(to_camel_cc(src,dst));}
|
2017-01-23 06:19:43 +00:00
|
|
|
FSTRING_LINK i32_4tech str_is_int(char *str){return(str_is_int_c(str));}
|
|
|
|
FSTRING_LINK b32_4tech str_is_int(String str){return(str_is_int_s(str));}
|
|
|
|
FSTRING_LINK i32_4tech str_to_int(char *str){return(str_to_int_c(str));}
|
|
|
|
FSTRING_LINK i32_4tech str_to_int(String str){return(str_to_int_s(str));}
|
|
|
|
FSTRING_LINK i32_4tech reverse_seek_slash(String str, i32_4tech pos){return(reverse_seek_slash_pos(str,pos));}
|
|
|
|
FSTRING_LINK b32_4tech set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));}
|
|
|
|
FSTRING_LINK b32_4tech set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));}
|
|
|
|
FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));}
|
2016-08-28 04:31:06 +00:00
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Character Helpers
|
|
|
|
//
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
char_is_slash(char c)
|
|
|
|
{
|
2016-07-06 19:18:10 +00:00
|
|
|
return (c == '\\' || c == '/');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-09-08 22:03:43 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-09-08 22:03:43 +00:00
|
|
|
char_is_upper(char c)
|
|
|
|
{
|
|
|
|
return (c >= 'A' && c <= 'Z');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2017-03-27 22:36:42 +00:00
|
|
|
char_is_upper_utf8(char c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'A' && c <= 'Z') || (unsigned char)c >= 128);
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-09-08 22:03:43 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-09-08 22:03:43 +00:00
|
|
|
char_is_lower(char c)
|
|
|
|
{
|
|
|
|
return (c >= 'a' && c <= 'z');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2017-03-27 22:36:42 +00:00
|
|
|
char_is_lower_utf8(u8_4tech c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (unsigned char)c >= 128);
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE char
|
2016-07-12 22:17:45 +00:00
|
|
|
char_to_upper(char c)
|
|
|
|
{
|
2016-07-06 19:18:10 +00:00
|
|
|
return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE char
|
2016-07-12 22:17:45 +00:00
|
|
|
char_to_lower(char c)
|
|
|
|
{
|
2016-07-06 19:18:10 +00:00
|
|
|
return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
char_is_whitespace(char c)
|
|
|
|
{
|
2016-07-06 19:18:10 +00:00
|
|
|
return (c == ' ' || c == '\n' || c == '\r' || c == '\t');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
char_is_alpha_numeric(char c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_');
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2017-03-27 22:36:42 +00:00
|
|
|
char_is_alpha_numeric_utf8(u8_4tech c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (unsigned char)c >= 128);
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
char_is_alpha_numeric_true(char c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'));
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2017-03-27 22:36:42 +00:00
|
|
|
char_is_alpha_numeric_true_utf8(u8_4tech c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (unsigned char)c >= 128);
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
char_is_alpha(char c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_');
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2017-03-27 22:36:42 +00:00
|
|
|
char_is_alpha_utf8(u8_4tech c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (unsigned char)c >= 128);
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
char_is_alpha_true(char c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2017-03-27 22:36:42 +00:00
|
|
|
char_is_alpha_true_utf8(u8_4tech c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (unsigned char)c >= 128);
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
char_is_hex(char c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'));
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2017-03-27 22:36:42 +00:00
|
|
|
char_is_hex_utf8(u8_4tech c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (unsigned char)c >= 128);
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
char_is_numeric(char c)
|
|
|
|
{
|
|
|
|
return (c >= '0' && c <= '9');
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-06-24 19:33:37 +00:00
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2017-03-27 22:36:42 +00:00
|
|
|
char_is_numeric_utf8(u8_4tech c)
|
|
|
|
{
|
2017-06-27 02:47:00 +00:00
|
|
|
return ((c >= '0' && c <= '9') || (unsigned char)c >= 128);
|
2017-03-27 22:36:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-06-24 19:33:37 +00:00
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
//
|
|
|
|
// String Making Functions
|
|
|
|
//
|
2016-05-27 14:51:12 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE String
|
2017-01-23 06:19:43 +00:00
|
|
|
make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){
|
2016-02-01 05:03:42 +00:00
|
|
|
String result;
|
2016-02-29 03:35:19 +00:00
|
|
|
result.str = (char*)str;
|
2016-02-01 05:03:42 +00:00
|
|
|
result.size = size;
|
|
|
|
result.memory_size = mem_size;
|
2016-09-03 05:03:03 +00:00
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE String
|
2017-01-23 06:19:43 +00:00
|
|
|
make_string(void *str, i32_4tech size){
|
2016-02-01 05:03:42 +00:00
|
|
|
String result;
|
2016-02-29 03:35:19 +00:00
|
|
|
result.str = (char*)str;
|
2016-02-01 05:03:42 +00:00
|
|
|
result.size = size;
|
|
|
|
result.memory_size = size;
|
2016-09-03 05:03:03 +00:00
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
str_size(char *str)
|
|
|
|
{
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
2018-05-08 07:14:23 +00:00
|
|
|
if (str != 0){
|
|
|
|
for (;str[i];++i);
|
|
|
|
}
|
2016-09-03 05:03:03 +00:00
|
|
|
return(i);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE String
|
2016-07-12 22:17:45 +00:00
|
|
|
make_string_slowly(void *str)
|
|
|
|
{
|
2016-02-01 05:03:42 +00:00
|
|
|
String result;
|
2016-02-29 03:35:19 +00:00
|
|
|
result.str = (char*)str;
|
|
|
|
result.size = str_size((char*)str);
|
2018-05-08 07:14:23 +00:00
|
|
|
result.memory_size = result.size + 1;
|
2016-09-03 05:03:03 +00:00
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE String
|
2017-01-23 06:19:43 +00:00
|
|
|
substr_tail(String str, i32_4tech start)
|
2016-07-12 22:17:45 +00:00
|
|
|
{
|
2016-02-01 05:03:42 +00:00
|
|
|
String result;
|
|
|
|
result.str = str.str + start;
|
|
|
|
result.size = str.size - start;
|
2016-07-06 19:18:10 +00:00
|
|
|
result.memory_size = 0;
|
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE String
|
2017-01-23 06:19:43 +00:00
|
|
|
substr(String str, i32_4tech start, i32_4tech size)
|
2016-07-12 22:17:45 +00:00
|
|
|
{
|
2016-02-01 05:03:42 +00:00
|
|
|
String result;
|
|
|
|
result.str = str.str + start;
|
2016-07-06 19:18:10 +00:00
|
|
|
result.size = size;
|
2016-02-01 05:03:42 +00:00
|
|
|
if (start + size > str.size){
|
|
|
|
result.size = str.size - start;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
result.memory_size = 0;
|
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2016-07-12 22:17:45 +00:00
|
|
|
skip_whitespace(String str)
|
|
|
|
{
|
2018-11-20 08:18:54 +00:00
|
|
|
String result = {};
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
for (; i < str.size && char_is_whitespace(str.str[i]); ++i);
|
|
|
|
result = substr(str, i, str.size - i);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2017-01-29 00:03:23 +00:00
|
|
|
skip_whitespace_measure(String str, i32_4tech *skip_length)
|
|
|
|
{
|
2018-11-20 08:18:54 +00:00
|
|
|
String result = {};
|
2017-01-29 00:03:23 +00:00
|
|
|
i32_4tech i = 0;
|
|
|
|
for (; i < str.size && char_is_whitespace(str.str[i]); ++i);
|
|
|
|
result = substr(str, i, str.size - i);
|
|
|
|
*skip_length = i;
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2016-07-12 22:17:45 +00:00
|
|
|
chop_whitespace(String str)
|
|
|
|
{
|
2018-11-20 08:18:54 +00:00
|
|
|
String result = {};
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = str.size;
|
2016-07-06 19:18:10 +00:00
|
|
|
for (; i > 0 && char_is_whitespace(str.str[i-1]); --i);
|
|
|
|
result = substr(str, 0, i);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-25 12:12:09 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2016-07-12 22:17:45 +00:00
|
|
|
skip_chop_whitespace(String str)
|
|
|
|
{
|
2016-07-06 19:18:10 +00:00
|
|
|
str = skip_whitespace(str);
|
|
|
|
str = chop_whitespace(str);
|
|
|
|
return(str);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2017-01-29 00:03:23 +00:00
|
|
|
skip_chop_whitespace_measure(String str, i32_4tech *skip_length)
|
|
|
|
{
|
|
|
|
str = skip_whitespace_measure(str, skip_length);
|
|
|
|
str = chop_whitespace(str);
|
|
|
|
return(str);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE String
|
2016-07-12 22:17:45 +00:00
|
|
|
tailstr(String str)
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
result.str = str.str + str.size;
|
|
|
|
result.memory_size = str.memory_size - str.size;
|
|
|
|
result.size = 0;
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// String Comparison
|
|
|
|
//
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_cc(char *a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0;; ++i){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (a[i] != b[i]){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (a[i] == 0){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_sc(String a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
2016-02-01 05:03:42 +00:00
|
|
|
for (; i < a.size; ++i){
|
|
|
|
if (a.str[i] != b[i]){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (b[i] != 0){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_cs(char *a, String b){
|
|
|
|
return(match_sc(b,a));
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_ss(String a, String b){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (a.size != b.size){
|
|
|
|
return 0;
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0; i < b.size; ++i){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (a.str[i] != b.str[i]){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
match_part_ccl(char *a, char *b, i32_4tech *len){
|
2017-07-17 18:12:28 +00:00
|
|
|
if (a == 0){
|
|
|
|
a = "";
|
|
|
|
}
|
|
|
|
if (b == 0){
|
|
|
|
b = "";
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i;
|
2016-02-01 05:03:42 +00:00
|
|
|
for (i = 0; b[i] != 0; ++i){
|
|
|
|
if (a[i] != b[i]){
|
2017-07-17 18:12:28 +00:00
|
|
|
return(0);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*len = i;
|
2017-07-17 18:12:28 +00:00
|
|
|
return(1);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
match_part_scl(String a, char *b, i32_4tech *len){
|
2017-07-17 18:12:28 +00:00
|
|
|
if (b == 0){
|
|
|
|
b = "";
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i;
|
2016-02-01 05:03:42 +00:00
|
|
|
for (i = 0; b[i] != 0; ++i){
|
2017-07-17 18:12:28 +00:00
|
|
|
if (i == a.size || a.str[i] != b[i]){
|
|
|
|
return(0);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*len = i;
|
2017-07-17 18:12:28 +00:00
|
|
|
return(1);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_part_cc(char *a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech x;
|
2016-08-28 04:31:06 +00:00
|
|
|
return match_part_ccl(a,b,&x);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_part_sc(String a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech x;
|
2016-08-28 04:31:06 +00:00
|
|
|
return match_part_scl(a,b,&x);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_part_cs(char *a, String b){
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0; i != b.size; ++i){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (a[i] != b.str[i]){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_part_ss(String a, String b){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (a.size < b.size){
|
2017-07-17 18:12:28 +00:00
|
|
|
return(0);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0; i < b.size; ++i){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (a.str[i] != b.str[i]){
|
2017-07-17 18:12:28 +00:00
|
|
|
return(0);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-17 18:12:28 +00:00
|
|
|
return(1);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_insensitive_cc(char *a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0;; ++i){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (char_to_upper(a[i]) !=
|
|
|
|
char_to_upper(b[i])){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (a[i] == 0){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_insensitive_sc(String a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
2016-02-01 05:03:42 +00:00
|
|
|
for (; i < a.size; ++i){
|
|
|
|
if (char_to_upper(a.str[i]) !=
|
|
|
|
char_to_upper(b[i])){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (b[i] != 0){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_insensitive_cs(char *a, String b){
|
|
|
|
return match_insensitive_sc(b,a);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_insensitive_ss(String a, String b){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (a.size != b.size){
|
|
|
|
return 0;
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0; i < b.size; ++i){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (char_to_upper(a.str[i]) !=
|
|
|
|
char_to_upper(b.str[i])){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){
|
|
|
|
i32_4tech i;
|
2016-02-01 05:03:42 +00:00
|
|
|
for (i = 0; b[i] != 0; ++i){
|
|
|
|
if (char_to_upper(a[i]) != char_to_upper(b[i])){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*len = i;
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
match_part_insensitive_scl(String a, char *b, i32_4tech *len){
|
|
|
|
i32_4tech i;
|
2016-02-01 05:03:42 +00:00
|
|
|
for (i = 0; b[i] != 0; ++i){
|
|
|
|
if (char_to_upper(a.str[i]) != char_to_upper(b[i]) ||
|
|
|
|
i == a.size){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*len = i;
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_part_insensitive_cc(char *a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech x;
|
2016-08-28 04:31:06 +00:00
|
|
|
return match_part_insensitive_ccl(a,b,&x);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_part_insensitive_sc(String a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech x;
|
2016-08-28 04:31:06 +00:00
|
|
|
return match_part_insensitive_scl(a,b,&x);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_part_insensitive_cs(char *a, String b){
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0; i != b.size; ++i){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (char_to_upper(a[i]) != char_to_upper(b.str[i])){
|
2016-08-31 16:52:46 +00:00
|
|
|
return(0);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
return(1);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
match_part_insensitive_ss(String a, String b){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (a.size < b.size){
|
2016-08-31 16:52:46 +00:00
|
|
|
return(0);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0; i < b.size; ++i){
|
2016-02-01 05:03:42 +00:00
|
|
|
if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){
|
2016-08-31 16:52:46 +00:00
|
|
|
return(0);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
return(1);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
compare_cc(char *a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0, r = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
while (a[i] == b[i] && a[i] != 0){
|
|
|
|
++i;
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
r = (a[i] > b[i]) - (a[i] < b[i]);
|
|
|
|
return(r);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
compare_sc(String a, char *b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0, r = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
while (i < a.size && a.str[i] == b[i]){
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i < a.size){
|
2016-08-31 16:52:46 +00:00
|
|
|
r = (a.str[i] > b[i]) - (a.str[i] < b[i]);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (b[i] == 0){
|
2016-08-31 16:52:46 +00:00
|
|
|
r = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
else{
|
2016-08-31 16:52:46 +00:00
|
|
|
r = -1;
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
return(r);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
compare_cs(char *a, String b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech r = -compare_sc(b,a);
|
2016-08-31 16:52:46 +00:00
|
|
|
return(r);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
compare_ss(String a, String b){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0, r = 0;
|
|
|
|
i32_4tech m = a.size;
|
2016-08-31 16:52:46 +00:00
|
|
|
if (b.size < m){
|
|
|
|
m = b.size;
|
|
|
|
}
|
|
|
|
while (i < m && a.str[i] == b.str[i]){
|
2016-07-06 19:18:10 +00:00
|
|
|
++i;
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
|
|
|
|
if (i < m){
|
|
|
|
r = (a.str[i] > b.str[i]) - (b.str[i] > a.str[i]);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
else{
|
2016-08-31 18:40:22 +00:00
|
|
|
r = (a.size > b.size) - (b.size > a.size);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
|
|
|
|
return(r);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// Finding Characters and Substrings
|
|
|
|
//
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
find_c_char(char *str, i32_4tech start, char character){
|
|
|
|
i32_4tech i = start;
|
2016-02-01 05:03:42 +00:00
|
|
|
while (str[i] != character && str[i] != 0) ++i;
|
2016-08-31 16:52:46 +00:00
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
find_s_char(String str, i32_4tech start, char character){
|
|
|
|
i32_4tech i = start;
|
2016-02-01 05:03:42 +00:00
|
|
|
while (i < str.size && str.str[i] != character) ++i;
|
2016-08-31 16:52:46 +00:00
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
rfind_s_char(String str, i32_4tech start, char character){
|
|
|
|
i32_4tech i = start;
|
2016-08-31 16:52:46 +00:00
|
|
|
while (i >= 0 && str.str[i] != character) --i;
|
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
find_c_chars(char *str, i32_4tech start, char *characters){
|
|
|
|
i32_4tech i = start, j;
|
2016-02-01 05:03:42 +00:00
|
|
|
while (str[i] != 0){
|
|
|
|
for (j = 0; characters[j]; ++j){
|
|
|
|
if (str[i] == characters[j]){
|
2016-08-31 16:52:46 +00:00
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
find_s_chars(String str, i32_4tech start, char *characters){
|
|
|
|
i32_4tech i = start, j;
|
2016-02-01 05:03:42 +00:00
|
|
|
while (i < str.size){
|
|
|
|
for (j = 0; characters[j]; ++j){
|
|
|
|
if (str.str[i] == characters[j]){
|
2016-08-31 16:52:46 +00:00
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
find_substr_c(char *str, i32_4tech start, String seek){
|
|
|
|
i32_4tech i, j, k;
|
|
|
|
b32_4tech hit;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
if (seek.size == 0){
|
2016-08-31 16:52:46 +00:00
|
|
|
i = str_size(str);
|
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
for (i = start; str[i]; ++i){
|
|
|
|
if (str[i] == seek.str[0]){
|
|
|
|
hit = 1;
|
|
|
|
for (j = 1, k = i+1; j < seek.size; ++j, ++k){
|
|
|
|
if (str[k] != seek.str[j]){
|
|
|
|
hit = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hit){
|
2016-08-31 16:52:46 +00:00
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
return(i);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
find_substr_s(String str, i32_4tech start, String seek){
|
|
|
|
i32_4tech stop_at, i, j, k;
|
|
|
|
b32_4tech hit;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
if (seek.size == 0){
|
|
|
|
return str.size;
|
|
|
|
}
|
|
|
|
stop_at = str.size - seek.size + 1;
|
|
|
|
for (i = start; i < stop_at; ++i){
|
|
|
|
if (str.str[i] == seek.str[0]){
|
|
|
|
hit = 1;
|
|
|
|
for (j = 1, k = i+1; j < seek.size; ++j, ++k){
|
|
|
|
if (str.str[k] != seek.str[j]){
|
|
|
|
hit = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hit){
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-31 16:52:46 +00:00
|
|
|
return(str.size);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
rfind_substr_s(String str, i32_4tech start, String seek){
|
|
|
|
i32_4tech i, j, k;
|
|
|
|
b32_4tech hit;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
if (seek.size == 0){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (start + seek.size > str.size){
|
|
|
|
start = str.size - seek.size;
|
|
|
|
}
|
|
|
|
for (i = start; i >= 0; --i){
|
|
|
|
if (str.str[i] == seek.str[0]){
|
|
|
|
hit = 1;
|
|
|
|
for (j = 1, k = i+1; j < seek.size; ++j, ++k){
|
|
|
|
if (str.str[k] != seek.str[j]){
|
|
|
|
hit = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hit){
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
find_substr_insensitive_c(char *str, i32_4tech start, String seek){
|
|
|
|
i32_4tech i, j, k;
|
|
|
|
b32_4tech hit;
|
2016-02-01 05:03:42 +00:00
|
|
|
char a_upper, b_upper;
|
2017-03-13 23:48:11 +00:00
|
|
|
char first_test_char;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
if (seek.size == 0){
|
|
|
|
return str_size(str);
|
|
|
|
}
|
2017-03-13 23:48:11 +00:00
|
|
|
first_test_char = char_to_upper(seek.str[0]);
|
2016-02-01 05:03:42 +00:00
|
|
|
for (i = start; str[i]; ++i){
|
2017-03-13 23:48:11 +00:00
|
|
|
a_upper = char_to_upper(str[i]);
|
|
|
|
if (a_upper == first_test_char){
|
2016-02-01 05:03:42 +00:00
|
|
|
hit = 1;
|
|
|
|
for (j = 1, k = i+1; j < seek.size; ++j, ++k){
|
|
|
|
a_upper = char_to_upper(str[k]);
|
|
|
|
b_upper = char_to_upper(seek.str[j]);
|
|
|
|
if (a_upper != b_upper){
|
|
|
|
hit = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hit){
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
find_substr_insensitive_s(String str, i32_4tech start, String seek){
|
|
|
|
i32_4tech i, j, k;
|
|
|
|
i32_4tech stop_at;
|
|
|
|
b32_4tech hit;
|
2016-02-01 05:03:42 +00:00
|
|
|
char a_upper, b_upper;
|
2017-03-13 23:48:11 +00:00
|
|
|
char first_test_char;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
if (seek.size == 0){
|
|
|
|
return str.size;
|
|
|
|
}
|
|
|
|
stop_at = str.size - seek.size + 1;
|
2017-03-13 23:48:11 +00:00
|
|
|
first_test_char = char_to_upper(seek.str[0]);
|
2016-02-01 05:03:42 +00:00
|
|
|
for (i = start; i < stop_at; ++i){
|
2017-03-13 23:48:11 +00:00
|
|
|
a_upper = char_to_upper(str.str[i]);
|
|
|
|
if (a_upper == first_test_char){
|
2016-02-01 05:03:42 +00:00
|
|
|
hit = 1;
|
|
|
|
for (j = 1, k = i+1; j < seek.size; ++j, ++k){
|
|
|
|
a_upper = char_to_upper(str.str[k]);
|
|
|
|
b_upper = char_to_upper(seek.str[j]);
|
|
|
|
if (a_upper != b_upper){
|
|
|
|
hit = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hit){
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str.size;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
has_substr_c(char *s, String seek){
|
|
|
|
return (s[find_substr_c(s, 0, seek)] != 0);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
has_substr_s(String s, String seek){
|
|
|
|
return (find_substr_s(s, 0, seek) < s.size);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
has_substr_insensitive_c(char *s, String seek){
|
|
|
|
return (s[find_substr_insensitive_c(s, 0, seek)] != 0);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
has_substr_insensitive_s(String s, String seek){
|
|
|
|
return (find_substr_insensitive_s(s, 0, seek) < s.size);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// String Copies and Appends
|
|
|
|
//
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
copy_fast_unsafe_cc(char *dest, char *src){
|
2016-07-06 19:18:10 +00:00
|
|
|
char *start = dest;
|
|
|
|
while (*src != 0){
|
|
|
|
*dest = *src;
|
|
|
|
++dest;
|
|
|
|
++src;
|
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
return (i32_4tech)(dest - start);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
copy_fast_unsafe_cs(char *dest, String src){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
while (i != src.size){
|
|
|
|
dest[i] = src.str[i];
|
|
|
|
++i;
|
|
|
|
}
|
2016-07-12 22:17:45 +00:00
|
|
|
return(src.size);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
copy_checked_ss(String *dest, String src){
|
2016-07-06 19:18:10 +00:00
|
|
|
char *dest_str;
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i;
|
2016-07-06 19:18:10 +00:00
|
|
|
if (dest->memory_size < src.size){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dest_str = dest->str;
|
|
|
|
for (i = 0; i < src.size; ++i){
|
|
|
|
dest_str[i] = src.str[i];
|
|
|
|
}
|
|
|
|
dest->size = src.size;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-03-13 23:48:11 +00:00
|
|
|
copy_checked_cs(char *dest, i32_4tech dest_cap, String src){
|
|
|
|
i32_4tech i;
|
|
|
|
if (dest_cap < src.size){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < src.size; ++i){
|
|
|
|
dest[i] = src.str[i];
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
copy_partial_sc(String *dest, char *src){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
|
|
|
i32_4tech memory_size = dest->memory_size;
|
2016-07-06 19:18:10 +00:00
|
|
|
char *dest_str = dest->str;
|
|
|
|
while (src[i] != 0){
|
|
|
|
if (i >= memory_size){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dest_str[i] = src[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
dest->size = i;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
copy_partial_ss(String *dest, String src){
|
2016-07-06 19:18:10 +00:00
|
|
|
char *dest_str = dest->str;
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech memory_size = dest->memory_size;
|
|
|
|
b32_4tech result = 0;
|
2016-07-12 22:17:45 +00:00
|
|
|
if (memory_size >= src.size){
|
2016-08-28 04:31:06 +00:00
|
|
|
result = 1;
|
2016-07-12 22:17:45 +00:00
|
|
|
memory_size = src.size;
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
2017-01-23 06:19:43 +00:00
|
|
|
for (i32_4tech i = 0; i < memory_size; ++i){
|
2016-07-12 22:17:45 +00:00
|
|
|
dest_str[i] = src.str[i];
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
2016-07-12 22:17:45 +00:00
|
|
|
dest->size = memory_size;
|
2017-03-13 23:48:11 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-03-13 23:48:11 +00:00
|
|
|
copy_partial_cs(char *dest, i32_4tech dest_cap, String src){
|
|
|
|
b32_4tech result = 0;
|
|
|
|
i32_4tech copy_size = dest_cap;
|
|
|
|
i32_4tech i;
|
|
|
|
if (dest_cap >= src.size){
|
|
|
|
result = 1;
|
|
|
|
copy_size = src.size;
|
|
|
|
}
|
|
|
|
for (i = 0; i < copy_size; ++i){
|
|
|
|
dest[i] = src.str[i];
|
|
|
|
}
|
|
|
|
return(result);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
copy_cc(char *dest, char *src){
|
|
|
|
return copy_fast_unsafe_cc(dest, src);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE void
|
2016-08-28 04:31:06 +00:00
|
|
|
copy_ss(String *dest, String src){
|
|
|
|
copy_checked_ss(dest, src);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE void
|
2016-08-28 04:31:06 +00:00
|
|
|
copy_sc(String *dest, char *src){
|
|
|
|
copy_partial_sc(dest, src);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
append_checked_ss(String *dest, String src){
|
2016-07-06 19:18:10 +00:00
|
|
|
String end;
|
|
|
|
end = tailstr(*dest);
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = copy_checked_ss(&end, src);
|
2016-07-06 19:18:10 +00:00
|
|
|
// NOTE(allen): This depends on end.size still being 0 if
|
|
|
|
// the check failed and no coppy occurred.
|
|
|
|
dest->size += end.size;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
append_partial_sc(String *dest, char *src){
|
2016-07-06 19:18:10 +00:00
|
|
|
String end = tailstr(*dest);
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = copy_partial_sc(&end, src);
|
2016-07-06 19:18:10 +00:00
|
|
|
dest->size += end.size;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
append_partial_ss(String *dest, String src){
|
2016-07-06 19:18:10 +00:00
|
|
|
String end = tailstr(*dest);
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = copy_partial_ss(&end, src);
|
2016-07-06 19:18:10 +00:00
|
|
|
dest->size += end.size;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
append_s_char(String *dest, char c){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
if (dest->size < dest->memory_size){
|
|
|
|
dest->str[dest->size++] = c;
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
append_ss(String *dest, String src){
|
|
|
|
return append_partial_ss(dest, src);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
append_sc(String *dest, char *src){
|
|
|
|
return append_partial_sc(dest, src);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-07-12 22:17:45 +00:00
|
|
|
terminate_with_null(String *str){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
if (str->size < str->memory_size){
|
|
|
|
str->str[str->size] = 0;
|
|
|
|
result = 1;
|
|
|
|
}
|
2016-06-28 22:58:50 +00:00
|
|
|
return(result);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-28 22:58:50 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
append_padding(String *dest, char c, i32_4tech target_size){
|
|
|
|
b32_4tech result = 1;
|
|
|
|
i32_4tech offset = target_size - dest->size;
|
|
|
|
i32_4tech r = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
if (offset > 0){
|
|
|
|
for (r = 0; r < offset; ++r){
|
2016-08-28 04:31:06 +00:00
|
|
|
if (append_s_char(dest, c) == 0){
|
2016-07-06 19:18:10 +00:00
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-28 22:58:50 +00:00
|
|
|
return(result);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-28 22:58:50 +00:00
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Other Edits
|
|
|
|
//
|
|
|
|
|
2018-05-08 07:14:23 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
|
|
|
FSTRING_LINK void
|
|
|
|
string_interpret_escapes(String src, char *dst){
|
|
|
|
i32_4tech mode = 0;
|
|
|
|
i32_4tech j = 0;
|
|
|
|
for (i32_4tech i = 0; i < src.size; ++i){
|
|
|
|
switch (mode){
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
if (src.str[i] == '\\'){
|
|
|
|
mode = 1;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
dst[j++] = src.str[i];
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
2018-06-10 02:28:22 +00:00
|
|
|
char c = src.str[i];
|
|
|
|
switch (c){
|
|
|
|
case '\\':{dst[j++] = '\\';} break;
|
|
|
|
case 'n': {dst[j++] = '\n';} break;
|
|
|
|
case 't': {dst[j++] = '\t';} break;
|
|
|
|
case '"': {dst[j++] = '"'; } break;
|
|
|
|
case '0': {dst[j++] = '\0';} break;
|
|
|
|
default: {dst[j++] = '\\'; dst[j++] = c;}break;
|
2018-05-08 07:14:23 +00:00
|
|
|
}
|
2018-06-10 02:28:22 +00:00
|
|
|
mode = 0;
|
2018-05-08 07:14:23 +00:00
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst[j] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK void
|
2016-07-06 19:18:10 +00:00
|
|
|
replace_char(String *str, char replace, char with){
|
|
|
|
char *s = str->str;
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
2016-07-06 19:18:10 +00:00
|
|
|
for (i = 0; i < str->size; ++i, ++s){
|
|
|
|
if (*s == replace) *s = with;
|
|
|
|
}
|
2016-06-28 22:58:50 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-28 22:58:50 +00:00
|
|
|
|
2017-11-09 18:30:24 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
|
|
|
void
|
|
|
|
block_move(void *a_ptr, void *b_ptr, i32_4tech s){
|
|
|
|
u8_4tech *a = (u8_4tech*)a_ptr;
|
|
|
|
u8_4tech *b = (u8_4tech*)b_ptr;
|
|
|
|
if (a < b){
|
|
|
|
for (i32_4tech i = 0; i < s; ++i, ++a, ++b){
|
|
|
|
*a = *b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (a > b){
|
|
|
|
a = a + s - 1;
|
|
|
|
b = b + s - 1;
|
|
|
|
for (i32_4tech i = 0; i < s; ++i, --a, --b){
|
|
|
|
*a = *b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
replace_range_str(String *str, i32_4tech first, i32_4tech one_past_last, String with){
|
|
|
|
i32_4tech shift = with.size - (one_past_last - first);
|
|
|
|
i32_4tech new_size = str->size + shift;
|
|
|
|
if (new_size <= str->memory_size){
|
|
|
|
if (shift != 0){
|
|
|
|
char *tail = str->str + one_past_last;
|
|
|
|
char *new_tail_pos = tail + shift;
|
|
|
|
block_move(new_tail_pos, tail, str->size - one_past_last);
|
|
|
|
}
|
|
|
|
block_move(str->str + first, with.str, with.size);
|
|
|
|
str->size += shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
|
|
|
FSTRING_LINK void
|
|
|
|
replace_str_ss(String *str, String replace, String with){
|
|
|
|
i32_4tech i = 0;
|
|
|
|
for (;;){
|
|
|
|
i = find_substr_s(*str, i, replace);
|
|
|
|
if (i >= str->size){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
replace_range_str(str, i, i + replace.size, with);
|
|
|
|
i += with.size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
|
|
|
FSTRING_LINK void
|
|
|
|
replace_str_sc(String *str, String replace, char *with){
|
|
|
|
String w = make_string_slowly(with);
|
|
|
|
replace_str_ss(str, replace, w);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
|
|
|
FSTRING_LINK void
|
|
|
|
replace_str_cs(String *str, char *replace, String with){
|
|
|
|
String r = make_string_slowly(replace);
|
|
|
|
replace_str_ss(str, r, with);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
|
|
|
FSTRING_LINK void
|
|
|
|
replace_str_cc(String *str, char *replace, char *with){
|
|
|
|
String r = make_string_slowly(replace);
|
|
|
|
String w = make_string_slowly(with);
|
|
|
|
replace_str_ss(str, r, w);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-09-02 17:01:52 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK void
|
2016-09-02 17:01:52 +00:00
|
|
|
to_lower_cc(char *src, char *dst){
|
|
|
|
for (; *src != 0; ++src){
|
|
|
|
*dst++ = char_to_lower(*src);
|
|
|
|
}
|
|
|
|
*dst++ = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK void
|
2016-09-04 01:44:12 +00:00
|
|
|
to_lower_ss(String *dst, String src){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
|
|
|
i32_4tech size = src.size;
|
2016-09-04 01:44:12 +00:00
|
|
|
char *c = src.str;
|
2016-09-02 17:01:52 +00:00
|
|
|
char *d = dst->str;
|
|
|
|
|
|
|
|
if (dst->memory_size >= size){
|
|
|
|
for (; i < size; ++i){
|
|
|
|
*d++ = char_to_lower(*c++);
|
|
|
|
}
|
2016-09-04 01:44:12 +00:00
|
|
|
dst->size = size;
|
2016-09-02 17:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK void
|
2016-09-02 17:01:52 +00:00
|
|
|
to_lower_s(String *str){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
|
|
|
i32_4tech size = str->size;
|
2016-09-02 17:01:52 +00:00
|
|
|
char *c = str->str;
|
|
|
|
for (; i < size; ++c, ++i){
|
|
|
|
*c = char_to_lower(*c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK void
|
2016-09-02 17:01:52 +00:00
|
|
|
to_upper_cc(char *src, char *dst){
|
|
|
|
for (; *src != 0; ++src){
|
|
|
|
*dst++ = char_to_upper(*src);
|
|
|
|
}
|
|
|
|
*dst++ = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK void
|
2016-09-04 01:44:12 +00:00
|
|
|
to_upper_ss(String *dst, String src){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
|
|
|
i32_4tech size = src.size;
|
2016-09-04 01:44:12 +00:00
|
|
|
char *c = src.str;
|
2016-09-02 17:01:52 +00:00
|
|
|
char *d = dst->str;
|
|
|
|
|
|
|
|
if (dst->memory_size >= size){
|
|
|
|
for (; i < size; ++i){
|
|
|
|
*d++ = char_to_upper(*c++);
|
|
|
|
}
|
2016-09-04 01:44:12 +00:00
|
|
|
dst->size = size;
|
2016-09-02 17:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK void
|
2016-09-02 17:01:52 +00:00
|
|
|
to_upper_s(String *str){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i = 0;
|
|
|
|
i32_4tech size = str->size;
|
2016-09-02 17:01:52 +00:00
|
|
|
char *c = str->str;
|
|
|
|
for (; i < size; ++c, ++i){
|
|
|
|
*c = char_to_upper(*c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-09-02 19:39:38 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK void
|
2016-09-02 19:39:38 +00:00
|
|
|
to_camel_cc(char *src, char *dst){
|
|
|
|
char *c, ch;
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech is_first = 1;
|
2016-09-02 19:39:38 +00:00
|
|
|
for (c = src; *c != 0; ++c){
|
|
|
|
ch = *c;
|
|
|
|
if (char_is_alpha_numeric_true(ch)){
|
|
|
|
if (is_first){
|
|
|
|
is_first = 0;
|
|
|
|
ch = char_to_upper(ch);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
ch = char_to_lower(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
is_first = 1;
|
|
|
|
}
|
|
|
|
*dst++ = ch;
|
|
|
|
}
|
|
|
|
*dst = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
//
|
|
|
|
// String <-> Number Conversions
|
|
|
|
//
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
int_to_str_size(i32_4tech x){
|
|
|
|
i32_4tech size = 1;
|
2016-02-01 05:03:42 +00:00
|
|
|
if (x < 0){
|
2016-06-07 16:26:11 +00:00
|
|
|
size = 2;
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-06-07 16:26:11 +00:00
|
|
|
x /= 10;
|
|
|
|
while (x != 0){
|
2016-02-01 05:03:42 +00:00
|
|
|
x /= 10;
|
2016-06-07 16:26:11 +00:00
|
|
|
++size;
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-06-07 16:26:11 +00:00
|
|
|
return(size);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
int_to_str(String *dest, i32_4tech x){
|
|
|
|
b32_4tech result = 1;
|
2016-06-07 16:26:11 +00:00
|
|
|
char *str = dest->str;
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech memory_size = dest->memory_size;
|
|
|
|
i32_4tech size, i, j;
|
|
|
|
b32_4tech negative;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
if (x == 0){
|
|
|
|
str[0] = '0';
|
2016-06-07 16:26:11 +00:00
|
|
|
dest->size = 1;
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
size = 0;
|
|
|
|
negative = 0;
|
|
|
|
if (x < 0){
|
|
|
|
negative = 1;
|
|
|
|
x = -x;
|
|
|
|
str[size++] = '-';
|
|
|
|
}
|
|
|
|
while (x != 0){
|
2016-06-07 16:26:11 +00:00
|
|
|
if (size == memory_size){
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
}
|
2016-02-01 05:03:42 +00:00
|
|
|
i = x % 10;
|
|
|
|
x /= 10;
|
|
|
|
str[size++] = (char)('0' + i);
|
|
|
|
}
|
2016-06-07 16:26:11 +00:00
|
|
|
if (result){
|
2017-01-23 06:19:43 +00:00
|
|
|
// NOTE(allen): Start i = 0 if not negative, start i = 1 if is negative because - should not be flipped if it is negative :)
|
2016-06-07 16:26:11 +00:00
|
|
|
for (i = negative, j = size-1; i < j; ++i, --j){
|
|
|
|
char temp = str[i];
|
|
|
|
str[i] = str[j];
|
|
|
|
str[j] = temp;
|
|
|
|
}
|
|
|
|
dest->size = size;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
dest->size = 0;
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-07 16:26:11 +00:00
|
|
|
return(result);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-07 16:26:11 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
append_int_to_str(String *dest, i32_4tech x){
|
2016-06-07 16:26:11 +00:00
|
|
|
String last_part = tailstr(*dest);
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = int_to_str(&last_part, x);
|
2016-06-07 16:26:11 +00:00
|
|
|
if (result){
|
|
|
|
dest->size += last_part.size;
|
|
|
|
}
|
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-06-07 16:26:11 +00:00
|
|
|
u64_to_str_size(uint64_t x){
|
2017-06-27 01:11:23 +00:00
|
|
|
i32_4tech size = 1;
|
|
|
|
x /= 10;
|
|
|
|
while (x != 0){
|
2016-06-07 16:26:11 +00:00
|
|
|
x /= 10;
|
2017-06-27 01:11:23 +00:00
|
|
|
++size;
|
2016-06-07 16:26:11 +00:00
|
|
|
}
|
|
|
|
return(size);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-07 16:26:11 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-06-07 16:26:11 +00:00
|
|
|
u64_to_str(String *dest, uint64_t x){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 1;
|
2016-02-01 05:03:42 +00:00
|
|
|
char *str = dest->str;
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech memory_size = dest->memory_size;
|
|
|
|
i32_4tech size, i, j;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
if (x == 0){
|
|
|
|
str[0] = '0';
|
|
|
|
dest->size = 1;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
size = 0;
|
|
|
|
while (x != 0){
|
|
|
|
if (size == memory_size){
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i = x % 10;
|
|
|
|
x /= 10;
|
|
|
|
str[size++] = (char)('0' + i);
|
|
|
|
}
|
|
|
|
if (result){
|
2016-06-07 16:26:11 +00:00
|
|
|
for (i = 0, j = size-1; i < j; ++i, --j){
|
2016-02-01 05:03:42 +00:00
|
|
|
char temp = str[i];
|
|
|
|
str[i] = str[j];
|
|
|
|
str[j] = temp;
|
|
|
|
}
|
|
|
|
dest->size = size;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
dest->size = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-06-07 16:26:11 +00:00
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-06-07 16:26:11 +00:00
|
|
|
append_u64_to_str(String *dest, uint64_t x){
|
2016-02-01 05:03:42 +00:00
|
|
|
String last_part = tailstr(*dest);
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = u64_to_str(&last_part, x);
|
2016-02-01 05:03:42 +00:00
|
|
|
if (result){
|
|
|
|
dest->size += last_part.size;
|
|
|
|
}
|
2016-06-07 16:26:11 +00:00
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2016-08-28 04:31:06 +00:00
|
|
|
typedef struct Float_To_Str_Variables{
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech negative;
|
|
|
|
i32_4tech int_part;
|
|
|
|
i32_4tech dec_part;
|
2016-08-28 04:31:06 +00:00
|
|
|
} Float_To_Str_Variables;
|
2016-06-10 03:20:45 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
static Float_To_Str_Variables
|
2016-06-10 03:20:45 +00:00
|
|
|
get_float_vars(float x){
|
2018-11-20 08:18:54 +00:00
|
|
|
Float_To_Str_Variables vars = {};
|
2016-06-10 03:20:45 +00:00
|
|
|
|
|
|
|
if (x < 0){
|
2016-08-28 04:31:06 +00:00
|
|
|
vars.negative = 1;
|
2016-06-10 03:20:45 +00:00
|
|
|
x = -x;
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
vars.int_part = (i32_4tech)(x);
|
|
|
|
vars.dec_part = (i32_4tech)((x - vars.int_part) * 1000);
|
2016-06-10 03:20:45 +00:00
|
|
|
|
|
|
|
return(vars);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-10 03:20:45 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-06-10 03:20:45 +00:00
|
|
|
float_to_str_size(float x){
|
|
|
|
Float_To_Str_Variables vars = get_float_vars(x);
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part);
|
2016-06-10 03:20:45 +00:00
|
|
|
return(size);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-10 03:20:45 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-06-10 03:20:45 +00:00
|
|
|
append_float_to_str(String *dest, float x){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 1;
|
2016-06-10 03:20:45 +00:00
|
|
|
Float_To_Str_Variables vars = get_float_vars(x);
|
|
|
|
|
|
|
|
if (vars.negative){
|
2016-08-28 04:31:06 +00:00
|
|
|
append_s_char(dest, '-');
|
2016-06-10 03:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
append_int_to_str(dest, vars.int_part);
|
2016-08-28 04:31:06 +00:00
|
|
|
append_s_char(dest, '.');
|
2016-06-10 03:20:45 +00:00
|
|
|
append_int_to_str(dest, vars.dec_part);
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-10 03:20:45 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-06-10 03:20:45 +00:00
|
|
|
float_to_str(String *dest, float x){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 1;
|
2016-06-10 03:20:45 +00:00
|
|
|
dest->size = 0;
|
|
|
|
append_float_to_str(dest, x);
|
|
|
|
return(result);
|
2016-07-14 16:41:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
str_is_int_c(char *str){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 1;
|
2016-08-28 04:31:06 +00:00
|
|
|
for (; *str; ++str){
|
|
|
|
if (!char_is_numeric(*str)){
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
str_is_int_s(String str){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 1;
|
|
|
|
for (i32_4tech i = 0; i < str.size; ++i){
|
2016-07-14 16:41:23 +00:00
|
|
|
if (!char_is_numeric(str.str[i])){
|
2016-08-28 04:31:06 +00:00
|
|
|
result = 0;
|
2016-07-14 16:41:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
2016-06-10 03:20:45 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-06-10 03:20:45 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
str_to_int_c(char *str){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech x = 0;
|
2016-02-01 05:03:42 +00:00
|
|
|
for (; *str; ++str){
|
2016-08-31 15:10:22 +00:00
|
|
|
if (*str >= '0' && *str <= '9'){
|
2016-02-01 05:03:42 +00:00
|
|
|
x *= 10;
|
|
|
|
x += *str - '0';
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
x = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(x);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
str_to_int_s(String str){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech x, i;
|
2016-02-01 05:03:42 +00:00
|
|
|
if (str.size == 0){
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
x = str.str[0] - '0';
|
|
|
|
for (i = 1; i < str.size; ++i){
|
|
|
|
x *= 10;
|
|
|
|
x += str.str[i] - '0';
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
return(x);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2016-02-01 05:03:42 +00:00
|
|
|
hexchar_to_int(char c){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech x = 0;
|
2016-02-01 05:03:42 +00:00
|
|
|
if (c >= '0' && c <= '9'){
|
|
|
|
x = c-'0';
|
|
|
|
}
|
|
|
|
else if (c > 'F'){
|
|
|
|
x = c+(10-'a');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
x = c+(10-'A');
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
return(x);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK char
|
2017-01-23 06:19:43 +00:00
|
|
|
int_to_hexchar(i32_4tech x){
|
2016-02-01 05:03:42 +00:00
|
|
|
return (x<10)?((char)x+'0'):((char)x+'a'-10);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK u32_4tech
|
2016-02-01 05:03:42 +00:00
|
|
|
hexstr_to_int(String str){
|
2017-01-23 06:19:43 +00:00
|
|
|
u32_4tech x;
|
|
|
|
i32_4tech i;
|
2016-02-01 05:03:42 +00:00
|
|
|
if (str.size == 0){
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
x = hexchar_to_int(str.str[0]);
|
|
|
|
for (i = 1; i < str.size; ++i){
|
|
|
|
x *= 0x10;
|
|
|
|
x += hexchar_to_int(str.str[i]);
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
return(x);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
color_to_hexstr(String *s, u32_4tech color){
|
|
|
|
b32_4tech result = 0;
|
|
|
|
i32_4tech i;
|
2016-04-29 20:57:54 +00:00
|
|
|
|
|
|
|
if (s->memory_size == 7 || s->memory_size == 8){
|
|
|
|
result = 1;
|
|
|
|
s->size = 6;
|
|
|
|
s->str[6] = 0;
|
|
|
|
color = color & 0x00FFFFFF;
|
|
|
|
for (i = 5; i >= 0; --i){
|
|
|
|
s->str[i] = int_to_hexchar(color & 0xF);
|
|
|
|
color >>= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (s->memory_size > 8){
|
|
|
|
result = 1;
|
|
|
|
s->size = 8;
|
|
|
|
s->str[8] = 0;
|
|
|
|
for (i = 7; i >= 0; --i){
|
|
|
|
s->str[i] = int_to_hexchar(color & 0xF);
|
|
|
|
color >>= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-04-29 20:57:54 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
hexstr_to_color(String s, u32_4tech *out){
|
|
|
|
b32_4tech result = 0;
|
|
|
|
u32_4tech color = 0;
|
2016-04-29 20:57:54 +00:00
|
|
|
if (s.size == 6){
|
|
|
|
result = 1;
|
2017-01-23 06:19:43 +00:00
|
|
|
color = (u32_4tech)hexstr_to_int(s);
|
2016-04-29 20:57:54 +00:00
|
|
|
color |= (0xFF << 24);
|
|
|
|
*out = color;
|
|
|
|
}
|
|
|
|
else if (s.size == 8){
|
|
|
|
result = 1;
|
2017-01-23 06:19:43 +00:00
|
|
|
color = (u32_4tech)hexstr_to_int(s);
|
2016-04-29 20:57:54 +00:00
|
|
|
*out = color;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-04-29 20:57:54 +00:00
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
//
|
|
|
|
// Directory String Management
|
|
|
|
//
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK i32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
reverse_seek_slash_pos(String str, i32_4tech pos){
|
|
|
|
i32_4tech i = str.size - 1 - pos;
|
2016-07-12 22:17:45 +00:00
|
|
|
while (i >= 0 && !char_is_slash(str.str[i])){
|
2016-02-01 05:03:42 +00:00
|
|
|
--i;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE i32_4tech
|
2016-02-01 05:03:42 +00:00
|
|
|
reverse_seek_slash(String str){
|
2016-08-28 04:31:06 +00:00
|
|
|
return(reverse_seek_slash_pos(str, 0));
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE String
|
2016-07-06 19:18:10 +00:00
|
|
|
front_of_directory(String dir){
|
2016-08-28 04:31:06 +00:00
|
|
|
return substr_tail(dir, reverse_seek_slash(dir) + 1);
|
2016-07-06 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_INLINE String
|
2016-07-06 19:18:10 +00:00
|
|
|
path_of_directory(String dir){
|
|
|
|
return substr(dir, 0, reverse_seek_slash(dir) + 1);
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
set_last_folder_sc(String *dir, char *folder_name, char slash){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 0;
|
|
|
|
i32_4tech size = reverse_seek_slash(*dir) + 1;
|
2016-02-01 05:03:42 +00:00
|
|
|
dir->size = size;
|
2016-08-28 04:31:06 +00:00
|
|
|
if (append_sc(dir, folder_name)){
|
|
|
|
if (append_s_char(dir, slash)){
|
2016-02-01 05:03:42 +00:00
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!result){
|
|
|
|
dir->size = size;
|
|
|
|
}
|
2016-08-28 04:31:06 +00:00
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-08-28 04:31:06 +00:00
|
|
|
set_last_folder_ss(String *dir, String folder_name, char slash){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 0;
|
|
|
|
i32_4tech size = reverse_seek_slash(*dir) + 1;
|
2016-02-01 05:03:42 +00:00
|
|
|
dir->size = size;
|
2016-08-28 04:31:06 +00:00
|
|
|
if (append_ss(dir, folder_name)){
|
|
|
|
if (append_s_char(dir, slash)){
|
2016-02-01 05:03:42 +00:00
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!result){
|
|
|
|
dir->size = size;
|
|
|
|
}
|
2016-08-28 04:31:06 +00:00
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2016-02-01 05:03:42 +00:00
|
|
|
file_extension(String str){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i;
|
2016-02-01 05:03:42 +00:00
|
|
|
for (i = str.size - 1; i >= 0; --i){
|
|
|
|
if (str.str[i] == '.') break;
|
|
|
|
}
|
|
|
|
++i;
|
2016-08-28 04:31:06 +00:00
|
|
|
return(make_string(str.str+i, str.size-i));
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-09-02 15:58:04 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-09-02 15:58:04 +00:00
|
|
|
remove_extension(String *str){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 0;
|
|
|
|
i32_4tech i;
|
2016-09-02 15:58:04 +00:00
|
|
|
for (i = str->size - 1; i >= 0; --i){
|
|
|
|
if (str->str[i] == '.') break;
|
|
|
|
}
|
|
|
|
if (i >= 0){
|
|
|
|
result = 1;
|
|
|
|
str->size = i + 1;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2016-02-01 05:03:42 +00:00
|
|
|
remove_last_folder(String *str){
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech result = 0;
|
|
|
|
i32_4tech end = reverse_seek_slash_pos(*str, 1);
|
2016-02-01 05:03:42 +00:00
|
|
|
if (end >= 0){
|
|
|
|
result = 1;
|
|
|
|
str->size = end + 1;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-09-03 21:04:55 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){
|
|
|
|
b32_4tech result = 0;
|
|
|
|
i32_4tech i = 0;
|
2016-09-03 21:04:55 +00:00
|
|
|
uint8_t *ptr = (uint8_t*)str_set;
|
|
|
|
for (; i < count; ++i, ptr += item_size){
|
|
|
|
if (match_ss(*(String*)ptr, str)){
|
2016-06-24 19:33:37 +00:00
|
|
|
*match_index = i;
|
2016-08-28 04:31:06 +00:00
|
|
|
result = 1;
|
2016-06-24 19:33:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-03 21:04:55 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK b32_4tech
|
2017-01-23 06:19:43 +00:00
|
|
|
string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index){
|
|
|
|
b32_4tech result = string_set_match_table(str_set, sizeof(String), count, str, match_index);
|
2016-09-03 21:04:55 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-05 02:59:35 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2016-11-05 02:59:35 +00:00
|
|
|
get_first_double_line(String source){
|
2018-11-20 08:18:54 +00:00
|
|
|
String line = {};
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech pos0 = find_substr_s(source, 0, make_lit_string("\n\n"));
|
|
|
|
i32_4tech pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n"));
|
2016-11-05 02:59:35 +00:00
|
|
|
if (pos1 < pos0){
|
|
|
|
pos0 = pos1;
|
|
|
|
}
|
|
|
|
line = substr(source, 0, pos0);
|
|
|
|
return(line);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2016-11-05 02:59:35 +00:00
|
|
|
get_next_double_line(String source, String line){
|
2018-11-20 08:18:54 +00:00
|
|
|
String next = {};
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech pos = (i32_4tech)(line.str - source.str) + line.size;
|
|
|
|
i32_4tech start = 0, pos0 = 0, pos1 = 0;
|
2016-11-05 02:59:35 +00:00
|
|
|
|
|
|
|
if (pos < source.size){
|
|
|
|
//Assert(source.str[pos] == '\n' || source.str[pos] == '\r');
|
|
|
|
start = pos + 1;
|
|
|
|
|
|
|
|
if (start < source.size){
|
|
|
|
pos0 = find_substr_s(source, start, make_lit_string("\n\n"));
|
|
|
|
pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n"));
|
|
|
|
if (pos1 < pos0){
|
|
|
|
pos0 = pos1;
|
|
|
|
}
|
|
|
|
next = substr(source, start, pos0 - start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(next);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2016-11-05 02:59:35 +00:00
|
|
|
get_next_word(String source, String prev_word){
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
String word = {};
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech pos0 = (i32_4tech)(prev_word.str - source.str) + prev_word.size;
|
|
|
|
i32_4tech pos1 = 0;
|
2016-11-05 02:59:35 +00:00
|
|
|
char c = 0;
|
|
|
|
|
|
|
|
for (; pos0 < source.size; ++pos0){
|
|
|
|
c = source.str[pos0];
|
|
|
|
if (!(char_is_whitespace(c) || c == '(' || c == ')')){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos0 < source.size){
|
|
|
|
for (pos1 = pos0; pos1 < source.size; ++pos1){
|
|
|
|
c = source.str[pos1];
|
|
|
|
if (char_is_whitespace(c) || c == '(' || c == ')'){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
word = substr(source, pos0, pos1 - pos0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(word);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2017-07-17 18:12:28 +00:00
|
|
|
FSTRING_LINK String
|
2016-11-05 02:59:35 +00:00
|
|
|
get_first_word(String source){
|
|
|
|
String start_str = make_string(source.str, 0);
|
|
|
|
String word = get_next_word(source, start_str);
|
|
|
|
return(word);
|
|
|
|
}
|
|
|
|
#endif
|
2016-09-03 21:04:55 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
// TODO(allen): eliminate this.
|
2016-07-06 19:18:10 +00:00
|
|
|
#ifndef FSTRING_EXPERIMENTAL
|
|
|
|
#define FSTRING_EXPERIMENTAL
|
2016-06-24 19:33:37 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
// NOTE(allen): experimental section, things below here are
|
|
|
|
// not promoted to public API level yet.
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
typedef struct Absolutes{
|
2016-02-01 05:03:42 +00:00
|
|
|
String a[8];
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech count;
|
2016-08-28 04:31:06 +00:00
|
|
|
} Absolutes;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
static void
|
2017-01-23 06:19:43 +00:00
|
|
|
get_absolutes(String name, Absolutes *absolutes, b32_4tech implicit_first, b32_4tech implicit_last){
|
2017-01-03 20:05:35 +00:00
|
|
|
if (name.size != 0){
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech count = 0;
|
2017-01-29 00:03:23 +00:00
|
|
|
i32_4tech max = (sizeof(absolutes->a)/sizeof(*absolutes->a)) - 1;
|
2017-01-03 20:05:35 +00:00
|
|
|
if (implicit_last) --max;
|
|
|
|
|
|
|
|
String str;
|
|
|
|
str.str = name.str;
|
|
|
|
str.size = 0;
|
|
|
|
str.memory_size = 0;
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech prev_was_wild = 0;
|
2017-01-03 20:05:35 +00:00
|
|
|
|
|
|
|
if (implicit_first){
|
|
|
|
absolutes->a[count++] = str;
|
2016-02-01 05:03:42 +00:00
|
|
|
prev_was_wild = 1;
|
|
|
|
}
|
2017-01-03 20:05:35 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_4tech i;
|
2017-01-03 20:05:35 +00:00
|
|
|
for (i = 0; i < name.size; ++i){
|
|
|
|
if (name.str[i] == '*' && count < max){
|
|
|
|
if (!prev_was_wild){
|
|
|
|
str.memory_size = str.size;
|
|
|
|
absolutes->a[count++] = str;
|
|
|
|
str.size = 0;
|
|
|
|
}
|
|
|
|
str.str = name.str + i + 1;
|
|
|
|
prev_was_wild = 1;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
++str.size;
|
|
|
|
prev_was_wild = 0;
|
|
|
|
}
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
2017-01-03 20:05:35 +00:00
|
|
|
|
|
|
|
str.memory_size = str.size;
|
2016-02-01 05:03:42 +00:00
|
|
|
absolutes->a[count++] = str;
|
2017-01-03 20:05:35 +00:00
|
|
|
|
|
|
|
if (implicit_last){
|
|
|
|
str.size = 0;
|
|
|
|
str.memory_size = 0;
|
|
|
|
absolutes->a[count++] = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
absolutes->count = count;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
absolutes->count = 0;
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
static b32_4tech
|
|
|
|
wildcard_match_c(Absolutes *absolutes, char *x, i32_4tech case_sensitive){
|
|
|
|
b32_4tech r = 1;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2017-01-03 20:05:35 +00:00
|
|
|
if (absolutes->count > 0){
|
|
|
|
String *a = absolutes->a;
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
b32_4tech (*match_func)(char*, String);
|
|
|
|
b32_4tech (*match_part_func)(char*, String);
|
2017-01-03 20:05:35 +00:00
|
|
|
|
|
|
|
if (case_sensitive){
|
|
|
|
match_func = match_cs;
|
|
|
|
match_part_func = match_part_cs;
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-01-03 20:05:35 +00:00
|
|
|
match_func = match_insensitive_cs;
|
|
|
|
match_part_func = match_part_insensitive_cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (absolutes->count == 1){
|
|
|
|
r = match_func(x, *a);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (!match_part_func(x, *a)){
|
2016-02-01 05:03:42 +00:00
|
|
|
r = 0;
|
2017-01-03 20:05:35 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
String *max = a + absolutes->count - 1;
|
|
|
|
x += a->size;
|
|
|
|
++a;
|
|
|
|
while (a < max){
|
|
|
|
if (*x == 0){
|
|
|
|
r = 0;
|
2016-02-01 05:03:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-03 20:05:35 +00:00
|
|
|
if (match_part_func(x, *a)){
|
|
|
|
x += a->size;
|
|
|
|
++a;
|
|
|
|
}
|
2016-02-01 05:03:42 +00:00
|
|
|
else{
|
|
|
|
++x;
|
|
|
|
}
|
|
|
|
}
|
2017-01-03 20:05:35 +00:00
|
|
|
if (r && a->size > 0){
|
|
|
|
r = 0;
|
|
|
|
while (*x != 0){
|
|
|
|
if (match_part_func(x, *a) && *(x + a->size) == 0){
|
|
|
|
r = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
++x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-28 04:31:06 +00:00
|
|
|
return(r);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
static b32_4tech
|
|
|
|
wildcard_match_s(Absolutes *absolutes, String x, i32_4tech case_sensitive){
|
2016-02-01 05:03:42 +00:00
|
|
|
terminate_with_null(&x);
|
2016-08-28 04:31:06 +00:00
|
|
|
return(wildcard_match_c(absolutes, x.str, case_sensitive));
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if defined(FSTRING_IMPLEMENTATION)
|
2016-07-06 19:18:10 +00:00
|
|
|
#undef FSTRING_IMPLEMENTATION
|
2017-01-23 06:19:43 +00:00
|
|
|
#define FSTRING_IMPL_GUARD
|
2016-07-06 19:18:10 +00:00
|
|
|
#endif
|
2016-02-25 12:12:09 +00:00
|
|
|
|
2016-08-28 04:31:06 +00:00
|
|
|
#if !defined(FSTRING_GUARD)
|
2016-07-06 19:18:10 +00:00
|
|
|
#define FSTRING_GUARD
|
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|