diff --git a/4coder_API.html b/4coder_API.html index 241285c6..db1d65bd 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -22,7 +22,7 @@ ul { list-style: none; padding: 0; margin: 0; }

§1 Introduction

-This is the documentation for alpha 4.0.10 super! The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.

+This is the documentation for alpha 4.0.10 The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.

If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network

@@ -550,7 +550,7 @@ the filename does not correspond to a file on disk the buffer is created empty.<
flags
The flags parameter specifies behaviors for the buffer kill.
-
Return
This call returns non-zero on success.
Description
Tries to kill the idenfied buffer. If the buffer is dirty and the "are you sure" +
Return
This call returns non-zero if the buffer is killed.
Description
Tries to kill the idenfied buffer. If the buffer is dirty and the "are you sure" dialogue needs to be displayed the provided view is used to show the dialogue. If the view is not open the kill fails.
See Also
Buffer_Kill_Flag
Buffer_Identifier

@@ -2285,35 +2285,70 @@ Coming Soon
  • char_is_hex
  • char_is_numeric
  • string_zero
  • +
  • make_string_cap
  • make_string
  • make_lit_string
  • make_fixed_width_string
  • expand_str
  • str_size
  • make_string_slowly
  • +
  • substr_tail
  • substr
  • skip_whitespace
  • chop_whitespace
  • skip_chop_whitespace
  • tailstr
  • -
  • match
  • -
  • match_part
  • -
  • match_insensitive
  • -
  • match_part_insensitive
  • -
  • compare
  • -
  • find
  • -
  • find_substr
  • -
  • rfind_substr
  • -
  • find_substr_insensitive
  • -
  • has_substr
  • -
  • has_substr_insensitive
  • -
  • copy_fast_unsafe
  • -
  • copy_checked
  • -
  • copy_partial
  • -
  • copy
  • -
  • append_checked
  • -
  • append_partial
  • -
  • append
  • +
  • match_cc
  • +
  • match_sc
  • +
  • match_cs
  • +
  • match_ss
  • +
  • match_part_ccl
  • +
  • match_part_scl
  • +
  • match_part_cc
  • +
  • match_part_sc
  • +
  • match_part_cs
  • +
  • match_part_ss
  • +
  • match_insensitive_cc
  • +
  • match_insensitive_sc
  • +
  • match_insensitive_cs
  • +
  • match_insensitive_ss
  • +
  • match_part_insensitive_ccl
  • +
  • match_part_insensitive_scl
  • +
  • match_part_insensitive_cc
  • +
  • match_part_insensitive_sc
  • +
  • match_part_insensitive_cs
  • +
  • match_part_insensitive_ss
  • +
  • compare_cc
  • +
  • compare_sc
  • +
  • compare_cs
  • +
  • compare_ss
  • +
  • find_c_char
  • +
  • find_s_char
  • +
  • find_c_chars
  • +
  • find_s_chars
  • +
  • find_substr_c
  • +
  • find_substr_s
  • +
  • rfind_substr_s
  • +
  • find_substr_insensitive_c
  • +
  • find_substr_insensitive_s
  • +
  • has_substr_c
  • +
  • has_substr_s
  • +
  • has_substr_insensitive_c
  • +
  • has_substr_insensitive_s
  • +
  • copy_fast_unsafe_cc
  • +
  • copy_fast_unsafe_cs
  • +
  • copy_checked_ss
  • +
  • copy_partial_sc
  • +
  • copy_partial_ss
  • +
  • copy_cc
  • +
  • copy_ss
  • +
  • copy_sc
  • +
  • append_checked_ss
  • +
  • append_partial_sc
  • +
  • append_partial_ss
  • +
  • append_s_char
  • +
  • append_ss
  • +
  • append_sc
  • terminate_with_null
  • append_padding
  • replace_char
  • @@ -2326,17 +2361,21 @@ Coming Soon
  • float_to_str_size
  • append_float_to_str
  • float_to_str
  • -
  • str_is_int
  • -
  • str_to_int
  • +
  • str_is_int_c
  • +
  • str_is_int_s
  • +
  • str_to_int_c
  • +
  • str_to_int_s
  • hexchar_to_int
  • int_to_hexchar
  • hexstr_to_int
  • color_to_hexstr
  • hexstr_to_color
  • +
  • reverse_seek_slash_pos
  • reverse_seek_slash
  • front_of_directory
  • path_of_directory
  • -
  • set_last_folder
  • +
  • set_last_folder_sc
  • +
  • set_last_folder_ss
  • file_extension
  • remove_last_folder
  • string_set_match
  • @@ -2406,12 +2445,12 @@ fstr_bool char_is_numeric(

    §4.3.11: string_zero

    String string_zero( -

    ) +
    void
    )
    Description
    This call returns a String struct of zeroed members.

    -

    §4.3.12: make_string

    +

    §4.3.12: make_string_cap

    -String make_string( +String make_string_cap(
    void *str,
    int32_t size,
    int32_t mem_size
    )
    Parameters
    @@ -2428,7 +2467,7 @@ If the memory does not already contain a useful string this should be zero.
    The mem_size parameter expresses the full size of the memory provided by str.
    Description
    This call returns the String created from the parameters.

    -

    §4.3.13: make_string

    +

    §4.3.13: make_string

    String make_string(
    void *str,
    int32_t size
    ) @@ -2473,15 +2512,15 @@ String make_string_slowly(
    Description
    This call makes a string by counting the number of bytes before a null terminator and treating that as the size and memory size of the string.

    -

    §4.3.19: substr

    +

    §4.3.19: substr_tail

    -String substr( +String substr_tail(
    String str,
    int32_t start
    )
    Description
    This call creates a substring of str that starts with an offset from str's base. The new string uses the same underlying memory so both strings will see changes. Usually strings created this way should only go through immutable calls.

    -

    §4.3.20: substr

    +

    §4.3.20: substr

    String substr(
    String str,
    int32_t start,
    int32_t size
    ) @@ -2518,33 +2557,33 @@ String tailstr(
    Description
    This call returns an empty String with underlying memory taken from the portion of str's memory that is not used.

    -

    §4.3.25: match

    +

    §4.3.25: match_cc

    -fstr_bool match( +fstr_bool match_cc(
    char *a,
    char *b
    )
    Description
    This call returns non-zero if a and b are equivalent.

    -

    §4.3.26: match

    +

    §4.3.26: match_sc

    -fstr_bool match( +fstr_bool match_sc(
    String a,
    char *b
    )
    Description
    This call returns non-zero if a and b are equivalent.

    -

    §4.3.27: match

    +

    §4.3.27: match_cs

    -fstr_bool match( +fstr_bool match_cs(
    char *a,
    String b
    )
    Description
    This call returns non-zero if a and b are equivalent.

    -

    §4.3.28: match

    +

    §4.3.28: match_ss

    -fstr_bool match( +fstr_bool match_ss(
    String a,
    String b
    )
    Description
    This call returns non-zero if a and b are equivalent.

    -

    §4.3.29: match_part

    +

    §4.3.29: match_part_ccl

    -fstr_bool match_part( +fstr_bool match_part_ccl(
    char *a,
    char *b,
    int32_t *len
    )
    Parameters
    @@ -2553,9 +2592,9 @@ fstr_bool match_part(
    Description
    This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.

    -

    §4.3.30: match_part

    +

    §4.3.30: match_part_scl

    -fstr_bool match_part( +fstr_bool match_part_scl(
    String a,
    char *b,
    int32_t *len
    )
    Parameters
    @@ -2564,9 +2603,9 @@ fstr_bool match_part(
    Description
    This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.

    -

    §4.3.31: match_part

    +

    §4.3.31: match_part_cc

    -fstr_bool match_part( +fstr_bool match_part_cc(
    char *a,
    char *b
    )
    Parameters
    @@ -2575,54 +2614,54 @@ fstr_bool match_part(
    Description
    This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.

    -

    §4.3.32: match_part

    +

    §4.3.32: match_part_sc

    -fstr_bool match_part( +fstr_bool match_part_sc(
    String a,
    char *b
    )
    Description
    This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.

    -

    §4.3.33: match_part

    +

    §4.3.33: match_part_cs

    -fstr_bool match_part( +fstr_bool match_part_cs(
    char *a,
    String b
    )
    Description
    This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.

    -

    §4.3.34: match_part

    +

    §4.3.34: match_part_ss

    -fstr_bool match_part( +fstr_bool match_part_ss(
    String a,
    String b
    )
    Description
    This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.

    -

    §4.3.35: match_insensitive

    +

    §4.3.35: match_insensitive_cc

    -fstr_bool match_insensitive( +fstr_bool match_insensitive_cc(
    char *a,
    char *b
    )
    Description
    This call returns non-zero if a and b are equivalent under case insensitive comparison.

    -

    §4.3.36: match_insensitive

    +

    §4.3.36: match_insensitive_sc

    -fstr_bool match_insensitive( +fstr_bool match_insensitive_sc(
    String a,
    char *b
    )
    Description
    This call returns non-zero if a and b are equivalent under case insensitive comparison.

    -

    §4.3.37: match_insensitive

    +

    §4.3.37: match_insensitive_cs

    -fstr_bool match_insensitive( +fstr_bool match_insensitive_cs(
    char *a,
    String b
    )
    Description
    This call returns non-zero if a and b are equivalent under case insensitive comparison.

    -

    §4.3.38: match_insensitive

    +

    §4.3.38: match_insensitive_ss

    -fstr_bool match_insensitive( +fstr_bool match_insensitive_ss(
    String a,
    String b
    )
    Description
    This call returns non-zero if a and b are equivalent under case insensitive comparison.

    -

    §4.3.39: match_part_insensitive

    +

    §4.3.39: match_part_insensitive_ccl

    -fstr_bool match_part_insensitive( +fstr_bool match_part_insensitive_ccl(
    char *a,
    char *b,
    int32_t *len
    )
    Parameters
    @@ -2630,9 +2669,9 @@ fstr_bool match_part_insensitive(
    If this call returns non-zero this parameter is used to output the length of b.
    Description
    This call performs the same partial matching rule as match_part under case insensitive comparison.
    See Also

    -

    §4.3.40: match_part_insensitive

    +

    §4.3.40: match_part_insensitive_scl

    -fstr_bool match_part_insensitive( +fstr_bool match_part_insensitive_scl(
    String a,
    char *b,
    int32_t *len
    )
    Parameters
    @@ -2640,65 +2679,65 @@ fstr_bool match_part_insensitive(
    If this call returns non-zero this parameter is used to output the length of b.
    Description
    This call performs the same partial matching rule as match_part under case insensitive comparison.
    See Also

    -

    §4.3.41: match_part_insensitive

    +

    §4.3.41: match_part_insensitive_cc

    -fstr_bool match_part_insensitive( +fstr_bool match_part_insensitive_cc(
    char *a,
    char *b
    )
    Description
    This call performs the same partial matching rule as match_part under case insensitive comparison.
    See Also

    -

    §4.3.42: match_part_insensitive

    +

    §4.3.42: match_part_insensitive_sc

    -fstr_bool match_part_insensitive( +fstr_bool match_part_insensitive_sc(
    String a,
    char *b
    )
    Description
    This call performs the same partial matching rule as match_part under case insensitive comparison.
    See Also

    -

    §4.3.43: match_part_insensitive

    +

    §4.3.43: match_part_insensitive_cs

    -fstr_bool match_part_insensitive( +fstr_bool match_part_insensitive_cs(
    char *a,
    String b
    )
    Description
    This call performs the same partial matching rule as match_part under case insensitive comparison.
    See Also

    -

    §4.3.44: match_part_insensitive

    +

    §4.3.44: match_part_insensitive_ss

    -fstr_bool match_part_insensitive( +fstr_bool match_part_insensitive_ss(
    String a,
    String b
    )
    Description
    This call performs the same partial matching rule as match_part under case insensitive comparison.
    See Also

    -

    §4.3.45: compare

    +

    §4.3.45: compare_cc

    -int32_t compare( +int32_t compare_cc(
    char *a,
    char *b
    )
    Description
    This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.

    -

    §4.3.46: compare

    +

    §4.3.46: compare_sc

    -int32_t compare( +int32_t compare_sc(
    String a,
    char *b
    )
    Description
    This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.

    -

    §4.3.47: compare

    +

    §4.3.47: compare_cs

    -int32_t compare( +int32_t compare_cs(
    char *a,
    String b
    )
    Description
    This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.

    -

    §4.3.48: compare

    +

    §4.3.48: compare_ss

    -int32_t compare( +int32_t compare_ss(
    String a,
    String b
    )
    Description
    This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.

    -

    §4.3.49: find

    +

    §4.3.49: find_c_char

    -int32_t find( +int32_t find_c_char(
    char *str,
    int32_t start,
    char character
    )
    Parameters
    @@ -2715,9 +2754,9 @@ int32_t find(
    Description
    This call returns the index of the first occurance of character, or the size of the string if the character is not found.

    -

    §4.3.50: find

    +

    §4.3.50: find_s_char

    -int32_t find( +int32_t find_s_char(
    String str,
    int32_t start,
    char character
    )
    Parameters
    @@ -2734,9 +2773,9 @@ int32_t find(
    Description
    This call returns the index of the first occurance of character, or the size of the string if the character is not found.

    -

    §4.3.51: find

    +

    §4.3.51: find_c_chars

    -int32_t find( +int32_t find_c_chars(
    char *str,
    int32_t start,
    char *characters
    )
    Parameters
    @@ -2753,9 +2792,9 @@ int32_t find(
    Description
    This call returns the index of the first occurance of a character in the characters array, or the size of the string if no such character is not found.

    -

    §4.3.52: find

    +

    §4.3.52: find_s_chars

    -int32_t find( +int32_t find_s_chars(
    String str,
    int32_t start,
    char *characters
    )
    Parameters
    @@ -2772,9 +2811,9 @@ int32_t find(
    Description
    This call returns the index of the first occurance of a character in the characters array, or the size of the string if no such character is not found.

    -

    §4.3.53: find_substr

    +

    §4.3.53: find_substr_c

    -int32_t find_substr( +int32_t find_substr_c(
    char *str,
    int32_t start,
    String seek
    )
    Parameters
    @@ -2791,9 +2830,9 @@ int32_t find_substr(
    Description
    This call returns the index of the first occurance of the seek substring in str or the size of str if no such substring in str is found.

    -

    §4.3.54: find_substr

    +

    §4.3.54: find_substr_s

    -int32_t find_substr( +int32_t find_substr_s(
    String str,
    int32_t start,
    String seek
    )
    Parameters
    @@ -2810,9 +2849,9 @@ int32_t find_substr(
    Description
    This call returns the index of the first occurance of the seek substring in str or the size of str if no such substring in str is found.

    -

    §4.3.55: rfind_substr

    +

    §4.3.55: rfind_substr_s

    -int32_t rfind_substr( +int32_t rfind_substr_s(
    String str,
    int32_t start,
    String seek
    )
    Parameters
    @@ -2829,9 +2868,9 @@ int32_t rfind_substr(
    Description
    This call returns the index of the last occurance of the seek substring in str or -1 if no such substring in str is found.

    -

    §4.3.56: find_substr_insensitive

    +

    §4.3.56: find_substr_insensitive_c

    -int32_t find_substr_insensitive( +int32_t find_substr_insensitive_c(
    char *str,
    int32_t start,
    String seek
    )
    Parameters
    @@ -2847,9 +2886,9 @@ int32_t find_substr_insensitive(
    The seek parameter provides a string to find in str.
    Description
    This call acts as find_substr under case insensitive comparison.
    See Also

    -

    §4.3.57: find_substr_insensitive

    +

    §4.3.57: find_substr_insensitive_s

    -int32_t find_substr_insensitive( +int32_t find_substr_insensitive_s(
    String str,
    int32_t start,
    String seek
    )
    Parameters
    @@ -2865,35 +2904,35 @@ int32_t find_substr_insensitive(
    The seek parameter provides a string to find in str.
    Description
    This call acts as find_substr under case insensitive comparison.
    See Also

    -

    §4.3.58: has_substr

    +

    §4.3.58: has_substr_c

    -fstr_bool has_substr( +fstr_bool has_substr_c(
    char *s,
    String seek
    )
    Description
    This call returns non-zero if the string s contains a substring equivalent to seek.

    -

    §4.3.59: has_substr

    +

    §4.3.59: has_substr_s

    -fstr_bool has_substr( +fstr_bool has_substr_s(
    String s,
    String seek
    )
    Description
    This call returns non-zero if the string s contains a substring equivalent to seek.

    -

    §4.3.60: has_substr_insensitive

    +

    §4.3.60: has_substr_insensitive_c

    -fstr_bool has_substr_insensitive( +fstr_bool has_substr_insensitive_c(
    char *s,
    String seek
    )
    Description
    This call returns non-zero if the string s contains a substring equivalent to seek under case insensitive comparison.

    -

    §4.3.61: has_substr_insensitive

    +

    §4.3.61: has_substr_insensitive_s

    -fstr_bool has_substr_insensitive( +fstr_bool has_substr_insensitive_s(
    String s,
    String seek
    )
    Description
    This call returns non-zero if the string s contains a substring equivalent to seek under case insensitive comparison.

    -

    §4.3.62: copy_fast_unsafe

    +

    §4.3.62: copy_fast_unsafe_cc

    -int32_t copy_fast_unsafe( +int32_t copy_fast_unsafe_cc(
    char *dest,
    char *src
    )
    Description
    This call performs a copy from the src buffer to the dest buffer. @@ -2901,9 +2940,9 @@ The copy does not stop until a null terminator is found in src. There is no safety against overrun so dest must be large enough to contain src. The null terminator is not written to dest. This call returns the number of bytes coppied to dest.

    -

    §4.3.63: copy_fast_unsafe

    +

    §4.3.63: copy_fast_unsafe_cs

    -int32_t copy_fast_unsafe( +int32_t copy_fast_unsafe_cs(
    char *dest,
    String src
    )
    Description
    This call performs a copy from the src string to the dest buffer. @@ -2911,87 +2950,87 @@ The copy does not stop until src.size characters are coppied. There is no safety against overrun so dest must be large enough to contain src. The null terminator is not written to dest. This call returns the number of bytes coppied to dest.

    -

    §4.3.64: copy_checked

    +

    §4.3.64: copy_checked_ss

    -fstr_bool copy_checked( +fstr_bool copy_checked_ss(
    String *dest,
    String src
    )
    Description
    This call performs a copy from the src string to the dest string. The memory_size of dest is checked before any coppying is done. This call returns non-zero on a successful copy.

    -

    §4.3.65: copy_partial

    +

    §4.3.65: copy_partial_sc

    -fstr_bool copy_partial( +fstr_bool copy_partial_sc(
    String *dest,
    char *src
    )
    Description
    This call performs a copy from the src buffer to the dest string. The memory_size of dest is checked if the entire copy cannot be performed, as many bytes as possible are coppied to dest. This call returns non-zero if the entire string is coppied to dest.

    -

    §4.3.66: copy_partial

    +

    §4.3.66: copy_partial_ss

    -fstr_bool copy_partial( +fstr_bool copy_partial_ss(
    String *dest,
    String src
    )
    Description
    This call performs a copy from the src string to the dest string. The memory_size of dest is checked if the entire copy cannot be performed, as many bytes as possible are coppied to dest. This call returns non-zero if the entire string is coppied to dest.

    -

    §4.3.67: copy

    +

    §4.3.67: copy_cc

    -int32_t copy( +int32_t copy_cc(
    char *dest,
    char *src
    )
    Description
    This call performs a copy from src to dest equivalent to copy_fast_unsafe.
    See Also

    -

    §4.3.68: copy

    +

    §4.3.68: copy_ss

    -void copy( +void copy_ss(
    String *dest,
    String src
    )
    Description
    This call performs a copy from src to dest equivalent to copy_checked.
    See Also

    -

    §4.3.69: copy

    +

    §4.3.69: copy_sc

    -void copy( +void copy_sc(
    String *dest,
    char *src
    )
    Description
    This call performs a copy from src to dest equivalent to copy_partial.
    See Also

    -

    §4.3.70: append_checked

    +

    §4.3.70: append_checked_ss

    -fstr_bool append_checked( +fstr_bool append_checked_ss(
    String *dest,
    String src
    )
    Description
    This call checks if there is enough space in dest's underlying memory to append src onto dest. If there is src is appended and the call returns non-zero.

    -

    §4.3.71: append_partial

    +

    §4.3.71: append_partial_sc

    -fstr_bool append_partial( +fstr_bool append_partial_sc(
    String *dest,
    char *src
    )
    Description
    This call attemps to append as much of src into the space in dest's underlying memory as possible. If the entire string is appended the call returns non-zero.

    -

    §4.3.72: append_partial

    +

    §4.3.72: append_partial_ss

    -fstr_bool append_partial( +fstr_bool append_partial_ss(
    String *dest,
    String src
    )
    Description
    This call attemps to append as much of src into the space in dest's underlying memory as possible. If the entire string is appended the call returns non-zero.

    -

    §4.3.73: append

    +

    §4.3.73: append_s_char

    -fstr_bool append( +fstr_bool append_s_char(
    String *dest,
    char c
    )
    Description
    This call attemps to append c onto dest. If there is space left in dest's underlying memory the character is appended and the call returns non-zero.

    -

    §4.3.74: append

    +

    §4.3.74: append_ss

    -fstr_bool append( +fstr_bool append_ss(
    String *dest,
    String src
    )
    Description
    This call is equivalent to append_partial.
    See Also

    -

    §4.3.75: append

    +

    §4.3.75: append_sc

    -fstr_bool append( +fstr_bool append_sc(
    String *dest,
    char *src
    )
    Description
    This call is equivalent to append_partial.
    See Also

    @@ -3090,89 +3129,95 @@ fstr_bool float_to_str(
    Description
    This call appends a string representation of x onto dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.88: str_is_int

    +

    §4.3.88: str_is_int_c

    -fstr_bool str_is_int( +int32_t str_is_int_c( +
    char *str
    ) +
    +
    Description
    If str is a valid string representation of an integer, this call returns non-zero

    +

    §4.3.89: str_is_int_s

    +
    +fstr_bool str_is_int_s(
    String str
    )
    Description
    If str is a valid string representation of an integer, this call returns non-zero.

    -

    §4.3.89: str_to_int

    +

    §4.3.90: str_to_int_c

    -int32_t str_to_int( +int32_t str_to_int_c(
    char *str
    )
    Description
    If str is a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.

    -

    §4.3.90: str_to_int

    +

    §4.3.91: str_to_int_s

    -int32_t str_to_int( +int32_t str_to_int_s(
    String str
    )
    Description
    If str represents a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.

    -

    §4.3.91: hexchar_to_int

    +

    §4.3.92: hexchar_to_int

    int32_t hexchar_to_int(
    char c
    )
    Description
    If c is a valid hexadecimal digit [0-9a-fA-F] this call returns the value of the integer value of the digit. Otherwise the return is some nonsense value.

    -

    §4.3.92: int_to_hexchar

    +

    §4.3.93: int_to_hexchar

    char int_to_hexchar(
    int32_t x
    )
    Description
    If x is in the range [0,15] this call returns the equivalent lowercase hexadecimal digit. Otherwise the return is some nonsense value.

    -

    §4.3.93: hexstr_to_int

    +

    §4.3.94: hexstr_to_int

    uint32_t hexstr_to_int(
    String str
    )
    Description
    This call interprets str has a hexadecimal representation of an integer and returns the represented integer value.

    -

    §4.3.94: color_to_hexstr

    +

    §4.3.95: color_to_hexstr

    fstr_bool color_to_hexstr(
    String *s,
    uint32_t color
    )
    Description
    This call fills s with the hexadecimal representation of the color. If there is enough memory in s to represent the color this call returns non-zero.

    -

    §4.3.95: hexstr_to_color

    +

    §4.3.96: hexstr_to_color

    fstr_bool hexstr_to_color(
    String s,
    uint32_t *out
    )
    Description
    This call interprets s as a color and writes the 32-bit integer representation into out.

    -

    §4.3.96: reverse_seek_slash

    +

    §4.3.97: reverse_seek_slash_pos

    -int32_t reverse_seek_slash( +int32_t reverse_seek_slash_pos(
    String str,
    int32_t pos
    )
    Description
    This call searches for a slash in str by starting pos bytes from the end and going backwards.

    -

    §4.3.97: reverse_seek_slash

    +

    §4.3.98: reverse_seek_slash

    int32_t reverse_seek_slash(
    String str
    )
    Description
    This call searches for a slash in str by starting at the end and going backwards.

    -

    §4.3.98: front_of_directory

    +

    §4.3.99: front_of_directory

    String front_of_directory(
    String dir
    )
    Description
    This call returns a substring of dir containing only the file name or folder name furthest to the right in the directory.
    See Also

    -

    §4.3.99: path_of_directory

    +

    §4.3.100: path_of_directory

    String path_of_directory(
    String dir
    )
    Description
    This call returns a substring of dir containing the whole path except for the final file or folder name.
    See Also

    -

    §4.3.100: set_last_folder

    +

    §4.3.101: set_last_folder_sc

    -fstr_bool set_last_folder( +fstr_bool set_last_folder_sc(
    String *dir,
    char *folder_name,
    char slash
    )
    Parameters
    @@ -3190,9 +3235,9 @@ at the end of the directory.
    Description
    This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.

    -

    §4.3.101: set_last_folder

    +

    §4.3.102: set_last_folder_ss

    -fstr_bool set_last_folder( +fstr_bool set_last_folder_ss(
    String *dir,
    String folder_name,
    char slash
    )
    Parameters
    @@ -3209,20 +3254,20 @@ fstr_bool set_last_folder(
    Description
    This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.

    -

    §4.3.102: file_extension

    +

    §4.3.103: file_extension

    String file_extension(
    String str
    )
    Description
    This call returns a substring containing only the file extension of the provided filename.
    See Also

    -

    §4.3.103: remove_last_folder

    +

    §4.3.104: remove_last_folder

    fstr_bool remove_last_folder(
    String *str
    )
    Description
    This call attemps to delete a folder or filename off the end of a path string. This call returns non-zero on success.

    -

    §4.3.104: string_set_match

    +

    §4.3.105: string_set_match

    fstr_bool string_set_match(
    String *str_set,
    int32_t count,
    String str,
    int32_t *match_index
    ) diff --git a/4coder_custom.dll b/4coder_custom.dll new file mode 100644 index 00000000..763668bc Binary files /dev/null and b/4coder_custom.dll differ diff --git a/4coder_custom.pdb b/4coder_custom.pdb new file mode 100644 index 00000000..3017c104 Binary files /dev/null and b/4coder_custom.pdb differ diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index bd96e05e..e215a8de 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -180,10 +180,10 @@ OPEN_FILE_HOOK_SIG(my_file_settings){ if (buffer.file_name && buffer.size < (16 << 20)){ String ext = file_extension(make_string(buffer.file_name, buffer.file_name_len)); - if (match(ext, make_lit_string("cpp"))) treat_as_code = 1; - else if (match(ext, make_lit_string("h"))) treat_as_code = 1; - else if (match(ext, make_lit_string("c"))) treat_as_code = 1; - else if (match(ext, make_lit_string("hpp"))) treat_as_code = 1; + if (match_ss(ext, make_lit_string("cpp"))) treat_as_code = 1; + else if (match_ss(ext, make_lit_string("h"))) treat_as_code = 1; + else if (match_ss(ext, make_lit_string("c"))) treat_as_code = 1; + else if (match_ss(ext, make_lit_string("hpp"))) treat_as_code = 1; } if (treat_as_code){ diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 420daefb..afd7b6ef 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -267,7 +267,7 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, char at_pos = stream.data[pos]; if (at_pos == first_char){ app->buffer_read_range(app, buffer, pos, pos+size, read_buffer); - if (match(needle_str, read_str)){ + if (match_ss(needle_str, read_str)){ *result = pos; goto finished; } @@ -322,7 +322,7 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, char at_pos = stream.data[pos]; if (at_pos == first_char){ app->buffer_read_range(app, buffer, pos, pos+size, read_buffer); - if (match(needle_str, read_str)){ + if (match_ss(needle_str, read_str)){ *result = pos; goto finished; } @@ -372,7 +372,7 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b char at_pos = char_to_upper(stream.data[pos]); if (at_pos == first_char){ app->buffer_read_range(app, buffer, pos, pos+size, read_buffer); - if (match_insensitive(needle_str, read_str)){ + if (match_insensitive_ss(needle_str, read_str)){ *result = pos; goto finished; } @@ -422,7 +422,7 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * char at_pos = char_to_upper(stream.data[pos]); if (at_pos == first_char){ app->buffer_read_range(app, buffer, pos, pos+size, read_buffer); - if (match_insensitive(needle_str, read_str)){ + if (match_insensitive_ss(needle_str, read_str)){ *result = pos; goto finished; } @@ -1556,9 +1556,9 @@ file_name_in_quotes(Application_Links *app, String *file_name){ if (size < sizeof(short_file_name)){ if (app->buffer_read_range(app, &buffer, start, end, short_file_name)){ result = true; - copy(file_name, make_string(buffer.file_name, buffer.file_name_len)); + copy_ss(file_name, make_string(buffer.file_name, buffer.file_name_len)); remove_last_folder(file_name); - append(file_name, make_string(short_file_name, size)); + append_ss(file_name, make_string(short_file_name, size)); } } @@ -1631,7 +1631,7 @@ CUSTOM_COMMAND_SIG(goto_line){ bar.string = make_fixed_width_string(string_space); if (query_user_number(app, &bar)){ - int line_number = str_to_int(bar.string); + int line_number = str_to_int_s(bar.string); active_view_to_line(app, access, line_number); } } @@ -1684,7 +1684,7 @@ isearch(Application_Links *app, int start_reversed){ break; } else if (in.key.character && key_is_unmodified(&in.key)){ - append(&bar.string, in.key.character); + append_s_char(&bar.string, in.key.character); made_change = 1; } else if (in.key.keycode == key_back){ @@ -1896,10 +1896,11 @@ CUSTOM_COMMAND_SIG(close_all_code){ app->get_buffer_next(app, &buffer, access)){ extension = file_extension(make_string(buffer.file_name, buffer.file_name_len)); - if (match(extension, make_lit_string("cpp")) || - match(extension, make_lit_string("hpp")) || - match(extension, make_lit_string("c")) || - match(extension, make_lit_string("h"))){ + if (match_ss(extension, make_lit_string("cpp")) || + match_ss(extension, make_lit_string("hpp")) || + match_ss(extension, make_lit_string("c")) || + match_ss(extension, make_lit_string("h")) || + match_ss(extension, make_lit_string("cc"))){ buffers_to_close[buffers_to_close_count++] = buffer.buffer_id; } @@ -1916,7 +1917,7 @@ CUSTOM_COMMAND_SIG(open_all_code){ // and doesn't set up a persistent allocation system within app->memory. // push_directory isn't a very good option since it's tied to the parameter // stack, so I am phasing that idea out now. - String dir = make_string(app->memory, 0, app->memory_size); + String dir = make_string_cap(app->memory, 0, app->memory_size); dir.size = app->directory_get_hot(app, dir.str, dir.memory_size); int dir_size = dir.size; @@ -1927,19 +1928,19 @@ CUSTOM_COMMAND_SIG(open_all_code){ for (int i = 0; i < list.count; ++i){ File_Info *info = list.infos + i; if (!info->folder){ - String extension = make_string(info->filename, info->filename_len, info->filename_len+1); + String extension = make_string_cap(info->filename, info->filename_len, info->filename_len+1); extension = file_extension(extension); - if (match(extension, make_lit_string("cpp")) || - match(extension, make_lit_string("hpp")) || - match(extension, make_lit_string("c")) || - match(extension, make_lit_string("h")) || - match(extension, make_lit_string("cc"))){ + if (match_ss(extension, make_lit_string("cpp")) || + match_ss(extension, make_lit_string("hpp")) || + match_ss(extension, make_lit_string("c")) || + match_ss(extension, make_lit_string("h")) || + match_ss(extension, make_lit_string("cc"))){ // NOTE(allen): There's no way in the 4coder API to use relative // paths at the moment, so everything should be full paths. Which is // managable. Here simply set the dir string size back to where it // was originally, so that new appends overwrite old ones. dir.size = dir_size; - append(&dir, info->filename); + append_sc(&dir, info->filename); app->create_buffer(app, dir.str, dir.size, 0); } } @@ -2016,12 +2017,12 @@ get_build_directory(Application_Links *app, Buffer_Summary *buffer, String *dir_ int result = BuildDir_None; if (buffer && buffer->file_name){ - if (!match(buffer->file_name, buffer->buffer_name)){ - String dir = make_string(buffer->file_name, - buffer->file_name_len, - buffer->file_name_len+1); + if (!match_cc(buffer->file_name, buffer->buffer_name)){ + String dir = make_string_cap(buffer->file_name, + buffer->file_name_len, + buffer->file_name_len+1); remove_last_folder(&dir); - append(dir_out, dir); + append_ss(dir_out, dir); result = BuildDir_AtFile; } } @@ -2051,26 +2052,26 @@ standard_build_search(Application_Links *app, for(;;){ int old_size = dir->size; - append(dir, filename); + append_ss(dir, filename); if (app->file_exists(app, dir->str, dir->size)){ dir->size = old_size; if (use_path_in_command){ - append(command, '"'); - append(command, *dir); - append(command, commandname); - append(command, '"'); + append_s_char(command, '"'); + append_ss(command, *dir); + append_ss(command, commandname); + append_s_char(command, '"'); } else{ - append(command, commandname); + append_ss(command, commandname); } char space[512]; String message = make_fixed_width_string(space); - append(&message, "Building with: "); - append(&message, *command); - append(&message, '\n'); + append_ss(&message, make_lit_string("Building with: ")); + append_ss(&message, *command); + append_s_char(&message, '\n'); app->print_message(app, message.str, message.size); @@ -2089,8 +2090,8 @@ standard_build_search(Application_Links *app, dir->size = app->directory_get_hot(app, dir->str, dir->memory_size); char backup_space[256]; String backup_command = make_fixed_width_string(backup_space); - append(&backup_command, make_lit_string("echo could not find ")); - append(&backup_command, filename); + append_ss(&backup_command, make_lit_string("echo could not find ")); + append_ss(&backup_command, filename); app->exec_system_command(app, view, buffer_identifier(literal("*compilation*")), dir->str, dir->size, @@ -2258,7 +2259,7 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part Search_Iter iter = {0}; search_iter_init(general, &iter, string.string.size); - copy(&iter.word, string.string); + copy_ss(&iter.word, string.string); int buffer_count = app->get_buffer_count(app); search_set_init(general, &set, buffer_count); @@ -2346,16 +2347,16 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part part_size += str_len; - String out_line = make_string(spare, 0, str_len); - append(&out_line, make_string(match.buffer.file_name, file_len)); - append(&out_line, ':'); + String out_line = make_string_cap(spare, 0, str_len); + append_ss(&out_line, make_string(match.buffer.file_name, file_len)); + append_s_char(&out_line, ':'); append_int_to_str(&out_line, word_pos.line); - append(&out_line, ':'); + append_s_char(&out_line, ':'); append_int_to_str(&out_line, word_pos.character); - append(&out_line, ':'); - append(&out_line, ' '); - append(&out_line, line_str); - append(&out_line, '\n'); + append_s_char(&out_line, ':'); + append_s_char(&out_line, ' '); + append_ss(&out_line, line_str); + append_s_char(&out_line, '\n'); end_temp_memory(line_temp); } @@ -2589,19 +2590,19 @@ CUSTOM_COMMAND_SIG(execute_arbitrary_command){ // is still available in bar.string though. app->end_query_bar(app, &bar, 0); - if (match(bar.string, make_lit_string("open all code"))){ + if (match_ss(bar.string, make_lit_string("open all code"))){ exec_command(app, open_all_code); } - else if(match(bar.string, make_lit_string("close all code"))){ + else if(match_ss(bar.string, make_lit_string("close all code"))){ exec_command(app, close_all_code); } - else if (match(bar.string, make_lit_string("open menu"))){ + else if (match_ss(bar.string, make_lit_string("open menu"))){ exec_command(app, cmdid_open_menu); } - else if (match(bar.string, make_lit_string("dos lines"))){ + else if (match_ss(bar.string, make_lit_string("dos lines"))){ exec_command(app, eol_dosify); } - else if (match(bar.string, make_lit_string("nix lines"))){ + else if (match_ss(bar.string, make_lit_string("nix lines"))){ exec_command(app, eol_nixify); } else{ diff --git a/4coder_helper.h b/4coder_helper.h index bfe2aebb..c0903809 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -388,7 +388,7 @@ query_user_general(Application_Links *app, Query_Bar *bar, int force_number){ } } else if (good_character){ - append(&bar->string, in.key.character); + append_s_char(&bar->string, in.key.character); } } } diff --git a/4coder_jump_parsing.cpp b/4coder_jump_parsing.cpp index 78eb29a8..246e2484 100644 --- a/4coder_jump_parsing.cpp +++ b/4coder_jump_parsing.cpp @@ -18,40 +18,40 @@ static int ms_style_verify(String line, int paren_pos){ int result = false; - String line_part = substr(line, paren_pos); - if (match_part(line_part, ") : ")){ - result = true; - } - else if (match_part(line_part, "): ")){ - result = true; - } - - return(result); -} - -static int + String line_part = substr_tail(line, paren_pos); + if (match_part_sc(line_part, ") : ")){ + result = true; + } + else if (match_part_sc(line_part, "): ")){ + result = true; + } + + return(result); +} + +static int parse_error(String line, Jump_Location *location, int skip_sub_errors, int *colon_char){ - int result = false; - + int result = false; + String original_line = line; line = skip_chop_whitespace(line); - - int colon_pos = find(line, 0, ')'); + + int colon_pos = find_s_char(line, 0, ')'); if (ms_style_verify(line, colon_pos)){ - colon_pos = find(line, colon_pos, ':'); + colon_pos = find_s_char(line, colon_pos, ':'); if (colon_pos < line.size){ String location_str = substr(line, 0, colon_pos); if (!(skip_sub_errors && original_line.str[0] == ' ')){ location_str = skip_chop_whitespace(location_str); - int paren_pos = find(location_str, 0, '('); + int paren_pos = find_s_char(location_str, 0, '('); if (paren_pos < location_str.size){ String file = substr(location_str, 0, paren_pos); file = skip_chop_whitespace(file); - int close_pos = find(location_str, 0, ')') + 1; + int close_pos = find_s_char(location_str, 0, ')') + 1; if (close_pos == location_str.size && file.size > 0){ String line_number = substr(location_str, paren_pos+1, @@ -61,17 +61,17 @@ parse_error(String line, Jump_Location *location, if (line_number.size > 0){ location->file = file; - int comma_pos = find(line_number, 0, ','); + int comma_pos = find_s_char(line_number, 0, ','); if (comma_pos < line_number.size){ int start = comma_pos+1; String column_number = substr(line_number, start, line_number.size-start); line_number = substr(line_number, 0, comma_pos); - location->line = str_to_int(line_number); - location->column = str_to_int(column_number); + location->line = str_to_int_s(line_number); + location->column = str_to_int_s(column_number); } else{ - location->line = str_to_int(line_number); + location->line = str_to_int_s(line_number); location->column = 1; } @@ -85,15 +85,15 @@ parse_error(String line, Jump_Location *location, } else{ - int colon_pos1 = find(line, 0, ':'); + int colon_pos1 = find_s_char(line, 0, ':'); if (line.size > colon_pos1+1){ if (char_is_slash(line.str[colon_pos1+1])){ - colon_pos1 = find(line, colon_pos1+1, ':'); + colon_pos1 = find_s_char(line, colon_pos1+1, ':'); } } - int colon_pos2 = find(line, colon_pos1+1, ':'); - int colon_pos3 = find(line, colon_pos2+1, ':'); + int colon_pos2 = find_s_char(line, colon_pos1+1, ':'); + int colon_pos3 = find_s_char(line, colon_pos2+1, ':'); if (colon_pos3 < line.size){ String filename = substr(line, 0, colon_pos1); @@ -104,30 +104,30 @@ parse_error(String line, Jump_Location *location, line_number.size > 0 && column_number.size > 0){ location->file = filename; - location->line = str_to_int(line_number); - location->column = str_to_int(column_number); + location->line = str_to_int_s(line_number); + location->column = str_to_int_s(column_number); *colon_char = colon_pos3; result = true; } } else{ - colon_pos1 = find(line, 0, ':'); + colon_pos1 = find_s_char(line, 0, ':'); if (line.size > colon_pos1+1){ if (char_is_slash(line.str[colon_pos1+1])){ - colon_pos1 = find(line, colon_pos1+1, ':'); + colon_pos1 = find_s_char(line, colon_pos1+1, ':'); } } - colon_pos2 = find(line, colon_pos1+1, ':'); + colon_pos2 = find_s_char(line, colon_pos1+1, ':'); if (colon_pos2 < line.size){ String filename = substr(line, 0, colon_pos1); String line_number = substr(line, colon_pos1+1, colon_pos2 - colon_pos1 - 1); - if (str_is_int(line_number)){ + if (str_is_int_s(line_number)){ if (filename.size > 0 && line_number.size > 0){ location->file = filename; - location->line = str_to_int(line_number); + location->line = str_to_int_s(line_number); location->column = 0; *colon_char = colon_pos2; result = true; diff --git a/4coder_string.h b/4coder_string.h index 0a8e2f09..fb2d0749 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -1,6 +1,10 @@ // TOP +#if defined(FSTRING_C) +#define FSTRING_INLINE static +#endif + #if defined(FSTRING_IMPLEMENTATION) && defined(FSTRING_GUARD) #undef FSTRING_IMPLEMENTATION #endif @@ -17,16 +21,16 @@ #ifndef FSTRING_STRUCT #define FSTRING_STRUCT -struct String{ +typedef struct String{ char *str; int32_t size; int32_t memory_size; -}; +} String; -struct Offset_String{ +typedef struct Offset_String{ int32_t offset; int32_t size; -}; +} Offset_String; #endif #ifndef fstr_bool @@ -37,7 +41,7 @@ struct Offset_String{ # define literal(s) (s), (sizeof(s)-1) #endif -#ifndef FCODER_STRING_H +#if !defined(FCODER_STRING_H) #define FCODER_STRING_H FSTRING_INLINE fstr_bool char_is_slash(char c); @@ -50,77 +54,77 @@ FSTRING_INLINE fstr_bool char_is_alpha(char c); FSTRING_INLINE fstr_bool char_is_alpha_true(char c); FSTRING_INLINE fstr_bool char_is_hex(char c); FSTRING_INLINE fstr_bool char_is_numeric(char c); -FSTRING_INLINE String string_zero(); -FSTRING_INLINE String make_string(void *str, int32_t size, int32_t mem_size); +FSTRING_INLINE String string_zero(void); +FSTRING_INLINE String make_string_cap(void *str, int32_t size, int32_t mem_size); FSTRING_INLINE String make_string(void *str, int32_t size); #ifndef make_lit_string -# define make_lit_string(s) (make_string((char*)(s), sizeof(s)-1, sizeof(s))) +# define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) #endif #ifndef make_fixed_width_string -# define make_fixed_width_string(s) (make_string((char*)(s), 0, sizeof(s))) +# define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) #endif #ifndef expand_str # define expand_str(s) ((s).str), ((s).size) #endif FSTRING_LINK int32_t str_size(char *str); FSTRING_INLINE String make_string_slowly(void *str); -FSTRING_INLINE String substr(String str, int32_t start); +FSTRING_INLINE String substr_tail(String str, int32_t start); FSTRING_INLINE String substr(String str, int32_t start, int32_t size); FSTRING_LINK String skip_whitespace(String str); FSTRING_LINK String chop_whitespace(String str); FSTRING_LINK String skip_chop_whitespace(String str); FSTRING_INLINE String tailstr(String str); -FSTRING_LINK fstr_bool match(char *a, char *b); -FSTRING_LINK fstr_bool match(String a, char *b); -FSTRING_INLINE fstr_bool match(char *a, String b); -FSTRING_LINK fstr_bool match(String a, String b); -FSTRING_LINK fstr_bool match_part(char *a, char *b, int32_t *len); -FSTRING_LINK fstr_bool match_part(String a, char *b, int32_t *len); -FSTRING_INLINE fstr_bool match_part(char *a, char *b); -FSTRING_INLINE fstr_bool match_part(String a, char *b); -FSTRING_LINK fstr_bool match_part(char *a, String b); -FSTRING_LINK fstr_bool match_part(String a, String b); -FSTRING_LINK fstr_bool match_insensitive(char *a, char *b); -FSTRING_LINK fstr_bool match_insensitive(String a, char *b); -FSTRING_INLINE fstr_bool match_insensitive(char *a, String b); -FSTRING_LINK fstr_bool match_insensitive(String a, String b); -FSTRING_LINK fstr_bool match_part_insensitive(char *a, char *b, int32_t *len); -FSTRING_LINK fstr_bool match_part_insensitive(String a, char *b, int32_t *len); -FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b); -FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b); -FSTRING_LINK fstr_bool match_part_insensitive(char *a, String b); -FSTRING_LINK fstr_bool match_part_insensitive(String a, String b); -FSTRING_LINK int32_t compare(char *a, char *b); -FSTRING_LINK int32_t compare(String a, char *b); -FSTRING_INLINE int32_t compare(char *a, String b); -FSTRING_LINK int32_t compare(String a, String b); -FSTRING_LINK int32_t find(char *str, int32_t start, char character); -FSTRING_LINK int32_t find(String str, int32_t start, char character); -FSTRING_LINK int32_t find(char *str, int32_t start, char *characters); -FSTRING_LINK int32_t find(String str, int32_t start, char *characters); -FSTRING_LINK int32_t find_substr(char *str, int32_t start, String seek); -FSTRING_LINK int32_t find_substr(String str, int32_t start, String seek); -FSTRING_LINK int32_t rfind_substr(String str, int32_t start, String seek); -FSTRING_LINK int32_t find_substr_insensitive(char *str, int32_t start, String seek); -FSTRING_LINK int32_t find_substr_insensitive(String str, int32_t start, String seek); -FSTRING_INLINE fstr_bool has_substr(char *s, String seek); -FSTRING_INLINE fstr_bool has_substr(String s, String seek); -FSTRING_INLINE fstr_bool has_substr_insensitive(char *s, String seek); -FSTRING_INLINE fstr_bool has_substr_insensitive(String s, String seek); -FSTRING_LINK int32_t copy_fast_unsafe(char *dest, char *src); -FSTRING_LINK int32_t copy_fast_unsafe(char *dest, String src); -FSTRING_LINK fstr_bool copy_checked(String *dest, String src); -FSTRING_LINK fstr_bool copy_partial(String *dest, char *src); -FSTRING_LINK fstr_bool copy_partial(String *dest, String src); -FSTRING_INLINE int32_t copy(char *dest, char *src); -FSTRING_INLINE void copy(String *dest, String src); -FSTRING_INLINE void copy(String *dest, char *src); -FSTRING_LINK fstr_bool append_checked(String *dest, String src); -FSTRING_LINK fstr_bool append_partial(String *dest, char *src); -FSTRING_LINK fstr_bool append_partial(String *dest, String src); -FSTRING_LINK fstr_bool append(String *dest, char c); -FSTRING_INLINE fstr_bool append(String *dest, String src); -FSTRING_INLINE fstr_bool append(String *dest, char *src); +FSTRING_LINK fstr_bool match_cc(char *a, char *b); +FSTRING_LINK fstr_bool match_sc(String a, char *b); +FSTRING_INLINE fstr_bool match_cs(char *a, String b); +FSTRING_LINK fstr_bool match_ss(String a, String b); +FSTRING_LINK fstr_bool match_part_ccl(char *a, char *b, int32_t *len); +FSTRING_LINK fstr_bool match_part_scl(String a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part_cc(char *a, char *b); +FSTRING_INLINE fstr_bool match_part_sc(String a, char *b); +FSTRING_LINK fstr_bool match_part_cs(char *a, String b); +FSTRING_LINK fstr_bool match_part_ss(String a, String b); +FSTRING_LINK fstr_bool match_insensitive_cc(char *a, char *b); +FSTRING_LINK fstr_bool match_insensitive_sc(String a, char *b); +FSTRING_INLINE fstr_bool match_insensitive_cs(char *a, String b); +FSTRING_LINK fstr_bool match_insensitive_ss(String a, String b); +FSTRING_LINK fstr_bool match_part_insensitive_ccl(char *a, char *b, int32_t *len); +FSTRING_LINK fstr_bool match_part_insensitive_scl(String a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part_insensitive_cc(char *a, char *b); +FSTRING_INLINE fstr_bool match_part_insensitive_sc(String a, char *b); +FSTRING_LINK fstr_bool match_part_insensitive_cs(char *a, String b); +FSTRING_LINK fstr_bool match_part_insensitive_ss(String a, String b); +FSTRING_LINK int32_t compare_cc(char *a, char *b); +FSTRING_LINK int32_t compare_sc(String a, char *b); +FSTRING_INLINE int32_t compare_cs(char *a, String b); +FSTRING_LINK int32_t compare_ss(String a, String b); +FSTRING_LINK int32_t find_c_char(char *str, int32_t start, char character); +FSTRING_LINK int32_t find_s_char(String str, int32_t start, char character); +FSTRING_LINK int32_t find_c_chars(char *str, int32_t start, char *characters); +FSTRING_LINK int32_t find_s_chars(String str, int32_t start, char *characters); +FSTRING_LINK int32_t find_substr_c(char *str, int32_t start, String seek); +FSTRING_LINK int32_t find_substr_s(String str, int32_t start, String seek); +FSTRING_LINK int32_t rfind_substr_s(String str, int32_t start, String seek); +FSTRING_LINK int32_t find_substr_insensitive_c(char *str, int32_t start, String seek); +FSTRING_LINK int32_t find_substr_insensitive_s(String str, int32_t start, String seek); +FSTRING_INLINE fstr_bool has_substr_c(char *s, String seek); +FSTRING_INLINE fstr_bool has_substr_s(String s, String seek); +FSTRING_INLINE fstr_bool has_substr_insensitive_c(char *s, String seek); +FSTRING_INLINE fstr_bool has_substr_insensitive_s(String s, String seek); +FSTRING_LINK int32_t copy_fast_unsafe_cc(char *dest, char *src); +FSTRING_LINK int32_t copy_fast_unsafe_cs(char *dest, String src); +FSTRING_LINK fstr_bool copy_checked_ss(String *dest, String src); +FSTRING_LINK fstr_bool copy_partial_sc(String *dest, char *src); +FSTRING_LINK fstr_bool copy_partial_ss(String *dest, String src); +FSTRING_INLINE int32_t copy_cc(char *dest, char *src); +FSTRING_INLINE void copy_ss(String *dest, String src); +FSTRING_INLINE void copy_sc(String *dest, char *src); +FSTRING_LINK fstr_bool append_checked_ss(String *dest, String src); +FSTRING_LINK fstr_bool append_partial_sc(String *dest, char *src); +FSTRING_LINK fstr_bool append_partial_ss(String *dest, String src); +FSTRING_LINK fstr_bool append_s_char(String *dest, char c); +FSTRING_INLINE fstr_bool append_ss(String *dest, String src); +FSTRING_INLINE fstr_bool append_sc(String *dest, char *src); FSTRING_LINK fstr_bool terminate_with_null(String *str); FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size); FSTRING_LINK void replace_char(String *str, char replace, char with); @@ -133,24 +137,218 @@ FSTRING_LINK fstr_bool append_u64_to_str(String *dest, uint64_t x); FSTRING_LINK int32_t float_to_str_size(float x); FSTRING_LINK fstr_bool append_float_to_str(String *dest, float x); FSTRING_LINK fstr_bool float_to_str(String *dest, float x); -FSTRING_LINK fstr_bool str_is_int(String str); -FSTRING_LINK int32_t str_to_int(char *str); -FSTRING_LINK int32_t str_to_int(String str); +FSTRING_LINK int32_t str_is_int_c(char *str); +FSTRING_LINK fstr_bool str_is_int_s(String str); +FSTRING_LINK int32_t str_to_int_c(char *str); +FSTRING_LINK int32_t str_to_int_s(String str); FSTRING_LINK int32_t hexchar_to_int(char c); FSTRING_LINK char int_to_hexchar(int32_t x); FSTRING_LINK uint32_t hexstr_to_int(String str); FSTRING_LINK fstr_bool color_to_hexstr(String *s, uint32_t color); FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *out); -FSTRING_LINK int32_t reverse_seek_slash(String str, int32_t pos); +FSTRING_LINK int32_t reverse_seek_slash_pos(String str, int32_t pos); FSTRING_INLINE int32_t reverse_seek_slash(String str); FSTRING_INLINE String front_of_directory(String dir); FSTRING_INLINE String path_of_directory(String dir); -FSTRING_LINK fstr_bool set_last_folder(String *dir, char *folder_name, char slash); -FSTRING_LINK fstr_bool set_last_folder(String *dir, String folder_name, char slash); +FSTRING_LINK fstr_bool set_last_folder_sc(String *dir, char *folder_name, char slash); +FSTRING_LINK fstr_bool set_last_folder_ss(String *dir, String folder_name, char slash); FSTRING_LINK String file_extension(String str); FSTRING_LINK fstr_bool remove_last_folder(String *str); FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index); +#if !defined(FSTRING_C) + +// NOTE(allen): This section is here to enable nicer names +// for C++ users who can have overloaded functions. None of +// these functions add new features. +FSTRING_INLINE String make_string(void *str, int32_t size, int32_t mem_size); +FSTRING_INLINE String substr(String str, int32_t start); +FSTRING_INLINE fstr_bool match(char *a, char *b); +FSTRING_INLINE fstr_bool match(String a, char *b); +FSTRING_INLINE fstr_bool match(char *a, String b); +FSTRING_INLINE fstr_bool match(String a, String b); +FSTRING_INLINE fstr_bool match_part(char *a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part(String a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part(char *a, char *b); +FSTRING_INLINE fstr_bool match_part(String a, char *b); +FSTRING_INLINE fstr_bool match_part(char *a, String b); +FSTRING_INLINE fstr_bool match_part(String a, String b); +FSTRING_INLINE fstr_bool match_insensitive(char *a, char *b); +FSTRING_INLINE fstr_bool match_insensitive(String a, char *b); +FSTRING_INLINE fstr_bool match_insensitive(char *a, String b); +FSTRING_INLINE fstr_bool match_insensitive(String a, String b); +FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b); +FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b); +FSTRING_INLINE fstr_bool match_part_insensitive(char *a, String b); +FSTRING_INLINE fstr_bool match_part_insensitive(String a, String b); +FSTRING_INLINE int32_t compare(char *a, char *b); +FSTRING_INLINE int32_t compare(String a, char *b); +FSTRING_INLINE int32_t compare(char *a, String b); +FSTRING_INLINE int32_t compare(String a, String b); +FSTRING_INLINE int32_t find(char *str, int32_t start, char character); +FSTRING_INLINE int32_t find(String str, int32_t start, char character); +FSTRING_INLINE int32_t find(char *str, int32_t start, char *characters); +FSTRING_INLINE int32_t find(String str, int32_t start, char *characters); +FSTRING_INLINE int32_t find_substr(char *str, int32_t start, String seek); +FSTRING_INLINE int32_t find_substr(String str, int32_t start, String seek); +FSTRING_INLINE int32_t rfind_substr(String str, int32_t start, String seek); +FSTRING_INLINE int32_t find_substr_insensitive(char *str, int32_t start, String seek); +FSTRING_INLINE int32_t find_substr_insensitive(String str, int32_t start, String seek); +FSTRING_INLINE fstr_bool has_substr(char *s, String seek); +FSTRING_INLINE fstr_bool has_substr(String s, String seek); +FSTRING_INLINE fstr_bool has_substr_insensitive(char *s, String seek); +FSTRING_INLINE fstr_bool has_substr_insensitive(String s, String seek); +FSTRING_INLINE int32_t copy_fast_unsafe(char *dest, char *src); +FSTRING_INLINE int32_t copy_fast_unsafe(char *dest, String src); +FSTRING_INLINE fstr_bool copy_checked(String *dest, String src); +FSTRING_INLINE fstr_bool copy_partial(String *dest, char *src); +FSTRING_INLINE fstr_bool copy_partial(String *dest, String src); +FSTRING_INLINE int32_t copy(char *dest, char *src); +FSTRING_INLINE void copy(String *dest, String src); +FSTRING_INLINE void copy(String *dest, char *src); +FSTRING_INLINE fstr_bool append_checked(String *dest, String src); +FSTRING_INLINE fstr_bool append_partial(String *dest, char *src); +FSTRING_INLINE fstr_bool append_partial(String *dest, String src); +FSTRING_INLINE fstr_bool append(String *dest, char c); +FSTRING_INLINE fstr_bool append(String *dest, String src); +FSTRING_INLINE fstr_bool append(String *dest, char *src); +FSTRING_INLINE int32_t str_is_int(char *str); +FSTRING_INLINE fstr_bool str_is_int(String str); +FSTRING_INLINE int32_t str_to_int(char *str); +FSTRING_INLINE int32_t str_to_int(String str); +FSTRING_INLINE int32_t reverse_seek_slash(String str, int32_t pos); +FSTRING_INLINE fstr_bool set_last_folder(String *dir, char *folder_name, char slash); +FSTRING_INLINE fstr_bool set_last_folder(String *dir, String folder_name, char slash); + +#endif + +#endif + +#if !defined(FSTRING_C) && !defined(FSTRING_GUARD) + +FSTRING_INLINE String +make_string(void *str, int32_t size, int32_t mem_size){ return(make_string_cap(str,size,mem_size));} +FSTRING_INLINE String +substr(String str, int32_t start){ return(substr_tail(str,start));} +FSTRING_INLINE fstr_bool +match(char *a, char *b){ return(match_cc(a,b));} +FSTRING_INLINE fstr_bool +match(String a, char *b){ return(match_sc(a,b));} +FSTRING_INLINE fstr_bool +match(char *a, String b){ return(match_cs(a,b));} +FSTRING_INLINE fstr_bool +match(String a, String b){ return(match_ss(a,b));} +FSTRING_INLINE fstr_bool +match_part(char *a, char *b, int32_t *len){ return(match_part_ccl(a,b,len));} +FSTRING_INLINE fstr_bool +match_part(String a, char *b, int32_t *len){ return(match_part_scl(a,b,len));} +FSTRING_INLINE fstr_bool +match_part(char *a, char *b){ return(match_part_cc(a,b));} +FSTRING_INLINE fstr_bool +match_part(String a, char *b){ return(match_part_sc(a,b));} +FSTRING_INLINE fstr_bool +match_part(char *a, String b){ return(match_part_cs(a,b));} +FSTRING_INLINE fstr_bool +match_part(String a, String b){ return(match_part_ss(a,b));} +FSTRING_INLINE fstr_bool +match_insensitive(char *a, char *b){ return(match_insensitive_cc(a,b));} +FSTRING_INLINE fstr_bool +match_insensitive(String a, char *b){ return(match_insensitive_sc(a,b));} +FSTRING_INLINE fstr_bool +match_insensitive(char *a, String b){ return(match_insensitive_cs(a,b));} +FSTRING_INLINE fstr_bool +match_insensitive(String a, String b){ return(match_insensitive_ss(a,b));} +FSTRING_INLINE fstr_bool +match_part_insensitive(char *a, char *b, int32_t *len){ return(match_part_insensitive_ccl(a,b,len));} +FSTRING_INLINE fstr_bool +match_part_insensitive(String a, char *b, int32_t *len){ return(match_part_insensitive_scl(a,b,len));} +FSTRING_INLINE fstr_bool +match_part_insensitive(char *a, char *b){ return(match_part_insensitive_cc(a,b));} +FSTRING_INLINE fstr_bool +match_part_insensitive(String a, char *b){ return(match_part_insensitive_sc(a,b));} +FSTRING_INLINE fstr_bool +match_part_insensitive(char *a, String b){ return(match_part_insensitive_cs(a,b));} +FSTRING_INLINE fstr_bool +match_part_insensitive(String a, String b){ return(match_part_insensitive_ss(a,b));} +FSTRING_INLINE int32_t +compare(char *a, char *b){ return(compare_cc(a,b));} +FSTRING_INLINE int32_t +compare(String a, char *b){ return(compare_sc(a,b));} +FSTRING_INLINE int32_t +compare(char *a, String b){ return(compare_cs(a,b));} +FSTRING_INLINE int32_t +compare(String a, String b){ return(compare_ss(a,b));} +FSTRING_INLINE int32_t +find(char *str, int32_t start, char character){ return(find_c_char(str,start,character));} +FSTRING_INLINE int32_t +find(String str, int32_t start, char character){ return(find_s_char(str,start,character));} +FSTRING_INLINE int32_t +find(char *str, int32_t start, char *characters){ return(find_c_chars(str,start,characters));} +FSTRING_INLINE int32_t +find(String str, int32_t start, char *characters){ return(find_s_chars(str,start,characters));} +FSTRING_INLINE int32_t +find_substr(char *str, int32_t start, String seek){ return(find_substr_c(str,start,seek));} +FSTRING_INLINE int32_t +find_substr(String str, int32_t start, String seek){ return(find_substr_s(str,start,seek));} +FSTRING_INLINE int32_t +rfind_substr(String str, int32_t start, String seek){ return(rfind_substr_s(str,start,seek));} +FSTRING_INLINE int32_t +find_substr_insensitive(char *str, int32_t start, String seek){ return(find_substr_insensitive_c(str,start,seek));} +FSTRING_INLINE int32_t +find_substr_insensitive(String str, int32_t start, String seek){ return(find_substr_insensitive_s(str,start,seek));} +FSTRING_INLINE fstr_bool +has_substr(char *s, String seek){ return(has_substr_c(s,seek));} +FSTRING_INLINE fstr_bool +has_substr(String s, String seek){ return(has_substr_s(s,seek));} +FSTRING_INLINE fstr_bool +has_substr_insensitive(char *s, String seek){ return(has_substr_insensitive_c(s,seek));} +FSTRING_INLINE fstr_bool +has_substr_insensitive(String s, String seek){ return(has_substr_insensitive_s(s,seek));} +FSTRING_INLINE int32_t +copy_fast_unsafe(char *dest, char *src){ return(copy_fast_unsafe_cc(dest,src));} +FSTRING_INLINE int32_t +copy_fast_unsafe(char *dest, String src){ return(copy_fast_unsafe_cs(dest,src));} +FSTRING_INLINE fstr_bool +copy_checked(String *dest, String src){ return(copy_checked_ss(dest,src));} +FSTRING_INLINE fstr_bool +copy_partial(String *dest, char *src){ return(copy_partial_sc(dest,src));} +FSTRING_INLINE fstr_bool +copy_partial(String *dest, String src){ return(copy_partial_ss(dest,src));} +FSTRING_INLINE int32_t +copy(char *dest, char *src){ return(copy_cc(dest,src));} +FSTRING_INLINE void +copy(String *dest, String src){ (copy_ss(dest,src));} +FSTRING_INLINE void +copy(String *dest, char *src){ (copy_sc(dest,src));} +FSTRING_INLINE fstr_bool +append_checked(String *dest, String src){ return(append_checked_ss(dest,src));} +FSTRING_INLINE fstr_bool +append_partial(String *dest, char *src){ return(append_partial_sc(dest,src));} +FSTRING_INLINE fstr_bool +append_partial(String *dest, String src){ return(append_partial_ss(dest,src));} +FSTRING_INLINE fstr_bool +append(String *dest, char c){ return(append_s_char(dest,c));} +FSTRING_INLINE fstr_bool +append(String *dest, String src){ return(append_ss(dest,src));} +FSTRING_INLINE fstr_bool +append(String *dest, char *src){ return(append_sc(dest,src));} +FSTRING_INLINE int32_t +str_is_int(char *str){ return(str_is_int_c(str));} +FSTRING_INLINE fstr_bool +str_is_int(String str){ return(str_is_int_s(str));} +FSTRING_INLINE int32_t +str_to_int(char *str){ return(str_to_int_c(str));} +FSTRING_INLINE int32_t +str_to_int(String str){ return(str_to_int_s(str));} +FSTRING_INLINE int32_t +reverse_seek_slash(String str, int32_t pos){ return(reverse_seek_slash_pos(str,pos));} +FSTRING_INLINE fstr_bool +set_last_folder(String *dir, char *folder_name, char slash){ return(set_last_folder_sc(dir,folder_name,slash));} +FSTRING_INLINE fstr_bool +set_last_folder(String *dir, String folder_name, char slash){ return(set_last_folder_ss(dir,folder_name,slash));} + #endif @@ -158,7 +356,7 @@ FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, S // Character Helpers // -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool char_is_slash(char c) { @@ -166,7 +364,7 @@ char_is_slash(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE char char_to_upper(char c) { @@ -174,7 +372,7 @@ char_to_upper(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE char char_to_lower(char c) { @@ -182,7 +380,7 @@ char_to_lower(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool char_is_whitespace(char c) { @@ -190,7 +388,7 @@ char_is_whitespace(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool char_is_alpha_numeric(char c) { @@ -198,7 +396,7 @@ char_is_alpha_numeric(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool char_is_alpha_numeric_true(char c) { @@ -206,7 +404,7 @@ char_is_alpha_numeric_true(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool char_is_alpha(char c) { @@ -214,7 +412,7 @@ char_is_alpha(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool char_is_alpha_true(char c) { @@ -222,7 +420,7 @@ char_is_alpha_true(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool char_is_hex(char c) { @@ -230,7 +428,7 @@ char_is_hex(char c) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool char_is_numeric(char c) { @@ -243,18 +441,19 @@ char_is_numeric(char c) // String Making Functions // -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE String -string_zero() +string_zero(void) { String str={0}; return(str); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE String -make_string(void *str, int32_t size, int32_t mem_size) +make_string_cap(void *str, int32_t size, int32_t mem_size) { String result; result.str = (char*)str; @@ -264,7 +463,7 @@ make_string(void *str, int32_t size, int32_t mem_size) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE String make_string(void *str, int32_t size){ String result; @@ -275,7 +474,7 @@ make_string(void *str, int32_t size){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t str_size(char *str) { @@ -285,7 +484,7 @@ str_size(char *str) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE String make_string_slowly(void *str) { @@ -297,13 +496,10 @@ make_string_slowly(void *str) } #endif -// TODO(allen): I don't love the substr rule, I chose -// substr(String, start) and substr(String, start, size) -// but I wish I had substr(String, start) and substr(String, start, end) -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE String -substr(String str, int32_t start) +substr_tail(String str, int32_t start) { String result; result.str = str.str + start; @@ -313,7 +509,7 @@ substr(String str, int32_t start) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE String substr(String str, int32_t start, int32_t size) { @@ -328,7 +524,7 @@ substr(String str, int32_t start, int32_t size) } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String skip_whitespace(String str) { @@ -340,7 +536,7 @@ skip_whitespace(String str) } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String chop_whitespace(String str) { @@ -352,7 +548,7 @@ chop_whitespace(String str) } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String skip_chop_whitespace(String str) { @@ -362,7 +558,7 @@ skip_chop_whitespace(String str) } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE String tailstr(String str) { @@ -379,9 +575,10 @@ tailstr(String str) // String Comparison // -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match(char *a, char *b){ +match_cc(char *a, char *b){ for (int32_t i = 0;; ++i){ if (a[i] != b[i]){ return 0; @@ -393,9 +590,10 @@ match(char *a, char *b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match(String a, char *b){ +match_sc(String a, char *b){ int32_t i = 0; for (; i < a.size; ++i){ if (a.str[i] != b[i]){ @@ -409,16 +607,18 @@ match(String a, char *b){ } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -match(char *a, String b){ - return(match(b,a)); +match_cs(char *a, String b){ + return(match_sc(b,a)); } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match(String a, String b){ +match_ss(String a, String b){ if (a.size != b.size){ return 0; } @@ -431,9 +631,10 @@ match(String a, String b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_part(char *a, char *b, int32_t *len){ +match_part_ccl(char *a, char *b, int32_t *len){ int32_t i; for (i = 0; b[i] != 0; ++i){ if (a[i] != b[i]){ @@ -446,9 +647,9 @@ match_part(char *a, char *b, int32_t *len){ #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_part(String a, char *b, int32_t *len){ +match_part_scl(String a, char *b, int32_t *len){ int32_t i; for (i = 0; b[i] != 0; ++i){ if (a.str[i] != b[i] || i == a.size){ @@ -460,25 +661,28 @@ match_part(String a, char *b, int32_t *len){ } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -match_part(char *a, char *b){ +match_part_cc(char *a, char *b){ int32_t x; - return match_part(a,b,&x); + return match_part_ccl(a,b,&x); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -match_part(String a, char *b){ +match_part_sc(String a, char *b){ int32_t x; - return match_part(a,b,&x); + return match_part_scl(a,b,&x); } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_part(char *a, String b){ +match_part_cs(char *a, String b){ for (int32_t i = 0; i != b.size; ++i){ if (a[i] != b.str[i]){ return 0; @@ -488,9 +692,10 @@ match_part(char *a, String b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_part(String a, String b){ +match_part_ss(String a, String b){ if (a.size < b.size){ return 0; } @@ -503,9 +708,10 @@ match_part(String a, String b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_insensitive(char *a, char *b){ +match_insensitive_cc(char *a, char *b){ for (int32_t i = 0;; ++i){ if (char_to_upper(a[i]) != char_to_upper(b[i])){ @@ -518,9 +724,10 @@ match_insensitive(char *a, char *b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_insensitive(String a, char *b){ +match_insensitive_sc(String a, char *b){ int32_t i = 0; for (; i < a.size; ++i){ if (char_to_upper(a.str[i]) != @@ -535,16 +742,18 @@ match_insensitive(String a, char *b){ } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -match_insensitive(char *a, String b){ - return match_insensitive(b,a); +match_insensitive_cs(char *a, String b){ + return match_insensitive_sc(b,a); } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_insensitive(String a, String b){ +match_insensitive_ss(String a, String b){ if (a.size != b.size){ return 0; } @@ -558,9 +767,10 @@ match_insensitive(String a, String b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_part_insensitive(char *a, char *b, int32_t *len){ +match_part_insensitive_ccl(char *a, char *b, int32_t *len){ int32_t i; for (i = 0; b[i] != 0; ++i){ if (char_to_upper(a[i]) != char_to_upper(b[i])){ @@ -572,9 +782,10 @@ match_part_insensitive(char *a, char *b, int32_t *len){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_part_insensitive(String a, char *b, int32_t *len){ +match_part_insensitive_scl(String a, char *b, int32_t *len){ int32_t i; for (i = 0; b[i] != 0; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b[i]) || @@ -587,25 +798,28 @@ match_part_insensitive(String a, char *b, int32_t *len){ } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -match_part_insensitive(char *a, char *b){ +match_part_insensitive_cc(char *a, char *b){ int32_t x; - return match_part(a,b,&x); + return match_part_insensitive_ccl(a,b,&x); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -match_part_insensitive(String a, char *b){ +match_part_insensitive_sc(String a, char *b){ int32_t x; - return match_part(a,b,&x); + return match_part_insensitive_scl(a,b,&x); } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_part_insensitive(char *a, String b){ +match_part_insensitive_cs(char *a, String b){ for (int32_t i = 0; i != b.size; ++i){ if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ return 0; @@ -615,9 +829,10 @@ match_part_insensitive(char *a, String b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -match_part_insensitive(String a, String b){ +match_part_insensitive_ss(String a, String b){ if (a.size < b.size){ return 0; } @@ -630,9 +845,10 @@ match_part_insensitive(String a, String b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -compare(char *a, char *b){ +compare_cc(char *a, char *b){ int32_t i = 0; while (a[i] == b[i] && a[i] != 0){ ++i; @@ -641,9 +857,10 @@ compare(char *a, char *b){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -compare(String a, char *b){ +compare_sc(String a, char *b){ int32_t i = 0; while (i < a.size && a.str[i] == b[i]){ ++i; @@ -662,16 +879,18 @@ compare(String a, char *b){ } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE int32_t -compare(char *a, String b){ - return -compare(b,a); +compare_cs(char *a, String b){ + return -compare_sc(b,a); } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -compare(String a, String b){ +compare_ss(String a, String b){ int32_t i = 0; while (i < a.size && i < b.size && a.str[i] == b.str[i]){ ++i; @@ -689,27 +908,30 @@ compare(String a, String b){ // Finding Characters and Substrings // -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -find(char *str, int32_t start, char character){ +find_c_char(char *str, int32_t start, char character){ int32_t i = start; while (str[i] != character && str[i] != 0) ++i; return i; } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -find(String str, int32_t start, char character){ +find_s_char(String str, int32_t start, char character){ int32_t i = start; while (i < str.size && str.str[i] != character) ++i; return i; } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -find(char *str, int32_t start, char *characters){ +find_c_chars(char *str, int32_t start, char *characters){ int32_t i = start, j; while (str[i] != 0){ for (j = 0; characters[j]; ++j){ @@ -723,9 +945,10 @@ find(char *str, int32_t start, char *characters){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -find(String str, int32_t start, char *characters){ +find_s_chars(String str, int32_t start, char *characters){ int32_t i = start, j; while (i < str.size){ for (j = 0; characters[j]; ++j){ @@ -739,9 +962,10 @@ find(String str, int32_t start, char *characters){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -find_substr(char *str, int32_t start, String seek){ +find_substr_c(char *str, int32_t start, String seek){ int32_t i, j, k; fstr_bool hit; @@ -766,9 +990,10 @@ find_substr(char *str, int32_t start, String seek){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -find_substr(String str, int32_t start, String seek){ +find_substr_s(String str, int32_t start, String seek){ int32_t stop_at, i, j, k; fstr_bool hit; @@ -794,9 +1019,10 @@ find_substr(String str, int32_t start, String seek){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -rfind_substr(String str, int32_t start, String seek){ +rfind_substr_s(String str, int32_t start, String seek){ int32_t i, j, k; fstr_bool hit; @@ -824,9 +1050,10 @@ rfind_substr(String str, int32_t start, String seek){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -find_substr_insensitive(char *str, int32_t start, String seek){ +find_substr_insensitive_c(char *str, int32_t start, String seek){ int32_t i, j, k; fstr_bool hit; char a_upper, b_upper; @@ -854,9 +1081,10 @@ find_substr_insensitive(char *str, int32_t start, String seek){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -find_substr_insensitive(String str, int32_t start, String seek){ +find_substr_insensitive_s(String str, int32_t start, String seek){ int32_t i, j, k; int32_t stop_at; fstr_bool hit; @@ -886,31 +1114,35 @@ find_substr_insensitive(String str, int32_t start, String seek){ } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -has_substr(char *s, String seek){ - return (s[find_substr(s, 0, seek)] != 0); +has_substr_c(char *s, String seek){ + return (s[find_substr_c(s, 0, seek)] != 0); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -has_substr(String s, String seek){ - return (find_substr(s, 0, seek) < s.size); +has_substr_s(String s, String seek){ + return (find_substr_s(s, 0, seek) < s.size); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -has_substr_insensitive(char *s, String seek){ - return (s[find_substr_insensitive(s, 0, seek)] != 0); +has_substr_insensitive_c(char *s, String seek){ + return (s[find_substr_insensitive_c(s, 0, seek)] != 0); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -has_substr_insensitive(String s, String seek){ - return (find_substr_insensitive(s, 0, seek) < s.size); +has_substr_insensitive_s(String s, String seek){ + return (find_substr_insensitive_s(s, 0, seek) < s.size); } #endif @@ -918,9 +1150,10 @@ has_substr_insensitive(String s, String seek){ // String Copies and Appends // -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -copy_fast_unsafe(char *dest, char *src){ +copy_fast_unsafe_cc(char *dest, char *src){ char *start = dest; while (*src != 0){ *dest = *src; @@ -931,9 +1164,10 @@ copy_fast_unsafe(char *dest, char *src){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -copy_fast_unsafe(char *dest, String src){ +copy_fast_unsafe_cs(char *dest, String src){ int32_t i = 0; while (i != src.size){ dest[i] = src.str[i]; @@ -943,9 +1177,10 @@ copy_fast_unsafe(char *dest, String src){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -copy_checked(String *dest, String src){ +copy_checked_ss(String *dest, String src){ char *dest_str; int32_t i; if (dest->memory_size < src.size){ @@ -960,9 +1195,10 @@ copy_checked(String *dest, String src){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -copy_partial(String *dest, char *src){ +copy_partial_sc(String *dest, char *src){ int32_t i = 0; int32_t memory_size = dest->memory_size; char *dest_str = dest->str; @@ -978,14 +1214,15 @@ copy_partial(String *dest, char *src){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -copy_partial(String *dest, String src){ +copy_partial_ss(String *dest, String src){ char *dest_str = dest->str; int32_t memory_size = dest->memory_size; - fstr_bool result = false; + fstr_bool result = 0; if (memory_size >= src.size){ - result = true; + result = 1; memory_size = src.size; } for (int32_t i = 0; i < memory_size; ++i){ @@ -996,33 +1233,37 @@ copy_partial(String *dest, String src){ } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE int32_t -copy(char *dest, char *src){ - return copy_fast_unsafe(dest, src); +copy_cc(char *dest, char *src){ + return copy_fast_unsafe_cc(dest, src); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE void -copy(String *dest, String src){ - copy_checked(dest, src); +copy_ss(String *dest, String src){ + copy_checked_ss(dest, src); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE void -copy(String *dest, char *src){ - copy_partial(dest, src); +copy_sc(String *dest, char *src){ + copy_partial_sc(dest, src); } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -append_checked(String *dest, String src){ +append_checked_ss(String *dest, String src){ String end; end = tailstr(*dest); - fstr_bool result = copy_checked(&end, src); + fstr_bool result = copy_checked_ss(&end, src); // NOTE(allen): This depends on end.size still being 0 if // the check failed and no coppy occurred. dest->size += end.size; @@ -1030,29 +1271,32 @@ append_checked(String *dest, String src){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -append_partial(String *dest, char *src){ +append_partial_sc(String *dest, char *src){ String end = tailstr(*dest); - fstr_bool result = copy_partial(&end, src); + fstr_bool result = copy_partial_sc(&end, src); dest->size += end.size; return result; } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -append_partial(String *dest, String src){ +append_partial_ss(String *dest, String src){ String end = tailstr(*dest); - fstr_bool result = copy_partial(&end, src); + fstr_bool result = copy_partial_ss(&end, src); dest->size += end.size; return result; } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -append(String *dest, char c){ +append_s_char(String *dest, char c){ fstr_bool result = 0; if (dest->size < dest->memory_size){ dest->str[dest->size++] = c; @@ -1062,21 +1306,23 @@ append(String *dest, char c){ } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -append(String *dest, String src){ - return append_partial(dest, src); +append_ss(String *dest, String src){ + return append_partial_ss(dest, src); } #endif -#ifndef FSTRING_GUARD + +#if !defined(FSTRING_GUARD) FSTRING_INLINE fstr_bool -append(String *dest, char *src){ - return append_partial(dest, src); +append_sc(String *dest, char *src){ + return append_partial_sc(dest, src); } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool terminate_with_null(String *str){ fstr_bool result = 0; @@ -1088,7 +1334,7 @@ terminate_with_null(String *str){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size){ fstr_bool result = 1; @@ -1096,7 +1342,7 @@ append_padding(String *dest, char c, int32_t target_size){ int32_t r = 0; if (offset > 0){ for (r = 0; r < offset; ++r){ - if (append(dest, c) == 0){ + if (append_s_char(dest, c) == 0){ result = 0; break; } @@ -1111,7 +1357,7 @@ append_padding(String *dest, char c, int32_t target_size){ // Other Edits // -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK void replace_char(String *str, char replace, char with){ char *s = str->str; @@ -1126,7 +1372,7 @@ replace_char(String *str, char replace, char with){ // String <-> Number Conversions // -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t int_to_str_size(int32_t x){ int32_t size = 1; @@ -1142,7 +1388,7 @@ int_to_str_size(int32_t x){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool int_to_str(String *dest, int32_t x){ fstr_bool result = 1; @@ -1190,7 +1436,7 @@ int_to_str(String *dest, int32_t x){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool append_int_to_str(String *dest, int32_t x){ String last_part = tailstr(*dest); @@ -1202,7 +1448,7 @@ append_int_to_str(String *dest, int32_t x){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t u64_to_str_size(uint64_t x){ int32_t size; @@ -1221,7 +1467,7 @@ u64_to_str_size(uint64_t x){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool u64_to_str(String *dest, uint64_t x){ fstr_bool result = 1; @@ -1260,7 +1506,7 @@ u64_to_str(String *dest, uint64_t x){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool append_u64_to_str(String *dest, uint64_t x){ String last_part = tailstr(*dest); @@ -1273,18 +1519,18 @@ append_u64_to_str(String *dest, uint64_t x){ #endif #ifndef FSTRING_GUARD -struct Float_To_Str_Variables{ +typedef struct Float_To_Str_Variables{ fstr_bool negative; int32_t int_part; int32_t dec_part; -}; +} Float_To_Str_Variables; -Float_To_Str_Variables +static Float_To_Str_Variables get_float_vars(float x){ Float_To_Str_Variables vars = {0}; if (x < 0){ - vars.negative = true; + vars.negative = 1; x = -x; } @@ -1295,7 +1541,7 @@ get_float_vars(float x){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t float_to_str_size(float x){ Float_To_Str_Variables vars = get_float_vars(x); @@ -1305,25 +1551,25 @@ float_to_str_size(float x){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool append_float_to_str(String *dest, float x){ fstr_bool result = 1; Float_To_Str_Variables vars = get_float_vars(x); if (vars.negative){ - append(dest, '-'); + append_s_char(dest, '-'); } append_int_to_str(dest, vars.int_part); - append(dest, '.'); + append_s_char(dest, '.'); append_int_to_str(dest, vars.dec_part); return(result); } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool float_to_str(String *dest, float x){ fstr_bool result = 1; @@ -1333,13 +1579,14 @@ float_to_str(String *dest, float x){ } #endif -#ifdef FSTRING_IMPLEMENTATION -FSTRING_LINK fstr_bool -str_is_int(String str){ - fstr_bool result = true; - for (int32_t i = 0; i < str.size; ++i){ - if (!char_is_numeric(str.str[i])){ - result = false; + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK int32_t +str_is_int_c(char *str){ + fstr_bool result = 1; + for (; *str; ++str){ + if (!char_is_numeric(*str)){ + result = 0; break; } } @@ -1347,9 +1594,25 @@ str_is_int(String str){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK fstr_bool +str_is_int_s(String str){ + fstr_bool result = 1; + for (int32_t i = 0; i < str.size; ++i){ + if (!char_is_numeric(str.str[i])){ + result = 0; + break; + } + } + return(result); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -str_to_int(char *str){ +str_to_int_c(char *str){ int32_t x = 0; for (; *str; ++str){ if (*str >= '0' || *str <= '9'){ @@ -1365,9 +1628,10 @@ str_to_int(char *str){ } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -str_to_int(String str){ +str_to_int_s(String str){ int32_t x, i; if (str.size == 0){ x = 0; @@ -1383,7 +1647,7 @@ str_to_int(String str){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t hexchar_to_int(char c){ int32_t x = 0; @@ -1400,14 +1664,14 @@ hexchar_to_int(char c){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK char int_to_hexchar(int32_t x){ return (x<10)?((char)x+'0'):((char)x+'a'-10); } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK uint32_t hexstr_to_int(String str){ uint32_t x; @@ -1426,7 +1690,7 @@ hexstr_to_int(String str){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool color_to_hexstr(String *s, uint32_t color){ fstr_bool result = 0; @@ -1455,7 +1719,7 @@ color_to_hexstr(String *s, uint32_t color){ } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *out){ fstr_bool result = 0; @@ -1479,9 +1743,10 @@ hexstr_to_color(String s, uint32_t *out){ // Directory String Management // -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t -reverse_seek_slash(String str, int32_t pos){ +reverse_seek_slash_pos(String str, int32_t pos){ int32_t i = str.size - 1 - pos; while (i >= 0 && !char_is_slash(str.str[i])){ --i; @@ -1490,70 +1755,66 @@ reverse_seek_slash(String str, int32_t pos){ } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE int32_t reverse_seek_slash(String str){ - return(reverse_seek_slash(str, 0)); + return(reverse_seek_slash_pos(str, 0)); } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE String front_of_directory(String dir){ - return substr(dir, reverse_seek_slash(dir) + 1); + return substr_tail(dir, reverse_seek_slash(dir) + 1); } #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) FSTRING_INLINE String path_of_directory(String dir){ return substr(dir, 0, reverse_seek_slash(dir) + 1); } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -set_last_folder(String *dir, char *folder_name, char slash){ - char str[2]; +set_last_folder_sc(String *dir, char *folder_name, char slash){ fstr_bool result = 0; int32_t size = reverse_seek_slash(*dir) + 1; dir->size = size; - str[0] = slash; - str[1] = 0; - if (append(dir, folder_name)){ - if (append(dir, str)){ + if (append_sc(dir, folder_name)){ + if (append_s_char(dir, slash)){ result = 1; } } if (!result){ dir->size = size; } - return result; + return(result); } #endif -#ifdef FSTRING_IMPLEMENTATION + +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool -set_last_folder(String *dir, String folder_name, char slash){ - char str[2]; +set_last_folder_ss(String *dir, String folder_name, char slash){ fstr_bool result = 0; int32_t size = reverse_seek_slash(*dir) + 1; dir->size = size; - str[0] = slash; - str[1] = 0; - if (append(dir, folder_name)){ - if (append(dir, str)){ + if (append_ss(dir, folder_name)){ + if (append_s_char(dir, slash)){ result = 1; } } if (!result){ dir->size = size; } - return result; + return(result); } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK String file_extension(String str){ int32_t i; @@ -1561,15 +1822,15 @@ file_extension(String str){ if (str.str[i] == '.') break; } ++i; - return make_string(str.str+i, str.size-i); + return(make_string(str.str+i, str.size-i)); } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool remove_last_folder(String *str){ fstr_bool result = 0; - int32_t end = reverse_seek_slash(*str, 1); + int32_t end = reverse_seek_slash_pos(*str, 1); if (end >= 0){ result = 1; str->size = end + 1; @@ -1579,15 +1840,15 @@ remove_last_folder(String *str){ #endif // TODO(allen): Add hash-table extension to string sets. -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK fstr_bool string_set_match(String *str_set, int32_t count, String str, int32_t *match_index){ - fstr_bool result = false; + fstr_bool result = 0; int32_t i = 0; for (; i < count; ++i, ++str_set){ - if (match(*str_set, str)){ + if (match_ss(*str_set, str)){ *match_index = i; - result = true; + result = 1; break; } } @@ -1605,10 +1866,10 @@ string_set_match(String *str_set, int32_t count, String str, int32_t *match_inde # define ArrayCount(a) ((sizeof(a))/sizeof(*a)) #endif -struct Absolutes{ +typedef struct Absolutes{ String a[8]; int32_t count; -}; +} Absolutes; static void get_absolutes(String name, Absolutes *absolutes, fstr_bool implicit_first, fstr_bool implicit_last){ @@ -1657,7 +1918,7 @@ get_absolutes(String name, Absolutes *absolutes, fstr_bool implicit_first, fstr_ } static fstr_bool -wildcard_match(Absolutes *absolutes, char *x, int32_t case_sensitive){ +wildcard_match_c(Absolutes *absolutes, char *x, int32_t case_sensitive){ fstr_bool r = 1; String *a = absolutes->a; @@ -1665,12 +1926,12 @@ wildcard_match(Absolutes *absolutes, char *x, int32_t case_sensitive){ fstr_bool (*match_part_func)(char*, String); if (case_sensitive){ - match_func = match; - match_part_func = match_part; + match_func = match_cs; + match_part_func = match_part_cs; } else{ - match_func = match_insensitive; - match_part_func = match_part_insensitive; + match_func = match_insensitive_cs; + match_part_func = match_part_insensitive_cs; } if (absolutes->count == 1){ @@ -1711,22 +1972,22 @@ wildcard_match(Absolutes *absolutes, char *x, int32_t case_sensitive){ } } } - return r; + return(r); } static fstr_bool -wildcard_match(Absolutes *absolutes, String x, int32_t case_sensitive){ +wildcard_match_s(Absolutes *absolutes, String x, int32_t case_sensitive){ terminate_with_null(&x); - return wildcard_match(absolutes, x.str, case_sensitive); + return(wildcard_match_c(absolutes, x.str, case_sensitive)); } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) #undef FSTRING_IMPLEMENTATION #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) #define FSTRING_GUARD #endif diff --git a/4coder_table.cpp b/4coder_table.cpp index 2748deb2..936d4bf3 100644 --- a/4coder_table.cpp +++ b/4coder_table.cpp @@ -188,7 +188,7 @@ static int32_t tbl_string_compare(void *a, void *b, void *arg){ String *stra = (String*)a; String *strb = (String*)b; - int32_t result = !match(*stra, *strb); + int32_t result = !match_ss(*stra, *strb); return(result); } @@ -217,7 +217,7 @@ tbl_offset_string_compare(void *a, void *b, void *arg){ Offset_String *ostrb = (Offset_String*)b; String stra = make_string((char*)arg + ostra->offset, ostra->size); String strb = make_string((char*)arg + ostrb->offset, ostrb->size); - int32_t result = !match(stra, strb); + int32_t result = !match_ss(stra, strb); return(result); } diff --git a/4cpp_lexer.h b/4cpp_lexer.h index 3c9b3852..c5bea44e 100644 --- a/4cpp_lexer.h +++ b/4cpp_lexer.h @@ -398,7 +398,7 @@ sub_match_list(char *data, int size, int pos, String_List list, int sub_size){ str_main = substr(str_main, 0, sub_size); for (i = 0; i < list.count; ++i){ str_check = list.data[i].str; - if (match(str_main, str_check)){ + if (match_sc(str_main, str_check)){ result.index = i; result.new_pos = pos + sub_size; break; @@ -408,7 +408,7 @@ sub_match_list(char *data, int size, int pos, String_List list, int sub_size){ else{ for (i = 0; i < list.count; ++i){ str_check = list.data[i].str; - if (match_part(str_main, str_check, &l)){ + if (match_part_scl(str_main, str_check, &l)){ result.index = i; result.new_pos = pos + l; break; @@ -607,7 +607,7 @@ cpp_read_alpha_numeric(char *data, int size, int pos, bool in_if_body){ String word; word.size = result.token.size; word.str = data + result.token.start; - if (match(word, "defined")){ + if (match_ss(word, make_lit_string("defined"))){ result.token.type = CPP_TOKEN_DEFINED; result.token.flags |= CPP_TFLAG_IS_OPERATOR; result.token.flags |= CPP_TFLAG_IS_KEYWORD; diff --git a/4ed.cpp b/4ed.cpp index e8ee452a..b191e165 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -141,7 +141,7 @@ consume_input(Available_Input *available, i32 input_type, char *consumer){ record->consumed = 1; if (consumer){ String str = make_fixed_width_string(record->consumer); - copy(&str, consumer); + copy_sc(&str, consumer); terminate_with_null(&str); } else{ @@ -336,7 +336,7 @@ COMMAND_DECL(reopen){ USE_VIEW(view); REQ_FILE(file, view); - if (match(file->name.source_path, file->name.live_name)) return; + if (match_ss(file->name.source_path, file->name.live_name)) return; if (file->canon.name.size != 0){ Plat_Handle handle; @@ -1174,7 +1174,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, case CLAct_InitialFilePosition: { if (i < clparams.argc){ - settings->initial_line = str_to_int(clparams.argv[i]); + settings->initial_line = str_to_int_c(clparams.argv[i]); } action = CLAct_Nothing; }break; @@ -1183,8 +1183,8 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, { if (i + 1 < clparams.argc){ plat_settings->set_window_size = true; - plat_settings->window_w = str_to_int(clparams.argv[i]); - plat_settings->window_h = str_to_int(clparams.argv[i+1]); + plat_settings->window_w = str_to_int_c(clparams.argv[i]); + plat_settings->window_h = str_to_int_c(clparams.argv[i+1]); ++i; } @@ -1202,8 +1202,8 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, { if (i + 1 < clparams.argc){ plat_settings->set_window_pos = true; - plat_settings->window_x = str_to_int(clparams.argv[i]); - plat_settings->window_y = str_to_int(clparams.argv[i+1]); + plat_settings->window_x = str_to_int_c(clparams.argv[i]); + plat_settings->window_y = str_to_int_c(clparams.argv[i+1]); ++i; } @@ -1213,7 +1213,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, case CLAct_FontSize: { if (i < clparams.argc){ - settings->font_size = str_to_int(clparams.argv[i]); + settings->font_size = str_to_int_c(clparams.argv[i]); } action = CLAct_Nothing; }break; @@ -1601,7 +1601,7 @@ App_Init_Sig(app_init){ // TODO(allen): more robust allocation solution for the clipboard if (clipboard.str){ String *dest = working_set_next_clipboard_string(&models->mem.general, &models->working_set, clipboard.size); - copy(dest, make_string((char*)clipboard.str, clipboard.size)); + copy_ss(dest, make_string((char*)clipboard.str, clipboard.size)); } // NOTE(allen): style setup @@ -1642,7 +1642,7 @@ update_cli_handle_with_file(System_Functions *system, Models *models, if (system->cli_end_update(cli)){ char str_space[256]; String str = make_fixed_width_string(str_space); - append(&str, "exited with code "); + append_ss(&str, make_lit_string("exited with code ")); append_int_to_str(&str, cli->exit); output_file_append(system, models, file, str, cursor_at_end); result = -1; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 270eecd0..11d3dc47 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -221,17 +221,17 @@ DOC_SEE(Command_Line_Input_Flag) file = get_file_from_identifier(system, working_set, buffer); if (file){ if (file->settings.read_only == 0){ - append(&feedback_str, "ERROR: "); - append(&feedback_str, file->name.live_name); - append(&feedback_str, " is not a read-only buffer\n"); + append_ss(&feedback_str, make_lit_string("ERROR: ")); + append_ss(&feedback_str, file->name.live_name); + append_ss(&feedback_str, make_lit_string(" is not a read-only buffer\n")); do_feedback_message(system, models, feedback_str); result = false; goto done; } if (file->settings.never_kill){ - append(&feedback_str, "The buffer "); - append(&feedback_str, file->name.live_name); - append(&feedback_str, " is not killable"); + append_ss(&feedback_str, make_lit_string("The buffer ")); + append_ss(&feedback_str, file->name.live_name); + append_ss(&feedback_str, make_lit_string(" is not killable")); do_feedback_message(system, models, feedback_str); result = false; goto done; @@ -240,7 +240,8 @@ DOC_SEE(Command_Line_Input_Flag) else if (buffer.name){ file = working_set_alloc_always(working_set, general); if (file == 0){ - append(&feedback_str, "ERROR: unable to allocate a new buffer\n"); + append_ss(&feedback_str, + make_lit_string("ERROR: unable to allocate a new buffer\n")); do_feedback_message(system, models, feedback_str); result = false; goto done; @@ -277,7 +278,8 @@ DOC_SEE(Command_Line_Input_Flag) } } else{ - append(&feedback_str, "did not begin command-line command because the target buffer is already in use\n"); + append_ss(&feedback_str, + make_lit_string("did not begin command-line command because the target buffer is already in use\n")); do_feedback_message(system, models, feedback_str); result = false; goto done; @@ -326,7 +328,7 @@ DOC_SEE(Command_Line_Input_Flag) } } else{ - append(&feedback_str, "ERROR: no available process slot\n"); + append_ss(&feedback_str, make_lit_string("ERROR: no available process slot\n")); do_feedback_message(system, models, feedback_str); result = false; goto done; @@ -357,7 +359,7 @@ DOC_SEE(The_4coder_Clipboard) Working_Set *working = &models->working_set; String *dest = working_set_next_clipboard_string(general, working, len); - copy(dest, make_string(str, len)); + copy_ss(dest, make_string(str, len)); system->post_clipboard(*dest); } @@ -396,8 +398,8 @@ DOC_SEE(The_4coder_Clipboard) if (str){ size = str->size; if (out){ - String out_str = make_string(out, 0, len); - copy(&out_str, *str); + String out_str = make_string_cap(out, 0, len); + copy_ss(&out_str, *str); } } @@ -1904,7 +1906,7 @@ DOC(This call changes 4coder's color pallet to one of the built in themes.) Style *s = styles->styles; for (i = 0; i < count; ++i, ++s){ - if (match(s->name, theme_name)){ + if (match_ss(s->name, theme_name)){ style_copy(main_style(cmd->models), s); break; } diff --git a/4ed_file.cpp b/4ed_file.cpp index 7753dec0..277f20e5 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -364,7 +364,7 @@ tbl_name_compare(void *a, void *b, void *arg){ File_Name_Entry *fb = (File_Name_Entry*)b; i32 result = 1; - if (match(*fa, fb->name)){ + if (match_ss(*fa, fb->name)){ result = 0; } @@ -635,7 +635,7 @@ working_set_lookup_file(Working_Set *working_set, String string){ used_nodes = &working_set->used_sentinel; for (dll_items(node, used_nodes)){ file = (Editing_File*)node; - if (string.size == 0 || match(string, file->name.live_name)){ + if (string.size == 0 || match_ss(string, file->name.live_name)){ break; } } @@ -647,7 +647,7 @@ working_set_lookup_file(Working_Set *working_set, String string){ used_nodes = &working_set->used_sentinel; for (dll_items(node, used_nodes)){ file = (Editing_File*)node; - if (string.size == 0 || has_substr(file->name.live_name, string)){ + if (string.size == 0 || has_substr_s(file->name.live_name, string)){ break; } } @@ -690,7 +690,9 @@ hot_directory_quick_partition(File_Info *infos, i32 start, i32 pivot){ for (i32 i = start; i < pivot; ++i, ++a){ i32 comp = 0; comp = p->folder - a->folder; - if (comp == 0) comp = compare(a->filename, p->filename); + if (comp == 0){ + comp = compare_cc(a->filename, p->filename); + } if (comp < 0){ Swap(File_Info, *a, infos[start]); ++start; @@ -717,7 +719,7 @@ hot_directory_fixup(Hot_Directory *hot_directory, Working_Set *working_set){ inline void hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String str, Working_Set *working_set){ - b32 success = copy_checked(&hot_directory->string, str); + b32 success = copy_checked_ss(&hot_directory->string, str); terminate_with_null(&hot_directory->string); if (success){ if (str.size > 0){ @@ -741,8 +743,8 @@ hot_directory_init(Hot_Directory *hot_directory, String base, String dir, char s hot_directory->string = base; hot_directory->string.str[255] = 0; hot_directory->string.size = 0; - copy(&hot_directory->string, dir); - append(&hot_directory->string, slash); + copy_ss(&hot_directory->string, dir); + append_s_char(&hot_directory->string, slash); hot_directory->slash = slash; } @@ -755,7 +757,7 @@ internal b32 filename_match(String query, Absolutes *absolutes, String filename, b32 case_sensitive){ b32 result; result = (query.size == 0); - if (!result) result = wildcard_match(absolutes, filename, case_sensitive); + if (!result) result = wildcard_match_s(absolutes, filename, case_sensitive); return result; } @@ -858,15 +860,15 @@ internal void buffer_get_new_name(Working_Set *working_set, Editing_File_Name *name, String filename){ Assert(name->live_name.str != 0); - copy_checked(&name->source_path, filename); - copy(&name->live_name, front_of_directory(filename)); + copy_checked_ss(&name->source_path, filename); + copy_ss(&name->live_name, front_of_directory(filename)); if (name->source_path.size == name->live_name.size){ name->extension.size = 0; } else{ String ext = file_extension(filename); - copy(&name->extension, ext); + copy_ss(&name->extension, ext); } { @@ -880,7 +882,7 @@ buffer_get_new_name(Working_Set *working_set, Editing_File_Name *name, String fi for (dll_items(node, used_nodes)){ Editing_File *file_ptr = (Editing_File*)node; if (file_is_ready(file_ptr)){ - if (match(name->live_name, file_ptr->name.live_name)){ + if (match_ss(name->live_name, file_ptr->name.live_name)){ ++file_x; hit_conflict = 1; break; @@ -890,9 +892,9 @@ buffer_get_new_name(Working_Set *working_set, Editing_File_Name *name, String fi if (hit_conflict){ name->live_name.size = original_len; - append(&name->live_name, " <"); + append_ss(&name->live_name, make_lit_string(" <")); append_int_to_str(&name->live_name, file_x); - append(&name->live_name, ">"); + append_s_char(&name->live_name, '>'); } } } @@ -913,7 +915,7 @@ buffer_bind_file(System_Functions *system, General_Memory *general, Working_Set Assert(file->canon.name.size == 0); file->canon.name = make_fixed_width_string(file->canon.name_); - copy(&file->canon.name, canon_filename); + copy_ss(&file->canon.name, canon_filename); terminate_with_null(&file->canon.name); system->add_listener(file->canon.name_); b32 result = working_set_canon_add(general, working_set, file, file->canon.name); @@ -944,9 +946,9 @@ buffer_bind_name(General_Memory *general, Working_Set *working_set, buffer_get_new_name(working_set, &new_name, filename); editing_file_name_init(&file->name); - copy(&file->name.live_name, new_name.live_name); - copy(&file->name.source_path, new_name.source_path); - copy(&file->name.extension, new_name.extension); + copy_ss(&file->name.live_name, new_name.live_name); + copy_ss(&file->name.source_path, new_name.source_path); + copy_ss(&file->name.extension, new_name.extension); b32 result = working_set_name_add(general, working_set, file, file->name.live_name); Assert(result); AllowLocal(result); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index d8e68f85..810218de 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -2434,7 +2434,7 @@ working_set_next_clipboard_string(General_Memory *general, Working_Set *working, new_str = (char*)general_memory_allocate(general, str_size+1); } // TODO(allen): What if new_str == 0? - *result = make_string(new_str, 0, str_size); + *result = make_string_cap(new_str, 0, str_size); return result; } @@ -3123,8 +3123,8 @@ view_show_file(View *view){ internal String make_string_terminated(Partition *part, char *str, i32 len){ char *space = (char*)push_array(part, char, len + 1); - String string = make_string(str, len, len+1); - copy_fast_unsafe(space, string); + String string = make_string_cap(str, len, len+1); + copy_fast_unsafe_cs(space, string); string.str = space; terminate_with_null(&string); return(string); @@ -3317,7 +3317,7 @@ interactive_begin_sure_to_kill(System_Functions *system, View *view, Editing_Fil view_show_interactive(system, view, IAct_Sure_To_Kill, IInt_Sure_To_Kill, make_lit_string("Are you sure?")); - copy(&view->dest, file->name.live_name); + copy_ss(&view->dest, file->name.live_name); } enum Try_Kill_Result{ @@ -3638,9 +3638,9 @@ begin_exhaustive_loop(Exhaustive_File_Loop *loop, Hot_Directory *hdir){ loop->infos = hdir->file_list.infos; loop->count = hdir->file_list.count; - copy(&loop->front_name, front_of_directory(hdir->string)); + copy_ss(&loop->front_name, front_of_directory(hdir->string)); get_absolutes(loop->front_name, &loop->absolutes, 1, 1); - copy(&loop->full_path, path_of_directory(hdir->string)); + copy_ss(&loop->full_path, path_of_directory(hdir->string)); loop->r = loop->full_path.size; } @@ -3655,7 +3655,7 @@ get_exhaustive_info(System_Functions *system, Working_Set *working_set, Exhausti result.info = loop->infos + i; loop->full_path.size = loop->r; - append(&loop->full_path, result.info->filename); + append_sc(&loop->full_path, result.info->filename); terminate_with_null(&loop->full_path); Editing_File_Canon_Name canon_name; @@ -3664,8 +3664,8 @@ get_exhaustive_info(System_Functions *system, Working_Set *working_set, Exhausti file = working_set_canon_contains(working_set, canon_name.name); } - String filename = make_string(result.info->filename, - result.info->filename_len, result.info->filename_len+1); + String filename = make_string_cap(result.info->filename, + result.info->filename_len, result.info->filename_len+1); result.is_folder = (result.info->folder != 0); result.name_match = (filename_match(loop->front_name, &loop->absolutes, filename, 0) != 0); @@ -3854,9 +3854,9 @@ internal void append_label(String *string, i32 indent_level, char *message){ i32 r = 0; for (r = 0; r < indent_level; ++r){ - append(string, '>'); + append_s_char(string, '>'); } - append(string, message); + append_sc(string, message); } internal void @@ -3866,8 +3866,8 @@ show_gui_line(GUI_Target *target, String *string, append_label(string, indent_level, message); if (follow_up){ append_padding(string, '-', h_align); - append(string, ' '); - append(string, follow_up); + append_s_char(string, ' '); + append_sc(string, follow_up); } gui_do_text_field(target, *string, string_zero()); } @@ -3878,7 +3878,7 @@ show_gui_int(GUI_Target *target, String *string, string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); - append(string, ' '); + append_s_char(string, ' '); append_int_to_str(string, x); gui_do_text_field(target, *string, string_zero()); } @@ -3889,7 +3889,7 @@ show_gui_u64(GUI_Target *target, String *string, string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); - append(string, ' '); + append_s_char(string, ' '); append_u64_to_str(string, x); gui_do_text_field(target, *string, string_zero()); } @@ -3900,9 +3900,9 @@ show_gui_int_int(GUI_Target *target, String *string, string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); - append(string, ' '); + append_s_char(string, ' '); append_int_to_str(string, x); - append(string, '/'); + append_s_char(string, '/'); append_int_to_str(string, m); gui_do_text_field(target, *string, string_zero()); } @@ -3913,10 +3913,10 @@ show_gui_id(GUI_Target *target, String *string, string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); - append(string, " [0]: "); + append_ss(string, make_lit_string(" [0]: ")); append_u64_to_str(string, id.id[0]); append_padding(string, ' ', h_align + 26); - append(string, " [1]: "); + append_ss(string, make_lit_string(" [1]: ")); append_u64_to_str(string, id.id[1]); gui_do_text_field(target, *string, string_zero()); } @@ -3927,7 +3927,7 @@ show_gui_float(GUI_Target *target, String *string, string->size = 0; append_label(string, indent_level, message); append_padding(string, '-', h_align); - append(string, ' '); + append_s_char(string, ' '); append_float_to_str(string, x); gui_do_text_field(target, *string, string_zero()); } @@ -3979,11 +3979,11 @@ struct View_Step_Result{ inline void gui_show_mouse(GUI_Target *target, String *string, i32 mx, i32 my){ string->size = 0; - append(string, "mouse: ("); + append_ss(string, make_lit_string("mouse: (")); append_int_to_str(string, mx); - append(string, ","); + append_s_char(string, ','); append_int_to_str(string, my); - append(string, ")"); + append_s_char(string, ')'); gui_do_text_field(target, *string, string_zero()); } @@ -4190,8 +4190,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su else{ char message_space[256]; message = make_fixed_width_string(message_space); - copy(&message, make_lit_string("currently selected: ")); - append(&message, info->name); + copy_ss(&message, make_lit_string("currently selected: ")); + append_ss(&message, info->name); gui_do_font_button(target, id, i, message); } } @@ -4384,19 +4384,19 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (file_info.name_match){ id.id[0] = (u64)(file_info.info); - String filename = make_string(file_info.info->filename, - file_info.info->filename_len, - file_info.info->filename_len+1); + String filename = make_string_cap(file_info.info->filename, + file_info.info->filename_len, + file_info.info->filename_len+1); if (gui_do_file_option(target, id, filename, file_info.is_folder, file_info.message)){ if (file_info.is_folder){ - set_last_folder(&hdir->string, file_info.info->filename, '/'); + set_last_folder_sc(&hdir->string, file_info.info->filename, '/'); do_new_directory = 1; } else if (use_item_in_list){ complete = 1; - copy(&comp_dest, loop.full_path); + copy_ss(&comp_dest, loop.full_path); } } } @@ -4406,7 +4406,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (activate_directly){ complete = 1; - copy(&comp_dest, hdir->string); + copy_ss(&comp_dest, hdir->string); } if (do_new_directory){ @@ -4502,7 +4502,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su id.id[0] = (u64)(file); if (gui_do_file_option(target, id, file->name.live_name, 0, message)){ complete = 1; - copy(&comp_dest, file->name.live_name); + copy_ss(&comp_dest, file->name.live_name); } } } @@ -4523,7 +4523,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su id.id[0] = (u64)(file); if (gui_do_file_option(target, id, file->name.live_name, 0, message)){ complete = 1; - copy(&comp_dest, file->name.live_name); + copy_ss(&comp_dest, file->name.live_name); } } @@ -4558,7 +4558,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (action != -1){ complete = 1; - copy(&comp_dest, view->dest); + copy_ss(&comp_dest, view->dest); comp_action = action; } }break; @@ -4592,7 +4592,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (action != -1){ complete = 1; - copy(&comp_dest, view->dest); + copy_ss(&comp_dest, view->dest); comp_action = action; } }break; @@ -4633,7 +4633,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su string.size = 0; u64 time = system->now_time(); - append(&string, "last redraw: "); + append_ss(&string, make_lit_string("last redraw: ")); append_u64_to_str(&string, time); gui_do_text_field(target, string, empty_str); @@ -4680,60 +4680,60 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su string.size = 0; if (input_event->is_hold){ - append(&string, "hold: "); + append_ss(&string, make_lit_string("hold: ")); } else{ - append(&string, "press: "); + append_ss(&string, make_lit_string("press: ")); } if (input_event->is_ctrl){ - append(&string, "ctrl-"); + append_ss(&string, make_lit_string("ctrl-")); } else{ - append(&string, " -"); + append_ss(&string, make_lit_string(" -")); } if (input_event->is_alt){ - append(&string, "alt-"); + append_ss(&string, make_lit_string("alt-")); } else{ - append(&string, " -"); + append_ss(&string, make_lit_string(" -")); } if (input_event->is_shift){ - append(&string, "shift "); + append_ss(&string, make_lit_string("shift ")); } else{ - append(&string, " "); + append_ss(&string, make_lit_string(" ")); } if (input_event->key > ' ' && input_event->key <= '~'){ - append(&string, make_string(&input_event->key, 1)); + append_ss(&string, make_string(&input_event->key, 1)); } else if (input_event->key == ' '){ - append(&string, "space"); + append_ss(&string, make_lit_string("space")); } else if (input_event->key == '\n'){ - append(&string, "\\n"); + append_ss(&string, make_lit_string("\\n")); } else if (input_event->key == '\t'){ - append(&string, "\\t"); + append_ss(&string, make_lit_string("\\t")); } else{ String str; str.str = global_key_name(input_event->key, &str.size); if (str.str){ str.memory_size = str.size + 1; - append(&string, str); + append_ss(&string, str); } else{ - append(&string, "unrecognized!"); + append_ss(&string, make_lit_string("unrecognized!")); } } if (input_event->consumer[0] != 0){ append_padding(&string, ' ', 40); - append(&string, input_event->consumer); + append_sc(&string, input_event->consumer); } gui_do_text_field(target, string, empty_str); @@ -4750,21 +4750,21 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su threads, &pending); string.size = 0; - append(&string, "pending jobs: "); + append_ss(&string, make_lit_string("pending jobs: ")); append_int_to_str(&string, pending); gui_do_text_field(target, string, empty_str); for (i32 i = 0; i < 4; ++i){ string.size = 0; - append(&string, "thread "); + append_ss(&string, make_lit_string("thread ")); append_int_to_str(&string, i); - append(&string, ": "); + append_ss(&string, make_lit_string(": ")); if (threads[i]){ - append(&string, "running"); + append_ss(&string, make_lit_string("running")); } else{ - append(&string, "waiting"); + append_ss(&string, make_lit_string("waiting")); } gui_do_text_field(target, string, empty_str); @@ -4775,9 +4775,9 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su General_Memory *general = &models->mem.general; string.size = 0; - append(&string, "part memory: "); + append_ss(&string, make_lit_string("part memory: ")); append_int_to_str(&string, part->pos); - append(&string, "/"); + append_s_char(&string, '/'); append_int_to_str(&string, part->max); gui_do_text_field(target, string, empty_str); @@ -4786,10 +4786,10 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su for (dll_items(bubble, sentinel)){ string.size = 0; if (bubble->flags & MEM_BUBBLE_USED){ - append(&string, " used: "); + append_ss(&string, make_lit_string(" used: ")); } else{ - append(&string, " free: "); + append_ss(&string, make_lit_string(" free: ")); } append_int_to_str(&string, bubble->size); @@ -4826,28 +4826,28 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su View *view_ptr = views_to_inspect[i]; string.size = 0; - append(&string, "view: "); + append_ss(&string, make_lit_string("view: ")); append_int_to_str(&string, view_ptr->persistent.id + 1); gui_do_text_field(target, string, empty_str); string.size = 0; Editing_File *file = view_ptr->file_data.file; - append(&string, " > buffer: "); + append_ss(&string, make_lit_string(" > buffer: ")); if (file){ - append(&string, file->name.live_name); + append_ss(&string, file->name.live_name); gui_do_text_field(target, string, empty_str); string.size = 0; - append(&string, " >> buffer-slot-id: "); + append_ss(&string, make_lit_string(" >> buffer-slot-id: ")); append_int_to_str(&string, file->id.id); } else{ - append(&string, "*NULL*"); + append_ss(&string, make_lit_string("*NULL*")); gui_do_text_field(target, string, empty_str); } if (low_detail){ string.size = 0; - append(&string, "inspect this"); + append_ss(&string, make_lit_string("inspect this")); id.id[0] = (u64)(view_ptr->persistent.id); if (gui_do_button(target, id, string)){ @@ -4858,15 +4858,15 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su gui_show_mouse(target, &string, input.mouse.x, input.mouse.y); -#define SHOW_GUI_BLANK(n) show_gui_line(target, &string, n, 0, "", 0) -#define SHOW_GUI_LINE(n, str) show_gui_line(target, &string, n, 0, " " str, 0) +#define SHOW_GUI_BLANK(n) show_gui_line(target, &string, n, 0, "", 0) +#define SHOW_GUI_LINE(n, str) show_gui_line(target, &string, n, 0, " " str, 0) #define SHOW_GUI_STRING(n, h, str, mes) show_gui_line(target, &string, n, h, " " str " ", mes) -#define SHOW_GUI_INT(n, h, str, v) show_gui_int(target, &string, n, h, " " str " ", v) +#define SHOW_GUI_INT(n, h, str, v) show_gui_int(target, &string, n, h, " " str " ", v) #define SHOW_GUI_INT_INT(n, h, str, v, m) show_gui_int_int(target, &string, n, h, " " str " ", v, m) -#define SHOW_GUI_U64(n, h, str, v) show_gui_u64(target, &string, n, h, " " str " ", v) -#define SHOW_GUI_ID(n, h, str, v) show_gui_id(target, &string, n, h, " " str, v) +#define SHOW_GUI_U64(n, h, str, v) show_gui_u64(target, &string, n, h, " " str " ", v) +#define SHOW_GUI_ID(n, h, str, v) show_gui_id(target, &string, n, h, " " str, v) #define SHOW_GUI_FLOAT(n, h, str, v) show_gui_float(target, &string, n, h, " " str " ", v) -#define SHOW_GUI_BOOL(n, h, str, v) do { if (v) { show_gui_line(target, &string, n, h, " " str " ", "true"); }\ +#define SHOW_GUI_BOOL(n, h, str, v) do { if (v) { show_gui_line(target, &string, n, h, " " str " ", "true"); }\ else { show_gui_line(target, &string, n, h, " " str " ", "false"); } } while(false) #define SHOW_GUI_SCROLL(n, h, str, v) show_gui_scroll(target, &string, n, h, " " str, v) @@ -5566,9 +5566,9 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re else{ char line_number_space[30]; String line_number = make_fixed_width_string(line_number_space); - append(&line_number, " L#"); + append_ss(&line_number, make_lit_string(" L#")); append_int_to_str(&line_number, view->edit_pos->cursor.line); - append(&line_number, " C#"); + append_ss(&line_number, make_lit_string(" C#")); append_int_to_str(&line_number, view->edit_pos->cursor.character); intbar_draw_string(target, &bar, line_number, base_color); @@ -5870,7 +5870,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol String m = gui_read_string(&ptr); if (folder){ - append(&f, system->slash); + append_s_char(&f, system->slash); } draw_fat_option_block(gui_target, target, view, font_id, gui_session.rect, b->id, f, m); diff --git a/4ed_font_set.cpp b/4ed_font_set.cpp index 8ecbcd17..386c906c 100644 --- a/4ed_font_set.cpp +++ b/4ed_font_set.cpp @@ -217,7 +217,7 @@ font_set_find_pos(Font_Set *set, String name, u32 *position){ if (i == set->max) i = 0; entry = set->entries + i; if (entry->hash == hash){ - if (match(name, entry->name)){ + if (match_ss(name, entry->name)){ result = 1; *position = i; break; diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index f16f6d2d..2496e315 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -365,6 +365,7 @@ struct Function_Set{ String *args; String *body; String *marker; + String *cpp_name; String *doc_string; @@ -441,7 +442,7 @@ file_dump(char *filename){ String get_first_line(String source){ String line = {0}; - int pos = find(source, 0, '\n'); + int pos = find_s_char(source, 0, '\n'); line = substr(source, 0, pos); @@ -459,7 +460,7 @@ get_next_line(String source, String line){ start = pos + 1; if (start < source.size){ - pos = find(source, start, '\n'); + pos = find_s_char(source, start, '\n'); next = substr(source, start, pos - start); } } @@ -824,7 +825,7 @@ parse_struct_next_member(Partition *part, (token->flags & CPP_TFLAG_IS_KEYWORD)){ String lexeme = make_string(data + token->start, token->size); - if (match(lexeme, make_lit_string("struct"))){ + if (match_ss(lexeme, make_lit_string("struct"))){ Struct_Member *member = push_struct(part, Struct_Member); if (parse_struct(part, true, data, tokens, count, &token, member)){ result = member; @@ -834,7 +835,7 @@ parse_struct_next_member(Partition *part, assert(!"unhandled error"); } } - else if (match(lexeme, make_lit_string("union"))){ + else if (match_ss(lexeme, make_lit_string("union"))){ Struct_Member *member = push_struct(part, Struct_Member); if (parse_struct(part, false, data, tokens, count, &token, member)){ result = member; @@ -960,8 +961,8 @@ print_struct_html(FILE *file, Struct_Member *member){ String type = member->type; String type_postfix = member->type_postfix; - if (match(type, make_lit_string("struct")) || - match(type, make_lit_string("union"))){ + if (match_ss(type, make_lit_string("struct")) || + match_ss(type, make_lit_string("union"))){ fprintf(file, "%.*s %.*s {
    \n" "
    \n", @@ -1086,8 +1087,8 @@ print_struct_docs(FILE *file, Partition *part, Struct_Member *member){ member_iter != 0; member_iter = member_iter->next_sibling){ String type = member_iter->type; - if (match(type, make_lit_string("struct")) || - match(type, make_lit_string("union"))){ + if (match_ss(type, make_lit_string("struct")) || + match_ss(type, make_lit_string("union"))){ print_struct_docs(file, part, member_iter); } else{ @@ -1248,17 +1249,19 @@ allocate_app_api(int count){ static Function_Set allocate_function_set(int count){ Function_Set function_set = {0}; - int memory_size = (sizeof(String)*6 + + int memory_size = (sizeof(String)*7 + sizeof(int)*2 + sizeof(Argument_Breakdown) + sizeof(Documentation))*count; - function_set.name = (String*)malloc(memory_size); - function_set.ret = function_set.name + count; - function_set.args = function_set.ret + count; - function_set.body = function_set.args + count; - function_set.marker = function_set.body + count; - function_set.doc_string = function_set.marker + count; + String *str_ptr = (String*)malloc(memory_size); + function_set.name = str_ptr; str_ptr += count; + function_set.ret = str_ptr; str_ptr += count; + function_set.args = str_ptr; str_ptr += count; + function_set.body = str_ptr; str_ptr += count; + function_set.marker = str_ptr; str_ptr += count; + function_set.cpp_name = str_ptr; str_ptr += count; + function_set.doc_string = str_ptr; str_ptr += count; function_set.is_macro = (int*)(function_set.doc_string + count); function_set.valid = function_set.is_macro + count; @@ -1390,9 +1393,48 @@ do_function_get_doc(int *index, Cpp_Token **token_ptr, int count, return(result); } +static String +get_lexeme(Cpp_Token token, char *code){ + String str = make_string(code + token.start, token.size); + return(str); +} + +static int +do_parse_cpp_name(int *i_ptr, Cpp_Token **token_ptr, int count, char *data, String *name){ + int result = false; + + int i = *i_ptr; + Cpp_Token *token = *token_ptr; + + int i_start = i; + Cpp_Token *token_start = token; + + ++i, ++token; + if (i < count && token->type == CPP_TOKEN_PARENTHESE_OPEN){ + ++i, ++token; + if (i < count && token->type == CPP_TOKEN_IDENTIFIER){ + ++i, ++token; + if (i < count && token->type == CPP_TOKEN_PARENTHESE_CLOSE){ + *name = get_lexeme(*(token-1), data); + result = true; + } + } + } + + if (!result){ + i = i_start; + token = token_start; + } + + *i_ptr = i; + *token_ptr = token; + + return(result); +} + static int do_function_parse(int *index, Cpp_Token **token_ptr, int count, Cpp_Token *ret_start_token, - char *data, Function_Set function_set, int sig_count){ + char *data, Function_Set function_set, int sig_count, String cpp_name){ int result = false; int i = *index; @@ -1422,6 +1464,8 @@ do_function_parse(int *index, Cpp_Token **token_ptr, int count, Cpp_Token *ret_s Argument_Breakdown *breakdown = &function_set.breakdown[sig_count]; *breakdown = do_parameter_parse(data, args_start_token, token); + + function_set.cpp_name[sig_count] = cpp_name; } *index = i; @@ -1432,7 +1476,7 @@ do_function_parse(int *index, Cpp_Token **token_ptr, int count, Cpp_Token *ret_s static int do_full_function_parse(int *index, Cpp_Token **token_ptr, int count, char *data, - Function_Set function_set, int sig_count){ + Function_Set function_set, int sig_count, String cpp_name){ int result = false; int i = *index; @@ -1458,7 +1502,7 @@ do_full_function_parse(int *index, Cpp_Token **token_ptr, int count, char *data, Cpp_Token *ret_start_token = token; if (do_function_parse_check(&i, &token, count)){ if (do_function_parse(&i, &token, count, ret_start_token, - data, function_set, sig_count)){ + data, function_set, sig_count, cpp_name)){ result = true; } } @@ -1580,22 +1624,26 @@ struct String_Function_Marker{ int parse_function; int is_inline; int parse_doc; + int cpp_name; }; static String_Function_Marker do_string_function_marker_check(String lexeme){ String_Function_Marker result = {0}; - if (match(lexeme, "FSTRING_INLINE")){ + if (match_ss(lexeme, make_lit_string("FSTRING_INLINE"))){ result.is_inline = true; result.parse_function = true; } - else if (match(lexeme, "FSTRING_LINK")){ + else if (match_ss(lexeme, make_lit_string("FSTRING_LINK"))){ result.parse_function = true; } - else if (match(lexeme, "DOC_EXPORT")){ + else if (match_ss(lexeme, make_lit_string("DOC_EXPORT"))){ result.parse_doc = true; } + else if (match_ss(lexeme, make_lit_string("CPP_NAME"))){ + result.cpp_name = true; + } return(result); } @@ -1792,6 +1840,9 @@ generate_custom_headers(){ Cpp_Token *tokens = token_stack->tokens; Cpp_Token *token = tokens; + String cpp_name = {0}; + int has_cpp_name = 0; + for (int i = 0; i < count; ++i, ++token){ if (token->type == CPP_TOKEN_IDENTIFIER && !(token->flags & CPP_TFLAG_PP_BODY)){ @@ -1800,9 +1851,15 @@ generate_custom_headers(){ String_Function_Marker marker = do_string_function_marker_check(lexeme); - if (marker.parse_function){ + if (marker.cpp_name){ + if (do_parse_cpp_name(&i, &token, count, data, &cpp_name)){ + has_cpp_name = 1; + } + } + else if (marker.parse_function){ if (do_full_function_parse(&i, &token, count, data, - string_function_set, string_sig_count)){ + string_function_set, string_sig_count, + cpp_name)){ ++string_sig_count; } } @@ -1813,6 +1870,13 @@ generate_custom_headers(){ ++string_sig_count; } } + + if (has_cpp_name){ + has_cpp_name = 0; + } + else{ + cpp_name = string_zero(); + } } } } @@ -1846,7 +1910,7 @@ generate_custom_headers(){ if (token->type == CPP_TOKEN_IDENTIFIER && !(token->flags & CPP_TFLAG_PP_BODY)){ String lexeme = make_string(data + token->start, token->size); - if (match(lexeme, "API_EXPORT")){ + if (match_ss(lexeme, make_lit_string("API_EXPORT"))){ if (do_function_parse_check(&i, &token, count)){ ++line_count; } @@ -1874,8 +1938,9 @@ generate_custom_headers(){ if (token->type == CPP_TOKEN_IDENTIFIER && !(token->flags & CPP_TFLAG_PP_BODY)){ String lexeme = make_string(data + token->start, token->size); - if (match(lexeme, "API_EXPORT")){ - do_full_function_parse(&i, &token, count, data, function_set, sig_count); + if (match_ss(lexeme, make_lit_string("API_EXPORT"))){ + do_full_function_parse(&i, &token, count, data, function_set, + sig_count, string_zero()); if (!function_set.valid[sig_count]){ zero_index(function_set, sig_count); // TODO(allen): get warning file name and line numbers @@ -1896,16 +1961,16 @@ generate_custom_headers(){ macro->memory_size = name_string.size+4; macro->str = (char*)malloc(macro->memory_size); - copy(macro, name_string); + copy_ss(macro, name_string); to_upper(macro); - append(macro, make_lit_string("_SIG")); + append_ss(macro, make_lit_string("_SIG")); public_name->size = 0; public_name->memory_size = name_string.size; public_name->str = (char*)malloc(public_name->memory_size); - copy(public_name, name_string); + copy_ss(public_name, name_string); to_lower(public_name); } @@ -2197,7 +2262,7 @@ generate_custom_headers(){ if (token->type == CPP_TOKEN_IDENTIFIER && !(token->flags & CPP_TFLAG_PP_BODY)){ String lexeme = make_string(code->str + token->start, token->size); - if (match(lexeme, "FSTRING_BEGIN")){ + if (match_ss(lexeme, make_lit_string("FSTRING_BEGIN"))){ start = token->start + token->size; break; } @@ -2216,13 +2281,17 @@ generate_custom_headers(){ do_whitespace_print = true; } - String lexeme = make_string(code->str + token->start, token->size); + String lexeme = get_lexeme(*token, code->str); int do_print = true; - if (match(lexeme, "FSTRING_DECLS")){ - fprintf(file, "#ifndef FCODER_STRING_H\n#define FCODER_STRING_H\n\n"); + if (match_ss(lexeme, make_lit_string("FSTRING_DECLS"))){ + fprintf(file, "#if !defined(FCODER_STRING_H)\n#define FCODER_STRING_H\n\n"); do_print = false; + +#define RETURN_PADDING 16 +#define SIG_PADDING 30 + for (int j = 0; j < string_sig_count; ++j){ char line_space[2048]; String line = make_fixed_width_string(line_space); @@ -2233,12 +2302,12 @@ generate_custom_headers(){ String name = string_function_set.name[j]; String args = string_function_set.args[j]; - append(&line, marker); - append_padding(&line, ' ', 16); - append(&line, ret); - append_padding(&line, ' ', 30); - append(&line, name); - append(&line, args); + append_ss(&line, marker); + append_padding(&line, ' ', RETURN_PADDING); + append_ss(&line, ret); + append_padding(&line, ' ', SIG_PADDING); + append_ss(&line, name); + append_ss(&line, args); terminate_with_null(&line); fprintf(file, "%s;\n", line.str); @@ -2248,32 +2317,117 @@ generate_custom_headers(){ String args = string_function_set.args[j]; String body = string_function_set.body[j]; - append(&line, "#ifndef "); + append_ss(&line, make_lit_string("#ifndef ")); append_padding(&line, ' ', 10); - append(&line, name); + append_ss(&line, name); terminate_with_null(&line); fprintf(file, "%s\n", line.str); line.size = 0; - append(&line, "# define "); + append_ss(&line, make_lit_string("# define ")); append_padding(&line, ' ', 10); - append(&line, name); - append(&line, args); - append(&line, ' '); - append(&line, body); + append_ss(&line, name); + append_ss(&line, args); + append_s_char(&line, ' '); + append_ss(&line, body); terminate_with_null(&line); fprintf(file, "%s\n", line.str); line.size = 0; - append(&line, "#endif"); + append_ss(&line, make_lit_string("#endif")); terminate_with_null(&line); fprintf(file, "%s\n", line.str); } } + { + fprintf(file, "\n#if !defined(FSTRING_C)\n\n" + "// NOTE(allen): This section is here to enable nicer names\n" + "// for C++ users who can have overloaded functions. None of\n" + "// these functions add new features.\n"); + + for (int j = 0; j < string_sig_count; ++j){ + char line_space[2048]; + String line = make_fixed_width_string(line_space); + + if (!string_function_set.is_macro[j]){ + String cpp_name = string_function_set.cpp_name[j]; + if (cpp_name.str != 0){ + String ret = string_function_set.ret[j]; + String args = string_function_set.args[j]; + + append_ss(&line, make_lit_string("FSTRING_INLINE")); + append_padding(&line, ' ', RETURN_PADDING); + append_ss(&line, ret); + append_padding(&line, ' ', SIG_PADDING); + append_ss(&line, cpp_name); + append_ss(&line, args); + terminate_with_null(&line); + + fprintf(file, "%s;\n", line.str); + } + } + } + + fprintf(file, "\n#endif\n"); + } + fprintf(file, "\n#endif\n"); + + { + fprintf(file, "\n#if !defined(FSTRING_C) && !defined(FSTRING_GUARD)\n\n"); + + for (int j = 0; j < string_sig_count; ++j){ + char line_space[2048]; + String line = make_fixed_width_string(line_space); + + if (!string_function_set.is_macro[j]){ + String cpp_name = string_function_set.cpp_name[j]; + if (cpp_name.str != 0){ + String name = string_function_set.name[j]; + String ret = string_function_set.ret[j]; + String args = string_function_set.args[j]; + Argument_Breakdown breakdown = string_function_set.breakdown[j]; + + append_ss(&line, make_lit_string("FSTRING_INLINE")); + append_s_char(&line, ' '); + append_ss(&line, ret); + append_s_char(&line, '\n'); + append_ss(&line, cpp_name); + append_ss(&line, args); + if (match_ss(ret, make_lit_string("void"))){ + append_ss(&line, make_lit_string("{ (")); + } + else{ + append_ss(&line, make_lit_string("{ return(")); + } + append_ss(&line, name); + append_s_char(&line, '('); + + if (breakdown.count > 0){ + for (int32_t i = 0; i < breakdown.count; ++i){ + if (i != 0){ + append_s_char(&line, ','); + } + append_ss(&line, breakdown.param_name[i]); + } + } + else{ + append_ss(&line, make_lit_string("void")); + } + + append_ss(&line, make_lit_string("));}")); + terminate_with_null(&line); + + fprintf(file, "%s\n", line.str); + } + } + } + + fprintf(file, "\n#endif\n"); + } } - else if (match(lexeme, "DOC_EXPORT")){ + else if (match_ss(lexeme, make_lit_string("DOC_EXPORT"))){ ++i, ++token; if (i < count && token->type == CPP_TOKEN_COMMENT){ ++i, ++token; @@ -2290,9 +2444,9 @@ generate_custom_headers(){ } } } - else if (match(lexeme, "FSTRING_INLINE")){ + else if (match_ss(lexeme, make_lit_string("FSTRING_INLINE"))){ if (!(token->flags & CPP_TFLAG_PP_BODY)){ - fprintf(file, "#ifndef FSTRING_GUARD\n"); + fprintf(file, "#if !defined(FSTRING_GUARD)\n"); print_function_body_code(file, &i, &token, count, code, start); @@ -2300,9 +2454,9 @@ generate_custom_headers(){ do_print = false; } } - else if (match(lexeme, "FSTRING_LINK")){ + else if (match_ss(lexeme, make_lit_string("FSTRING_LINK"))){ if (!(token->flags & CPP_TFLAG_PP_BODY)){ - fprintf(file, "#ifdef FSTRING_IMPLEMENTATION\n"); + fprintf(file, "#if defined(FSTRING_IMPLEMENTATION)\n"); print_function_body_code(file, &i, &token, count, code, start); @@ -2310,6 +2464,30 @@ generate_custom_headers(){ do_print = false; } } + else if (match_ss(lexeme, make_lit_string("CPP_NAME"))){ + + Cpp_Token *token_start = token; + int i_start = i; + int has_cpp_name = false; + + ++i, ++token; + if (token->type == CPP_TOKEN_PARENTHESE_OPEN){ + ++i, ++token; + if (token->type == CPP_TOKEN_IDENTIFIER){ + ++i, ++token; + if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){ + has_cpp_name = true; + } + } + } + + if (!has_cpp_name){ + i = i_start; + token = token_start; + } + + do_print = false; + } else if (token->type == CPP_TOKEN_COMMENT){ lexeme = make_string(code->str + token->start, token->size); if (check_and_fix_docs(&lexeme)){ @@ -2909,7 +3087,7 @@ int main(int argc, char **argv){ memset(&global_settings, 0, sizeof(global_settings)); global_settings.generate_docs = true; - global_settings.generate_string = false; + global_settings.generate_string = true; filename = generate_keycode_enum(); filename = generate_style(); diff --git a/4ed_style.cpp b/4ed_style.cpp index d0413575..d46ef063 100644 --- a/4ed_style.cpp +++ b/4ed_style.cpp @@ -28,8 +28,8 @@ style_copy(Style *dst, Style *src){ internal void style_set_name(Style *style, String name){ i32 count = ArrayCount(style->name_); - style->name = make_string(style->name_, 0, count - 1); - copy(&style->name, name); + style->name = make_string_cap(style->name_, 0, count - 1); + copy_ss(&style->name, name); terminate_with_null(&style->name); } diff --git a/build.bat b/build.bat index 92aebd90..72535094 100644 --- a/build.bat +++ b/build.bat @@ -1,6 +1,23 @@ @echo off REM "build_exp.bat" /O2 -"build_all.bat" /DFRED_SUPER /DFRED_INTERNAL /Zi +REM "build_all.bat" /DFRED_SUPER /DFRED_INTERNAL /Zi REM "build_all.bat" /DFRED_INTERNAL /Zi REM "build_all.bat" /DFRED_SUPER /O2 /Zi + +call "ctime" -begin 4ed_data.ctm + +SET OPTS=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX +SET OPTS=/GR- /EHa- /nologo /FC + +SET FirstError=0 + +pushd ..\build +cl %OPTS% ..\code\build.c /Febuild /DDEV_BUILD +if %ERRORLEVEL% neq 0 (set FirstError=1) +popd + +..\build\build +if %ERRORLEVEL% neq 0 (set FirstError=1) + +call "ctime" -end 4ed_data.ctm %FirstError% \ No newline at end of file diff --git a/build.c b/build.c new file mode 100644 index 00000000..628bdc51 --- /dev/null +++ b/build.c @@ -0,0 +1,234 @@ +/* + +4coder development build rule. + +*/ + +// TOP + +#include +#include +#include + +// +// reusable +// + +#define CL_OPTS \ +"/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX "\ +"/GR- /EHa- /nologo /FC" + +#if defined(_MSC_VER) + +#define IS_CL +#define snprintf _snprintf + +#if defined(_WIN32) +# define IS_WINDOWS +# pragma comment(lib, "Kernel32.lib") +#endif + +#else +#error This compiler is not supported yet +#endif + +static char cmd[1024]; +static int error_state = 0; + +#define systemf(...) do{\ + int32_t n = snprintf(cmd, sizeof(cmd), __VA_ARGS__);\ + assert(n < sizeof(cmd));\ + if (system(cmd) != 0) error_state = 1;\ +}while(0) + + +#if defined(IS_WINDOWS) + +#define DWORD uint32_t +#define LPTSTR char* + +DWORD GetCurrentDirectoryA( +_In_ DWORD nBufferLength, +_Out_ LPTSTR lpBuffer +); + +static int32_t +get_current_directory(char *buffer, int32_t max){ + int32_t result = GetCurrentDirectoryA(max, buffer); + return(result); +} + +static void +execute(char *dir, char *str){ + if (dir){ + systemf("pushd %s & call \"%s\"", dir, str); + } + else{ + systemf("call \"%s\"", str); + } +} + +#else +#error This OS is not supported yet +#endif + +// +// 4coder specific +// + +#define CL_INCLUDES \ +"/I..\\foreign /I..\\foreign\\freetype2" + +#define CL_LIBS \ +"user32.lib winmm.lib gdi32.lib opengl32.lib ..\\foreign\\freetype.lib" + +#define CL_ICON \ +"..\\foreign\\freetype.lib" + +static void +swap_ptr(void **A, void **B){ + void *a = *A; + void *b = *B; + *A = b; + *B = a; +} + +static void +win32_slash_fix(char *path){ + for (int32_t i = 0; path[i]; ++i){ + if (path[i] == '/') path[i] = '\\'; + } +} + +enum{ + OPTS = 0x1, + INCLUDES = 0x2, + LIBS = 0x4, + ICON = 0x8, + SHARED_CODE = 0x10, + DEBUG_INFO = 0x20 +}; + + +static void +build_cl(uint32_t flags, + char *code_path, char *code_file, + char *out_path, char *out_file, + char *exports){ + win32_slash_fix(out_path); + + char link_options[1024]; + if (flags & SHARED_CODE){ + assert(exports); + snprintf(link_options, sizeof(link_options), "/OPT:REF %s", exports); + } + else{ + snprintf(link_options, sizeof(link_options), "/NODEFAULTLIB:library"); + } + + char build_optionsA[4096]; + char build_optionsB[4096]; + char *build_options = build_optionsA; + char *build_options_prev = build_optionsB; + int32_t build_max = sizeof(build_optionsA); + + build_optionsA[0] = 0; + build_optionsB[0] = 0; + + if (flags & OPTS){ + snprintf(build_options, build_max, "%s "CL_OPTS, build_options_prev); + swap_ptr(&build_options, &build_options_prev); + } + + if (flags & INCLUDES){ + snprintf(build_options, build_max, "%s "CL_INCLUDES, build_options_prev); + swap_ptr(&build_options, &build_options_prev); + } + + if (flags & LIBS){ + snprintf(build_options, build_max, "%s "CL_LIBS, build_options_prev); + swap_ptr(&build_options, &build_options_prev); + } + + if (flags & ICON){ + snprintf(build_options, build_max, "%s "CL_ICON, build_options_prev); + swap_ptr(&build_options, &build_options_prev); + } + + if (flags & DEBUG_INFO){ + snprintf(build_options, build_max, "%s /Zi", build_options_prev); + swap_ptr(&build_options, &build_options_prev); + } + + if (flags & SHARED_CODE){ + snprintf(build_options, build_max, "%s /LD", build_options_prev); + swap_ptr(&build_options, &build_options_prev); + } + + swap_ptr(&build_options, &build_options_prev); + + systemf("pushd %s & cl %s %s\\%s /Fe%s /link /DEBUG /INCREMENTAL:NO %s", + out_path, build_options, code_path, code_file, out_file, link_options); +} + +static void +build(uint32_t flags, + char *code_path, char *code_file, + char *out_path, char *out_file, + char *exports){ +#if defined(IS_CL) + build_cl(flags, code_path, code_file, out_path, out_file, exports); +#else +#error The build rule for this compiler is not ready +#endif +} + +static void +buildsuper(char *code_path , char *filename){ +#if defined(IS_CL) + + win32_slash_fix(filename); + + systemf("call \"%s\\buildsuper.bat\" %s", + code_path, filename); + +#else +#error The build rule for this compiler is not ready +#endif +} + +#if defined(DEV_BUILD) + +int main(int argc, char **argv){ + char cdir[256]; + { + int32_t n = get_current_directory(cdir, sizeof(cdir)); + assert(n < sizeof(cdir)); + } + + build(OPTS | DEBUG_INFO, cdir, "4ed_metagen.cpp", + "../meta", "metagen", 0); + + execute(cdir, "../meta/metagen"); + + //buildsuper(cdir, "../code/4coder_default_bindings.cpp"); + buildsuper(cdir, "../code/internal_4coder_tests.cpp"); + //buildsuper(cdir, "../code/power/4coder_casey.cpp"); + //buildsuper(cdir, "../4vim/4coder_chronal.cpp"); + + build(OPTS | INCLUDES | SHARED_CODE | DEBUG_INFO, cdir, "4ed_app_target.cpp", + "../build", "4ed_app", "/EXPORT:app_get_functions"); + + build(OPTS | INCLUDES | LIBS | ICON | DEBUG_INFO, cdir, "win32_4ed.cpp", + "../build", "4ed", 0); + + return(error_state); +} + +#elif defined(PACKAGE) + + + +#endif + +// BOTTOM \ No newline at end of file diff --git a/build_all.bat b/build_all.bat index be47973f..59203d7b 100644 --- a/build_all.bat +++ b/build_all.bat @@ -32,7 +32,7 @@ REM call "%CODE_DIR%\buildsuper.bat" ..\4vim\4coder_chronal.cpp if %ERRORLEVEL% neq 0 (set FirstError=1) set EXPORTS=/EXPORT:app_get_functions -REM cl %OPTS% %INCLUDES% %DEFINES% %CODE_DIR%\4ed_app_target.cpp %* /Fe4ed_app /LD /link /DEBUG /INCREMENTAL:NO /OPT:REF %EXPORTS% +cl %OPTS% %INCLUDES% %DEFINES% %CODE_DIR%\4ed_app_target.cpp %* /Fe4ed_app /LD /link /DEBUG /INCREMENTAL:NO /OPT:REF %EXPORTS% if %ERRORLEVEL% neq 0 (set FirstError=1) cl %OPTS% %INCLUDES% %DEFINES% %CODE_DIR%\win32_4ed.cpp %LIBS% %ICON% %* /Fe4ed /link /DEBUG /NODEFAULTLIB:library diff --git a/internal_4coder_string.cpp b/internal_4coder_string.cpp index 52db6bd0..560b09c7 100644 --- a/internal_4coder_string.cpp +++ b/internal_4coder_string.cpp @@ -3,9 +3,15 @@ #define FSTRING_BEGIN #define DOC_EXPORT +#define CPP_NAME(n) + FSTRING_BEGIN // TOP +#if defined(FSTRING_C) +#define FSTRING_INLINE static +#endif + #if defined(FSTRING_IMPLEMENTATION) && defined(FSTRING_GUARD) #undef FSTRING_IMPLEMENTATION #endif @@ -22,16 +28,16 @@ FSTRING_BEGIN #ifndef FSTRING_STRUCT #define FSTRING_STRUCT -struct String{ +typedef struct String{ char *str; int32_t size; int32_t memory_size; -}; +} String; -struct Offset_String{ +typedef struct Offset_String{ int32_t offset; int32_t size; -}; +} Offset_String; #endif #ifndef fstr_bool @@ -114,14 +120,15 @@ char_is_numeric(char c) // FSTRING_INLINE String -string_zero() +string_zero(void) /* DOC(This call returns a String struct of zeroed members.) */{ String str={0}; return(str); } +CPP_NAME(make_string) FSTRING_INLINE String -make_string(void *str, int32_t size, int32_t mem_size) +make_string_cap(void *str, int32_t size, int32_t mem_size) /* DOC_PARAM(str, The str parameter provides the of memory with which the string shall operate.) DOC_PARAM(size, The size parameter expresses the initial size of the string. @@ -154,11 +161,11 @@ DOC(This call returns the String created from the parameters.) DOC_EXPORT /* DOC(This macro takes a literal string in quotes and uses it to create a String with the correct size and memory size. Strings created this way should usually not be mutated.) */ -#define make_lit_string(s) (make_string((char*)(s), sizeof(s)-1, sizeof(s))) +#define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) DOC_EXPORT /* DOC(This macro takes a local char array with a fixed width and uses it to create an empty String with the correct size and memory size to operate on the array.) */ -#define make_fixed_width_string(s) (make_string((char*)(s), 0, sizeof(s))) +#define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) DOC_EXPORT /* DOC(This macro is a helper for any calls that take a char*,int pair to specify a string. This macro expands to both of those parameters from one String struct.) */ @@ -183,12 +190,9 @@ treating that as the size and memory size of the string.) */{ return result; } -// TODO(allen): I don't love the substr rule, I chose -// substr(String, start) and substr(String, start, size) -// but I wish I had substr(String, start) and substr(String, start, end) - +CPP_NAME(substr) FSTRING_INLINE String -substr(String str, int32_t start) +substr_tail(String str, int32_t start) /* DOC(This call creates a substring of str that starts with an offset from str's base. The new string uses the same underlying memory so both strings will see changes. Usually strings created this way should only go through immutable calls.) */{ @@ -263,8 +267,9 @@ the portion of str's memory that is not used.) */{ // String Comparison // +CPP_NAME(match) FSTRING_LINK fstr_bool -match(char *a, char *b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ +match_cc(char *a, char *b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ for (int32_t i = 0;; ++i){ if (a[i] != b[i]){ return 0; @@ -275,8 +280,9 @@ match(char *a, char *b)/* DOC(This call returns non-zero if a and b are equivale } } +CPP_NAME(match) FSTRING_LINK fstr_bool -match(String a, char *b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ +match_sc(String a, char *b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ int32_t i = 0; for (; i < a.size; ++i){ if (a.str[i] != b[i]){ @@ -289,13 +295,15 @@ match(String a, char *b)/* DOC(This call returns non-zero if a and b are equival return 1; } +CPP_NAME(match) FSTRING_INLINE fstr_bool -match(char *a, String b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ - return(match(b,a)); +match_cs(char *a, String b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ + return(match_sc(b,a)); } +CPP_NAME(match) FSTRING_LINK fstr_bool -match(String a, String b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ +match_ss(String a, String b)/* DOC(This call returns non-zero if a and b are equivalent.) */{ if (a.size != b.size){ return 0; } @@ -307,8 +315,9 @@ match(String a, String b)/* DOC(This call returns non-zero if a and b are equiva return 1; } +CPP_NAME(match_part) FSTRING_LINK fstr_bool -match_part(char *a, char *b, int32_t *len)/* +match_part_ccl(char *a, char *b, int32_t *len)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.) */{ @@ -322,9 +331,9 @@ In other words this call returns non-zero if b is a prefix of a.) */{ return 1; } - +CPP_NAME(match_part) FSTRING_LINK fstr_bool -match_part(String a, char *b, int32_t *len)/* +match_part_scl(String a, char *b, int32_t *len)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.) */{ @@ -338,25 +347,28 @@ In other words this call returns non-zero if b is a prefix of a.) */{ return 1; } +CPP_NAME(match_part) FSTRING_INLINE fstr_bool -match_part(char *a, char *b)/* +match_part_cc(char *a, char *b)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.) */{ int32_t x; - return match_part(a,b,&x); + return match_part_ccl(a,b,&x); } +CPP_NAME(match_part) FSTRING_INLINE fstr_bool -match_part(String a, char *b)/* +match_part_sc(String a, char *b)/* DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.) */{ int32_t x; - return match_part(a,b,&x); + return match_part_scl(a,b,&x); } +CPP_NAME(match_part) FSTRING_LINK fstr_bool -match_part(char *a, String b)/* +match_part_cs(char *a, String b)/* DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.) */{ for (int32_t i = 0; i != b.size; ++i){ @@ -367,8 +379,9 @@ In other words this call returns non-zero if b is a prefix of a.) */{ return 1; } +CPP_NAME(match_part) FSTRING_LINK fstr_bool -match_part(String a, String b)/* +match_part_ss(String a, String b)/* DOC(This call is similar to a match call, except that it is permitted for a to be longer than b. In other words this call returns non-zero if b is a prefix of a.) */{ if (a.size < b.size){ @@ -382,8 +395,9 @@ In other words this call returns non-zero if b is a prefix of a.) */{ return 1; } +CPP_NAME(match_insensitive) FSTRING_LINK fstr_bool -match_insensitive(char *a, char *b)/* +match_insensitive_cc(char *a, char *b)/* DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ for (int32_t i = 0;; ++i){ if (char_to_upper(a[i]) != @@ -396,8 +410,9 @@ DOC(This call returns non-zero if a and b are equivalent under case insensitive } } +CPP_NAME(match_insensitive) FSTRING_LINK fstr_bool -match_insensitive(String a, char *b)/* +match_insensitive_sc(String a, char *b)/* DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ int32_t i = 0; for (; i < a.size; ++i){ @@ -412,14 +427,16 @@ DOC(This call returns non-zero if a and b are equivalent under case insensitive return 1; } +CPP_NAME(match_insensitive) FSTRING_INLINE fstr_bool -match_insensitive(char *a, String b)/* +match_insensitive_cs(char *a, String b)/* DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ - return match_insensitive(b,a); + return match_insensitive_sc(b,a); } +CPP_NAME(match_insensitive) FSTRING_LINK fstr_bool -match_insensitive(String a, String b)/* +match_insensitive_ss(String a, String b)/* DOC(This call returns non-zero if a and b are equivalent under case insensitive comparison.) */{ if (a.size != b.size){ return 0; @@ -433,8 +450,9 @@ DOC(This call returns non-zero if a and b are equivalent under case insensitive return 1; } +CPP_NAME(match_part_insensitive) FSTRING_LINK fstr_bool -match_part_insensitive(char *a, char *b, int32_t *len)/* +match_part_insensitive_ccl(char *a, char *b, int32_t *len)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ @@ -448,8 +466,9 @@ DOC_SEE(match_part) */{ return 1; } +CPP_NAME(match_part_insensitive) FSTRING_LINK fstr_bool -match_part_insensitive(String a, char *b, int32_t *len)/* +match_part_insensitive_scl(String a, char *b, int32_t *len)/* DOC_PARAM(len, If this call returns non-zero this parameter is used to output the length of b.) DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ @@ -464,24 +483,27 @@ DOC_SEE(match_part) */{ return 1; } +CPP_NAME(match_part_insensitive) FSTRING_INLINE fstr_bool -match_part_insensitive(char *a, char *b)/* +match_part_insensitive_cc(char *a, char *b)/* DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ int32_t x; - return match_part(a,b,&x); + return match_part_insensitive_ccl(a,b,&x); } +CPP_NAME(match_part_insensitive) FSTRING_INLINE fstr_bool -match_part_insensitive(String a, char *b)/* +match_part_insensitive_sc(String a, char *b)/* DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ int32_t x; - return match_part(a,b,&x); + return match_part_insensitive_scl(a,b,&x); } +CPP_NAME(match_part_insensitive) FSTRING_LINK fstr_bool -match_part_insensitive(char *a, String b)/* +match_part_insensitive_cs(char *a, String b)/* DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ for (int32_t i = 0; i != b.size; ++i){ @@ -492,8 +514,9 @@ DOC_SEE(match_part) */{ return 1; } +CPP_NAME(match_part_insensitive) FSTRING_LINK fstr_bool -match_part_insensitive(String a, String b)/* +match_part_insensitive_ss(String a, String b)/* DOC(This call performs the same partial matching rule as match_part under case insensitive comparison.) DOC_SEE(match_part) */{ if (a.size < b.size){ @@ -507,8 +530,9 @@ DOC_SEE(match_part) */{ return 1; } +CPP_NAME(compare) FSTRING_LINK int32_t -compare(char *a, char *b)/* +compare_cc(char *a, char *b)/* DOC(This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.) */{ @@ -519,8 +543,9 @@ and positive if a sorts after b alphabetically.) */{ return (a[i] > b[i]) - (a[i] < b[i]); } +CPP_NAME(compare) FSTRING_LINK int32_t -compare(String a, char *b)/* +compare_sc(String a, char *b)/* DOC(This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.) */{ @@ -541,16 +566,18 @@ and positive if a sorts after b alphabetically.) */{ } } +CPP_NAME(compare) FSTRING_INLINE int32_t -compare(char *a, String b)/* +compare_cs(char *a, String b)/* DOC(This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.) */{ - return -compare(b,a); + return -compare_sc(b,a); } +CPP_NAME(compare) FSTRING_LINK int32_t -compare(String a, String b)/* +compare_ss(String a, String b)/* DOC(This call returns zero if a and b are equivalent, it returns negative if a sorts before b alphabetically, and positive if a sorts after b alphabetically.) */{ @@ -570,8 +597,9 @@ and positive if a sorts after b alphabetically.) */{ // Finding Characters and Substrings // +CPP_NAME(find) FSTRING_LINK int32_t -find(char *str, int32_t start, char character)/* +find_c_char(char *str, int32_t start, char character)/* DOC_PARAM(str, The str parameter provides a null terminated string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(character, The character parameter provides the character for which to search.) @@ -582,8 +610,9 @@ if the character is not found.) */{ return i; } +CPP_NAME(find) FSTRING_LINK int32_t -find(String str, int32_t start, char character)/* +find_s_char(String str, int32_t start, char character)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(character, The character parameter provides the character for which to search.) @@ -594,8 +623,9 @@ if the character is not found.) */{ return i; } +CPP_NAME(find) FSTRING_LINK int32_t -find(char *str, int32_t start, char *characters)/* +find_c_chars(char *str, int32_t start, char *characters)/* DOC_PARAM(str, The str parameter provides a null terminated string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(character, The characters parameter provides a null terminated array of characters for which to search.) @@ -613,8 +643,9 @@ or the size of the string if no such character is not found.) */{ return i; } +CPP_NAME(find) FSTRING_LINK int32_t -find(String str, int32_t start, char *characters)/* +find_s_chars(String str, int32_t start, char *characters)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(character, The characters parameter provides a null terminated array of characters for which to search.) @@ -632,8 +663,9 @@ or the size of the string if no such character is not found.) */{ return i; } +CPP_NAME(find_substr) FSTRING_LINK int32_t -find_substr(char *str, int32_t start, String seek)/* +find_substr_c(char *str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a null terminated string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(seek, The seek parameter provides a string to find in str.) @@ -662,8 +694,9 @@ size of str if no such substring in str is found.) */{ return i; } +CPP_NAME(find_substr) FSTRING_LINK int32_t -find_substr(String str, int32_t start, String seek)/* +find_substr_s(String str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(seek, The seek parameter provides a string to find in str.) @@ -693,8 +726,9 @@ size of str if no such substring in str is found.) */{ return str.size; } +CPP_NAME(rfind_substr) FSTRING_LINK int32_t -rfind_substr(String str, int32_t start, String seek)/* +rfind_substr_s(String str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(seek, The seek parameter provides a string to find in str.) @@ -726,8 +760,9 @@ or -1 if no such substring in str is found.) */{ return -1; } +CPP_NAME(find_substr_insensitive) FSTRING_LINK int32_t -find_substr_insensitive(char *str, int32_t start, String seek)/* +find_substr_insensitive_c(char *str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a null terminated string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(seek, The seek parameter provides a string to find in str.) @@ -759,8 +794,9 @@ DOC_SEE(find_substr)*/{ return i; } +CPP_NAME(find_substr_insensitive) FSTRING_LINK int32_t -find_substr_insensitive(String str, int32_t start, String seek)/* +find_substr_insensitive_s(String str, int32_t start, String seek)/* DOC_PARAM(str, The str parameter provides a string to search.) DOC_PARAM(start, The start parameter provides the index of the first character in str to search.) DOC_PARAM(seek, The seek parameter provides a string to find in str.) @@ -794,38 +830,43 @@ DOC_SEE(find_substr)*/{ return str.size; } +CPP_NAME(has_substr) FSTRING_INLINE fstr_bool -has_substr(char *s, String seek)/* +has_substr_c(char *s, String seek)/* DOC(This call returns non-zero if the string s contains a substring equivalent to seek.) */{ - return (s[find_substr(s, 0, seek)] != 0); + return (s[find_substr_c(s, 0, seek)] != 0); } +CPP_NAME(has_substr) FSTRING_INLINE fstr_bool -has_substr(String s, String seek)/* +has_substr_s(String s, String seek)/* DOC(This call returns non-zero if the string s contains a substring equivalent to seek.) */{ - return (find_substr(s, 0, seek) < s.size); + return (find_substr_s(s, 0, seek) < s.size); } +CPP_NAME(has_substr_insensitive) FSTRING_INLINE fstr_bool -has_substr_insensitive(char *s, String seek)/* +has_substr_insensitive_c(char *s, String seek)/* DOC(This call returns non-zero if the string s contains a substring equivalent to seek under case insensitive comparison.) */{ - return (s[find_substr_insensitive(s, 0, seek)] != 0); + return (s[find_substr_insensitive_c(s, 0, seek)] != 0); } +CPP_NAME(has_substr_insensitive) FSTRING_INLINE fstr_bool -has_substr_insensitive(String s, String seek)/* +has_substr_insensitive_s(String s, String seek)/* DOC(This call returns non-zero if the string s contains a substring equivalent to seek under case insensitive comparison.) */{ - return (find_substr_insensitive(s, 0, seek) < s.size); + return (find_substr_insensitive_s(s, 0, seek) < s.size); } // // String Copies and Appends // +CPP_NAME(copy_fast_unsafe) FSTRING_LINK int32_t -copy_fast_unsafe(char *dest, char *src)/* +copy_fast_unsafe_cc(char *dest, char *src)/* DOC(This call performs a copy from the src buffer to the dest buffer. The copy does not stop until a null terminator is found in src. There is no safety against overrun so dest must be large enough to contain src. @@ -840,8 +881,9 @@ of bytes coppied to dest.) */{ return (int32_t)(dest - start); } +CPP_NAME(copy_fast_unsafe) FSTRING_LINK int32_t -copy_fast_unsafe(char *dest, String src)/* +copy_fast_unsafe_cs(char *dest, String src)/* DOC(This call performs a copy from the src string to the dest buffer. The copy does not stop until src.size characters are coppied. There is no safety against overrun so dest must be large enough to contain src. @@ -855,8 +897,9 @@ of bytes coppied to dest.) */{ return(src.size); } +CPP_NAME(copy_checked) FSTRING_LINK fstr_bool -copy_checked(String *dest, String src)/* +copy_checked_ss(String *dest, String src)/* DOC(This call performs a copy from the src string to the dest string. The memory_size of dest is checked before any coppying is done. This call returns non-zero on a successful copy.) */{ @@ -873,8 +916,9 @@ This call returns non-zero on a successful copy.) */{ return 1; } +CPP_NAME(copy_partial) FSTRING_LINK fstr_bool -copy_partial(String *dest, char *src)/* +copy_partial_sc(String *dest, char *src)/* DOC(This call performs a copy from the src buffer to the dest string. The memory_size of dest is checked if the entire copy cannot be performed, as many bytes as possible are coppied to dest. This call returns non-zero @@ -893,17 +937,18 @@ if the entire string is coppied to dest.) */{ return 1; } +CPP_NAME(copy_partial) FSTRING_LINK fstr_bool -copy_partial(String *dest, String src)/* +copy_partial_ss(String *dest, String src)/* DOC(This call performs a copy from the src string to the dest string. The memory_size of dest is checked if the entire copy cannot be performed, as many bytes as possible are coppied to dest. This call returns non-zero if the entire string is coppied to dest.) */{ char *dest_str = dest->str; int32_t memory_size = dest->memory_size; - fstr_bool result = false; + fstr_bool result = 0; if (memory_size >= src.size){ - result = true; + result = 1; memory_size = src.size; } for (int32_t i = 0; i < memory_size; ++i){ @@ -913,62 +958,69 @@ if the entire string is coppied to dest.) */{ return result; } +CPP_NAME(copy) FSTRING_INLINE int32_t -copy(char *dest, char *src)/* +copy_cc(char *dest, char *src)/* DOC(This call performs a copy from src to dest equivalent to copy_fast_unsafe.) DOC_SEE(copy_fast_unsafe) */{ - return copy_fast_unsafe(dest, src); + return copy_fast_unsafe_cc(dest, src); } +CPP_NAME(copy) FSTRING_INLINE void -copy(String *dest, String src)/* +copy_ss(String *dest, String src)/* DOC(This call performs a copy from src to dest equivalent to copy_checked.) DOC_SEE(copy_checked) */{ - copy_checked(dest, src); + copy_checked_ss(dest, src); } +CPP_NAME(copy) FSTRING_INLINE void -copy(String *dest, char *src)/* +copy_sc(String *dest, char *src)/* DOC(This call performs a copy from src to dest equivalent to copy_partial.) DOC_SEE(copy_partial) */{ - copy_partial(dest, src); + copy_partial_sc(dest, src); } +CPP_NAME(append_checked) FSTRING_LINK fstr_bool -append_checked(String *dest, String src)/* +append_checked_ss(String *dest, String src)/* DOC(This call checks if there is enough space in dest's underlying memory to append src onto dest. If there is src is appended and the call returns non-zero.) */{ String end; end = tailstr(*dest); - fstr_bool result = copy_checked(&end, src); + fstr_bool result = copy_checked_ss(&end, src); // NOTE(allen): This depends on end.size still being 0 if // the check failed and no coppy occurred. dest->size += end.size; return result; } +CPP_NAME(append_partial) FSTRING_LINK fstr_bool -append_partial(String *dest, char *src)/* +append_partial_sc(String *dest, char *src)/* DOC(This call attemps to append as much of src into the space in dest's underlying memory as possible. If the entire string is appended the call returns non-zero.) */{ String end = tailstr(*dest); - fstr_bool result = copy_partial(&end, src); + fstr_bool result = copy_partial_sc(&end, src); dest->size += end.size; return result; } +CPP_NAME(append_partial) FSTRING_LINK fstr_bool -append_partial(String *dest, String src)/* +append_partial_ss(String *dest, String src)/* DOC(This call attemps to append as much of src into the space in dest's underlying memory as possible. If the entire string is appended the call returns non-zero.) */{ String end = tailstr(*dest); - fstr_bool result = copy_partial(&end, src); + fstr_bool result = copy_partial_ss(&end, src); dest->size += end.size; return result; } +CPP_NAME(append) FSTRING_LINK fstr_bool -append(String *dest, char c)/* +append_s_char(String *dest, char c)/* DOC(This call attemps to append c onto dest. If there is space left in dest's underlying memory the character is appended and the call returns non-zero.) */{ fstr_bool result = 0; @@ -979,16 +1031,18 @@ memory the character is appended and the call returns non-zero.) */{ return result; } +CPP_NAME(append) FSTRING_INLINE fstr_bool -append(String *dest, String src)/* +append_ss(String *dest, String src)/* DOC(This call is equivalent to append_partial.) DOC_SEE(append_partial) */{ - return append_partial(dest, src); + return append_partial_ss(dest, src); } +CPP_NAME(append) FSTRING_INLINE fstr_bool -append(String *dest, char *src)/* +append_sc(String *dest, char *src)/* DOC(This call is equivalent to append_partial.) DOC_SEE(append_partial) */{ - return append_partial(dest, src); + return append_partial_sc(dest, src); } FSTRING_LINK fstr_bool @@ -1015,7 +1069,7 @@ non-zero if dest does not run out of space in the underlying memory.) */{ int32_t r = 0; if (offset > 0){ for (r = 0; r < offset; ++r){ - if (append(dest, c) == 0){ + if (append_s_char(dest, c) == 0){ result = 0; break; } @@ -1191,18 +1245,18 @@ space in dest this call returns non-zero.) */{ } #ifndef FSTRING_GUARD -struct Float_To_Str_Variables{ +typedef struct Float_To_Str_Variables{ fstr_bool negative; int32_t int_part; int32_t dec_part; -}; +} Float_To_Str_Variables; -Float_To_Str_Variables +static Float_To_Str_Variables get_float_vars(float x){ Float_To_Str_Variables vars = {0}; if (x < 0){ - vars.negative = true; + vars.negative = 1; x = -x; } @@ -1230,11 +1284,11 @@ space in dest this call returns non-zero.) */{ Float_To_Str_Variables vars = get_float_vars(x); if (vars.negative){ - append(dest, '-'); + append_s_char(dest, '-'); } append_int_to_str(dest, vars.int_part); - append(dest, '.'); + append_s_char(dest, '.'); append_int_to_str(dest, vars.dec_part); return(result); @@ -1250,21 +1304,37 @@ space in dest this call returns non-zero.) */{ return(result); } -FSTRING_LINK fstr_bool -str_is_int(String str)/* -DOC(If str is a valid string representation of an integer, this call returns non-zero.) */{ - fstr_bool result = true; - for (int32_t i = 0; i < str.size; ++i){ - if (!char_is_numeric(str.str[i])){ - result = false; +CPP_NAME(str_is_int) +FSTRING_LINK int32_t +str_is_int_c(char *str)/* +DOC(If str is a valid string representation of an integer, this call returns non-zero) */{ + fstr_bool result = 1; + for (; *str; ++str){ + if (!char_is_numeric(*str)){ + result = 0; break; } } return(result); } +CPP_NAME(str_is_int) +FSTRING_LINK fstr_bool +str_is_int_s(String str)/* +DOC(If str is a valid string representation of an integer, this call returns non-zero.) */{ + fstr_bool result = 1; + for (int32_t i = 0; i < str.size; ++i){ + if (!char_is_numeric(str.str[i])){ + result = 0; + break; + } + } + return(result); +} + +CPP_NAME(str_to_int) FSTRING_LINK int32_t -str_to_int(char *str)/* +str_to_int_c(char *str)/* DOC(If str is a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.) */{ int32_t x = 0; @@ -1281,8 +1351,9 @@ the integer represented by the string. Otherwise this call returns zero.) */{ return(x); } +CPP_NAME(str_to_int) FSTRING_LINK int32_t -str_to_int(String str)/* +str_to_int_s(String str)/* DOC(If str represents a valid string representation of an integer, this call will return the integer represented by the string. Otherwise this call returns zero.) */{ int32_t x, i; @@ -1394,8 +1465,9 @@ DOC(This call interprets s as a color and writes the 32-bit integer representati // Directory String Management // +CPP_NAME(reverse_seek_slash) FSTRING_LINK int32_t -reverse_seek_slash(String str, int32_t pos)/* +reverse_seek_slash_pos(String str, int32_t pos)/* DOC(This call searches for a slash in str by starting pos bytes from the end and going backwards.) */{ int32_t i = str.size - 1 - pos; while (i >= 0 && !char_is_slash(str.str[i])){ @@ -1407,14 +1479,14 @@ DOC(This call searches for a slash in str by starting pos bytes from the end and FSTRING_INLINE int32_t reverse_seek_slash(String str)/* DOC(This call searches for a slash in str by starting at the end and going backwards.) */{ - return(reverse_seek_slash(str, 0)); + return(reverse_seek_slash_pos(str, 0)); } FSTRING_INLINE String front_of_directory(String dir)/* DOC(This call returns a substring of dir containing only the file name or folder name furthest to the right in the directory.) DOC_SEE(substr) */{ - return substr(dir, reverse_seek_slash(dir) + 1); + return substr_tail(dir, reverse_seek_slash(dir) + 1); } FSTRING_INLINE String @@ -1424,53 +1496,49 @@ for the final file or folder name.) DOC_SEE(substr) */{ return substr(dir, 0, reverse_seek_slash(dir) + 1); } +CPP_NAME(set_last_folder) FSTRING_LINK fstr_bool -set_last_folder(String *dir, char *folder_name, char slash)/* +set_last_folder_sc(String *dir, char *folder_name, char slash)/* DOC_PARAM(dir, The dir parameter is the directory string in which to set the last folder in the directory.) DOC_PARAM(folder_name, The folder_name parameter is a null terminated string specifying the name to set at the end of the directory.) DOC_PARAM(slash, The slash parameter specifies what slash to use between names in the directory.) DOC(This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.) */{ - char str[2]; fstr_bool result = 0; int32_t size = reverse_seek_slash(*dir) + 1; dir->size = size; - str[0] = slash; - str[1] = 0; - if (append(dir, folder_name)){ - if (append(dir, str)){ + if (append_sc(dir, folder_name)){ + if (append_s_char(dir, slash)){ result = 1; } } if (!result){ dir->size = size; } - return result; + return(result); } +CPP_NAME(set_last_folder) FSTRING_LINK fstr_bool -set_last_folder(String *dir, String folder_name, char slash)/* +set_last_folder_ss(String *dir, String folder_name, char slash)/* DOC_PARAM(dir, The dir parameter is the directory string in which to set the last folder in the directory.) DOC_PARAM(folder_name, The folder_name parameter is a string specifying the name to set at the end of the directory.) DOC_PARAM(slash, The slash parameter specifies what slash to use between names in the directory.) DOC(This call deletes the last file name or folder name in the dir string and appends the new provided one. If there is enough memory in dir this call returns non-zero.) */{ - char str[2]; fstr_bool result = 0; int32_t size = reverse_seek_slash(*dir) + 1; dir->size = size; - str[0] = slash; - str[1] = 0; - if (append(dir, folder_name)){ - if (append(dir, str)){ + if (append_ss(dir, folder_name)){ + if (append_s_char(dir, slash)){ result = 1; } } if (!result){ dir->size = size; } - return result; + return(result); } FSTRING_LINK String @@ -1482,7 +1550,7 @@ DOC_SEE(substr) */{ if (str.str[i] == '.') break; } ++i; - return make_string(str.str+i, str.size-i); + return(make_string(str.str+i, str.size-i)); } FSTRING_LINK fstr_bool @@ -1490,7 +1558,7 @@ remove_last_folder(String *str)/* DOC(This call attemps to delete a folder or filename off the end of a path string. This call returns non-zero on success.) */{ fstr_bool result = 0; - int32_t end = reverse_seek_slash(*str, 1); + int32_t end = reverse_seek_slash_pos(*str, 1); if (end >= 0){ result = 1; str->size = end + 1; @@ -1508,12 +1576,12 @@ DOC_PARAM(match_index, If this call succeeds match_index is filled with the inde DOC(This call tries to see if str matches any of the strings in str_set. If there is a match the call succeeds and returns non-zero. The matching rule is equivalent to the matching rule for match.) DOC_SEE(match) */{ - fstr_bool result = false; + fstr_bool result = 0; int32_t i = 0; for (; i < count; ++i, ++str_set){ - if (match(*str_set, str)){ + if (match_ss(*str_set, str)){ *match_index = i; - result = true; + result = 1; break; } } @@ -1530,10 +1598,10 @@ DOC_SEE(match) */{ # define ArrayCount(a) ((sizeof(a))/sizeof(*a)) #endif -struct Absolutes{ +typedef struct Absolutes{ String a[8]; int32_t count; -}; +} Absolutes; static void get_absolutes(String name, Absolutes *absolutes, fstr_bool implicit_first, fstr_bool implicit_last){ @@ -1582,7 +1650,7 @@ get_absolutes(String name, Absolutes *absolutes, fstr_bool implicit_first, fstr_ } static fstr_bool -wildcard_match(Absolutes *absolutes, char *x, int32_t case_sensitive){ +wildcard_match_c(Absolutes *absolutes, char *x, int32_t case_sensitive){ fstr_bool r = 1; String *a = absolutes->a; @@ -1590,12 +1658,12 @@ wildcard_match(Absolutes *absolutes, char *x, int32_t case_sensitive){ fstr_bool (*match_part_func)(char*, String); if (case_sensitive){ - match_func = match; - match_part_func = match_part; + match_func = match_cs; + match_part_func = match_part_cs; } else{ - match_func = match_insensitive; - match_part_func = match_part_insensitive; + match_func = match_insensitive_cs; + match_part_func = match_part_insensitive_cs; } if (absolutes->count == 1){ @@ -1636,22 +1704,22 @@ wildcard_match(Absolutes *absolutes, char *x, int32_t case_sensitive){ } } } - return r; + return(r); } static fstr_bool -wildcard_match(Absolutes *absolutes, String x, int32_t case_sensitive){ +wildcard_match_s(Absolutes *absolutes, String x, int32_t case_sensitive){ terminate_with_null(&x); - return wildcard_match(absolutes, x.str, case_sensitive); + return(wildcard_match_c(absolutes, x.str, case_sensitive)); } #endif -#ifdef FSTRING_IMPLEMENTATION +#if defined(FSTRING_IMPLEMENTATION) #undef FSTRING_IMPLEMENTATION #endif -#ifndef FSTRING_GUARD +#if !defined(FSTRING_GUARD) #define FSTRING_GUARD #endif diff --git a/internal_4coder_tests.cpp b/internal_4coder_tests.cpp index 9c956014..5fa02293 100644 --- a/internal_4coder_tests.cpp +++ b/internal_4coder_tests.cpp @@ -38,13 +38,13 @@ CUSTOM_COMMAND_SIG(load_lots_of_files){ char space[1024]; String str = make_fixed_width_string(space); - append(&str, LOTS_OF_FILES); - append(&str, '/'); + append_ss(&str, make_lit_string(LOTS_OF_FILES)); + append_s_char(&str, '/'); int size = str.size; for (int i = 0; i < list.count; ++i, ++info){ if (!info->folder){ - append(&str, make_string(info->filename, info->filename_len)); + append_ss(&str, make_string(info->filename, info->filename_len)); Buffer_Summary buffer = app->create_buffer(app, str.str, str.size, BufferCreate_Background); assert(buffer.size != 0); diff --git a/system_shared.cpp b/system_shared.cpp index ab0fa9b0..a8597ec8 100644 --- a/system_shared.cpp +++ b/system_shared.cpp @@ -109,7 +109,7 @@ sysshared_to_binary_path(String *out_filename, char *filename){ i32 size = system_get_binary_path(out_filename); if (size > 0 && size < max-1){ out_filename->size = size; - if (append(out_filename, filename) && terminate_with_null(out_filename)){ + if (append_sc(out_filename, filename) && terminate_with_null(out_filename)){ translate_success = 1; } } diff --git a/test/4cpp_new_lexer.h b/test/4cpp_new_lexer.h index fd8f0ecc..783c1a24 100644 --- a/test/4cpp_new_lexer.h +++ b/test/4cpp_new_lexer.h @@ -130,7 +130,7 @@ sub_match_list(char *chunk, int size, int pos, String_List list, int sub_size){ str_main = substr(str_main, 0, sub_size); for (i = 0; i < list.count; ++i){ str_check = list.data[i].str; - if (match(str_main, str_check)){ + if (match_sc(str_main, str_check)){ result.index = i; result.new_pos = pos + sub_size; break; @@ -140,7 +140,7 @@ sub_match_list(char *chunk, int size, int pos, String_List list, int sub_size){ else{ for (i = 0; i < list.count; ++i){ str_check = list.data[i].str; - if (match_part(str_main, str_check, &l)){ + if (match_part_scl(str_main, str_check, &l)){ result.index = i; result.new_pos = pos + l; break; @@ -530,7 +530,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, int word_size = S.pos - S.token_start; if (S.pp_state == LSPP_body_if){ - if (match(make_string(S.tb, word_size), make_lit_string("defined"))){ + if (match_ss(make_string(S.tb, word_size), make_lit_string("defined"))){ S.token.type = CPP_TOKEN_DEFINED; S.token.flags = CPP_TFLAG_IS_OPERATOR | CPP_TFLAG_IS_KEYWORD; break; diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 7c7a3228..af63c660 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -802,7 +802,7 @@ system_file_load_begin(char *filename){ if (fname_str.size < 1024){ char fixed_space[1024]; String fixed_str = make_fixed_width_string(fixed_space); - copy(&fixed_str, fname_str); + copy_ss(&fixed_str, fname_str); terminate_with_null(&fixed_str); replace_char(&fixed_str, '/', '\\'); @@ -944,10 +944,9 @@ internal Sys_Set_File_List_Sig(system_set_file_list){ if (directory.size > 0){ char dir_space[MAX_PATH + 32]; - String dir = make_string(dir_space, 0, MAX_PATH + 32); - append(&dir, directory); - char trail_str[] = "\\*"; - append(&dir, trail_str); + String dir = make_string_cap(dir_space, 0, MAX_PATH + 32); + append_ss(&dir, directory); + append_ss(&dir, make_lit_string("\\*")); terminate_with_null(&dir); char *c_str_dir = dir.str; @@ -961,8 +960,8 @@ Sys_Set_File_List_Sig(system_set_file_list){ i32 file_count = 0; BOOL more_files = 1; do{ - if (!match(find_data.cFileName, ".") && - !match(find_data.cFileName, "..")){ + if (!match_cs(find_data.cFileName, make_lit_string(".")) && + !match_cs(find_data.cFileName, make_lit_string(".."))){ ++file_count; i32 size = 0; for(;find_data.cFileName[size];++size); @@ -988,8 +987,8 @@ Sys_Set_File_List_Sig(system_set_file_list){ File_Info *info = file_list->infos; more_files = 1; do{ - if (!match(find_data.cFileName, ".") && - !match(find_data.cFileName, "..")){ + if (!match_cs(find_data.cFileName, make_lit_string(".")) && + !match_cs(find_data.cFileName, make_lit_string(".."))){ info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; info->filename = name; @@ -997,9 +996,9 @@ Sys_Set_File_List_Sig(system_set_file_list){ for(;find_data.cFileName[i];++i) *name++ = find_data.cFileName[i]; info->filename_len = i; *name++ = 0; - String fname = make_string(info->filename, - info->filename_len, - info->filename_len+1); + String fname = make_string_cap(info->filename, + info->filename_len, + info->filename_len+1); replace_char(&fname, '\\', '/'); ++info; } @@ -1364,7 +1363,7 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){ memory_handle = GlobalAlloc(GMEM_MOVEABLE, str.size+1); if (memory_handle){ char *dest = (char*)GlobalLock(memory_handle); - copy_fast_unsafe(dest, str); + copy_fast_unsafe_cs(dest, str); GlobalUnlock(memory_handle); SetClipboardData(CF_TEXT, memory_handle); win32vars.next_clipboard_is_self = 1; @@ -1408,8 +1407,8 @@ Sys_CLI_Call_Sig(system_cli_call){ char command_line[2048]; String s = make_fixed_width_string(command_line); - copy(&s, make_lit_string("/C ")); - append_partial(&s, script_name); + copy_ss(&s, make_lit_string("/C ")); + append_partial_sc(&s, script_name); b32 success = terminate_with_null(&s); if (success){ @@ -2298,7 +2297,7 @@ WinMain(HINSTANCE hInstance, char *current_directory_mem = (char*)system_get_memory(required); DWORD written = GetCurrentDirectory(required, current_directory_mem); - String current_directory = make_string(current_directory_mem, written, required); + String current_directory = make_string_cap(current_directory_mem, written, required); terminate_with_null(¤t_directory); replace_char(¤t_directory, '\\', '/'); diff --git a/win32_api_impl.cpp b/win32_api_impl.cpp index 713c2805..6b5595a0 100644 --- a/win32_api_impl.cpp +++ b/win32_api_impl.cpp @@ -75,7 +75,7 @@ DOC_RETURN(This call returns non-zero if and only if the file exists.) if (len < sizeof(full_filename_space)){ full_filename = make_fixed_width_string(full_filename_space); - copy(&full_filename, make_string(filename, len)); + copy_ss(&full_filename, make_string(filename, len)); terminate_with_null(&full_filename); file = CreateFile(full_filename.str, GENERIC_READ, 0, 0, @@ -110,13 +110,13 @@ string. This call can also be used with rel set to ".." to traverse to parent folders. ) */{ - String directory = make_string(dir, *len, capacity); + String directory = make_string_cap(dir, *len, capacity); b32 result = 0; i32 old_size; char rel_path_space[1024]; String rel_path_string = make_fixed_width_string(rel_path_space); - copy(&rel_path_string, make_string(rel_path, rel_len)); + copy_ss(&rel_path_string, make_string(rel_path, rel_len)); terminate_with_null(&rel_path_string); if (rel_path[0] != 0){ @@ -130,8 +130,8 @@ folders. else{ if (directory.size + rel_len + 1 > directory.memory_size){ old_size = directory.size; - append_partial(&directory, rel_path); - append_partial(&directory, "\\"); + append_partial_sc(&directory, rel_path); + append_s_char(&directory, '\\'); if (Win32DirectoryExists(directory.str)){ result = 1; } @@ -153,7 +153,7 @@ DOC_PARAM(out, This parameter provides a character buffer that receives the path DOC_PARAM(capacity, This parameter specifies the maximum capacity of the out buffer.) DOC_RETURN(This call returns non-zero on success.) */{ - String str = make_string(out, 0, capacity); + String str = make_string_cap(out, 0, capacity); return(system_get_binary_path(&str)); } diff --git a/win32_ft_font.cpp b/win32_ft_font.cpp index 8c1f7079..69f85268 100644 --- a/win32_ft_font.cpp +++ b/win32_ft_font.cpp @@ -16,7 +16,7 @@ win32_ft_font_load(Partition *part, Render_Font *rf, char *name, char* filename = push_array(part, char, 256); if (filename != 0){ - String str = make_string(filename, 0, 256); + String str = make_string_cap(filename, 0, 256); sysshared_to_binary_path(&str, name); result = font_load_freetype(part, rf, filename, pt_size, tab_width, use_hinting);