From a7feb7052c8954dd3541e9a058684893a6bcfe10 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 31 Aug 2016 12:52:46 -0400 Subject: [PATCH] improved jump to parsing to handle parentheses in file paths on windows --- 4coder_API.html | 130 +++++++++++++++++++++---------------- 4coder_jump_parsing.cpp | 82 +++++++++++++---------- 4coder_string.h | 79 ++++++++++++++-------- TODO.txt | 8 +-- internal_4coder_string.cpp | 78 ++++++++++++++-------- 5 files changed, 228 insertions(+), 149 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index 2ff08350..de61d214 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -1117,6 +1117,7 @@ Coming Soon
  • compare_ss
  • find_c_char
  • find_s_char
  • +
  • rfind_s_char
  • find_c_chars
  • find_s_chars
  • find_substr_c
  • @@ -1566,7 +1567,26 @@ int32_t find_s_char(
    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_c_chars

    +

    §4.3.51: rfind_s_char

    +
    +int32_t rfind_s_char( +
    String str,
    int32_t start,
    char character
    ) +
    +
    Parameters
    +
    str
    +
    The str parameter provides a string to search.
    +
    +
    +
    start
    +
    The start parameter provides the index of the first character in str to search.
    +
    +
    +
    character
    +
    The character parameter provides the character for which to search.
    +
    +
    Description
    This call looks for the largest index less than or equal to the start position where +the given character occurs. If the index is found it is returned otherwise -1 is returned.

    +

    §4.3.52: find_c_chars

    int32_t find_c_chars(
    char *str,
    int32_t start,
    char *characters
    ) @@ -1585,7 +1605,7 @@ int32_t find_c_chars(
    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_s_chars

    +

    §4.3.53: find_s_chars

    int32_t find_s_chars(
    String str,
    int32_t start,
    char *characters
    ) @@ -1604,7 +1624,7 @@ int32_t find_s_chars(
    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_c

    +

    §4.3.54: find_substr_c

    int32_t find_substr_c(
    char *str,
    int32_t start,
    String seek
    ) @@ -1623,7 +1643,7 @@ int32_t find_substr_c(
    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_s

    +

    §4.3.55: find_substr_s

    int32_t find_substr_s(
    String str,
    int32_t start,
    String seek
    ) @@ -1642,7 +1662,7 @@ int32_t find_substr_s(
    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_s

    +

    §4.3.56: rfind_substr_s

    int32_t rfind_substr_s(
    String str,
    int32_t start,
    String seek
    ) @@ -1661,7 +1681,7 @@ int32_t rfind_substr_s(
    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_c

    +

    §4.3.57: find_substr_insensitive_c

    int32_t find_substr_insensitive_c(
    char *str,
    int32_t start,
    String seek
    ) @@ -1679,7 +1699,7 @@ int32_t find_substr_insensitive_c(
    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_s

    +

    §4.3.58: find_substr_insensitive_s

    int32_t find_substr_insensitive_s(
    String str,
    int32_t start,
    String seek
    ) @@ -1697,33 +1717,33 @@ int32_t find_substr_insensitive_s(
    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_c

    +

    §4.3.59: has_substr_c

    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_s

    +

    §4.3.60: has_substr_s

    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_c

    +

    §4.3.61: has_substr_insensitive_c

    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_s

    +

    §4.3.62: has_substr_insensitive_s

    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_cc

    +

    §4.3.63: copy_fast_unsafe_cc

    int32_t copy_fast_unsafe_cc(
    char *dest,
    char *src
    ) @@ -1733,7 +1753,7 @@ 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_cs

    +

    §4.3.64: copy_fast_unsafe_cs

    int32_t copy_fast_unsafe_cs(
    char *dest,
    String src
    ) @@ -1743,7 +1763,7 @@ 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_ss

    +

    §4.3.65: copy_checked_ss

    fstr_bool copy_checked_ss(
    String *dest,
    String src
    ) @@ -1751,7 +1771,7 @@ fstr_bool copy_checked_ss(
    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_sc

    +

    §4.3.66: copy_partial_sc

    fstr_bool copy_partial_sc(
    String *dest,
    char *src
    ) @@ -1760,7 +1780,7 @@ fstr_bool copy_partial_sc( 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_ss

    +

    §4.3.67: copy_partial_ss

    fstr_bool copy_partial_ss(
    String *dest,
    String src
    ) @@ -1769,65 +1789,65 @@ fstr_bool copy_partial_ss( 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_cc

    +

    §4.3.68: copy_cc

    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_ss

    +

    §4.3.69: copy_ss

    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_sc

    +

    §4.3.70: copy_sc

    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_ss

    +

    §4.3.71: append_checked_ss

    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_sc

    +

    §4.3.72: append_partial_sc

    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_ss

    +

    §4.3.73: append_partial_ss

    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_s_char

    +

    §4.3.74: append_s_char

    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_ss

    +

    §4.3.75: append_ss

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

    -

    §4.3.75: append_sc

    +

    §4.3.76: append_sc

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

    -

    §4.3.76: terminate_with_null

    +

    §4.3.77: terminate_with_null

    fstr_bool terminate_with_null(
    String *str
    ) @@ -1836,7 +1856,7 @@ fstr_bool terminate_with_null( size of str. This is usually called when the time comes to pass the the string to an API that requires a null terminator. This call returns non-zero if there was a spare byte in the strings underlying memory.

    -

    §4.3.77: append_padding

    +

    §4.3.78: append_padding

    fstr_bool append_padding(
    String *dest,
    char c,
    int32_t target_size
    ) @@ -1844,7 +1864,7 @@ fstr_bool append_padding(
    Description
    This call pads out dest so that it has a size of target_size by appending the padding character c until the target size is achieved. This call returns non-zero if dest does not run out of space in the underlying memory.

    -

    §4.3.78: replace_char

    +

    §4.3.79: replace_char

    void replace_char(
    String *str,
    char replace,
    char with
    ) @@ -1862,153 +1882,153 @@ void replace_char(
    The with character specifies what to write into the positions where replacement occurs.
    Description
    This call replaces all occurances of character in str with another character.

    -

    §4.3.79: int_to_str_size

    +

    §4.3.80: int_to_str_size

    int32_t int_to_str_size(
    int32_t x
    )
    Description
    This call returns the number of bytes required to represent x as a string.

    -

    §4.3.80: int_to_str

    +

    §4.3.81: int_to_str

    fstr_bool int_to_str(
    String *dest,
    int32_t x
    )
    Description
    This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.81: append_int_to_str

    +

    §4.3.82: append_int_to_str

    fstr_bool append_int_to_str(
    String *dest,
    int32_t x
    )
    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.82: u64_to_str_size

    +

    §4.3.83: u64_to_str_size

    int32_t u64_to_str_size(
    uint64_t x
    )
    Description
    This call returns the number of bytes required to represent x as a string.

    -

    §4.3.83: u64_to_str

    +

    §4.3.84: u64_to_str

    fstr_bool u64_to_str(
    String *dest,
    uint64_t x
    )
    Description
    This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.84: append_u64_to_str

    +

    §4.3.85: append_u64_to_str

    fstr_bool append_u64_to_str(
    String *dest,
    uint64_t x
    )
    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.85: float_to_str_size

    +

    §4.3.86: float_to_str_size

    int32_t float_to_str_size(
    float x
    )
    Description
    This call returns the number of bytes required to represent x as a string.

    -

    §4.3.86: append_float_to_str

    +

    §4.3.87: append_float_to_str

    fstr_bool append_float_to_str(
    String *dest,
    float x
    )
    Description
    This call writes a string representation of x into dest. If there is enough space in dest this call returns non-zero.

    -

    §4.3.87: float_to_str

    +

    §4.3.88: float_to_str

    fstr_bool float_to_str(
    String *dest,
    float x
    )
    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_c

    +

    §4.3.89: str_is_int_c

    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

    +

    §4.3.90: 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.90: str_to_int_c

    +

    §4.3.91: str_to_int_c

    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.91: str_to_int_s

    +

    §4.3.92: str_to_int_s

    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.92: hexchar_to_int

    +

    §4.3.93: 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.93: int_to_hexchar

    +

    §4.3.94: 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.94: hexstr_to_int

    +

    §4.3.95: 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.95: color_to_hexstr

    +

    §4.3.96: 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.96: hexstr_to_color

    +

    §4.3.97: 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.97: reverse_seek_slash_pos

    +

    §4.3.98: reverse_seek_slash_pos

    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.98: reverse_seek_slash

    +

    §4.3.99: 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.99: front_of_directory

    +

    §4.3.100: 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.100: path_of_directory

    +

    §4.3.101: 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.101: set_last_folder_sc

    +

    §4.3.102: set_last_folder_sc

    fstr_bool set_last_folder_sc(
    String *dir,
    char *folder_name,
    char slash
    ) @@ -2028,7 +2048,7 @@ 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.102: set_last_folder_ss

    +

    §4.3.103: set_last_folder_ss

    fstr_bool set_last_folder_ss(
    String *dir,
    String folder_name,
    char slash
    ) @@ -2047,20 +2067,20 @@ fstr_bool set_last_folder_ss(
    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.103: file_extension

    +

    §4.3.104: 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.104: remove_last_folder

    +

    §4.3.105: 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.105: string_set_match

    +

    §4.3.106: string_set_match

    fstr_bool string_set_match(
    String *str_set,
    int32_t count,
    String str,
    int32_t *match_index
    ) diff --git a/4coder_jump_parsing.cpp b/4coder_jump_parsing.cpp index ef777140..45bc81fa 100644 --- a/4coder_jump_parsing.cpp +++ b/4coder_jump_parsing.cpp @@ -36,55 +36,65 @@ parse_error(String line, Jump_Location *location, String original_line = line; line = skip_chop_whitespace(line); - - int32_t colon_pos = find_s_char(line, 0, ')'); - if (ms_style_verify(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); + + int32_t colon_pos = 0; + int32_t is_ms_style = 0; + + int32_t paren_pos = find_s_char(line, 0, ')'); + while (!is_ms_style && paren_pos < line.size){ + if (ms_style_verify(line, paren_pos)){ + is_ms_style = 1; + colon_pos = find_s_char(line, paren_pos, ':'); + if (colon_pos < line.size){ + String location_str = substr(line, 0, colon_pos); - int32_t 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); + if (!(skip_sub_errors && original_line.str[0] == ' ')){ + location_str = skip_chop_whitespace(location_str); - int32_t 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, - close_pos-paren_pos-2); - line_number = skip_chop_whitespace(line_number); + int32_t close_pos = paren_pos; + int32_t open_pos = rfind_s_char(location_str, close_pos, '('); + + if (0 < open_pos && open_pos < location_str.size){ + String file = substr(location_str, 0, open_pos); + file = skip_chop_whitespace(file); - if (line_number.size > 0){ - location->file = file; + if (file.size > 0){ + String line_number = substr(location_str, + open_pos+1, + close_pos-open_pos-1); + line_number = skip_chop_whitespace(line_number); - int32_t comma_pos = find_s_char(line_number, 0, ','); - if (comma_pos < line_number.size){ - int32_t start = comma_pos+1; - String column_number = substr(line_number, start, line_number.size-start); - line_number = substr(line_number, 0, comma_pos); + if (line_number.size > 0){ + location->file = file; - location->line = str_to_int_s(line_number); - location->column = str_to_int_s(column_number); + int32_t comma_pos = find_s_char(line_number, 0, ','); + if (comma_pos < line_number.size){ + int32_t 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_s(line_number); + location->column = str_to_int_s(column_number); + } + else{ + location->line = str_to_int_s(line_number); + location->column = 1; + } + + *colon_char = colon_pos; + result = true; } - else{ - location->line = str_to_int_s(line_number); - location->column = 1; - } - - *colon_char = colon_pos; - result = true; } } } } } + else{ + paren_pos = find_s_char(line, paren_pos+1, ')'); + } } - else{ + if (!is_ms_style){ int32_t colon_pos1 = find_s_char(line, 0, ':'); if (line.size > colon_pos1+1){ if (char_is_slash(line.str[colon_pos1+1])){ diff --git a/4coder_string.h b/4coder_string.h index fd955d66..451b7f41 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -103,6 +103,7 @@ 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 rfind_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); @@ -192,6 +193,7 @@ 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 rfind(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); @@ -288,6 +290,8 @@ find(char *str, int32_t start, char character){return(find_c_char(str,start,char FSTRING_INLINE int32_t find(String str, int32_t start, char character){return(find_s_char(str,start,character));} FSTRING_INLINE int32_t +rfind(String str, int32_t start, char character){return(rfind_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));} @@ -825,10 +829,10 @@ FSTRING_LINK fstr_bool 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; + return(0); } } - return 1; + return(1); } #endif @@ -837,14 +841,14 @@ match_part_insensitive_cs(char *a, String b){ FSTRING_LINK fstr_bool match_part_insensitive_ss(String a, String b){ if (a.size < b.size){ - return 0; + return(0); } for (int32_t i = 0; i < b.size; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ - return 0; + return(0); } } - return 1; + return(1); } #endif @@ -852,11 +856,12 @@ match_part_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t compare_cc(char *a, char *b){ - int32_t i = 0; + int32_t i = 0, r = 0; while (a[i] == b[i] && a[i] != 0){ ++i; } - return (a[i] > b[i]) - (a[i] < b[i]); + r = (a[i] > b[i]) - (a[i] < b[i]); + return(r); } #endif @@ -864,21 +869,22 @@ compare_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t compare_sc(String a, char *b){ - int32_t i = 0; + int32_t i = 0, r = 0; while (i < a.size && a.str[i] == b[i]){ ++i; } if (i < a.size){ - return (a.str[i] > b[i]) - (a.str[i] < b[i]); + r = (a.str[i] > b[i]) - (a.str[i] < b[i]); } else{ if (b[i] == 0){ - return 0; + r = 0; } else{ - return -1; + r = -1; } } + return(r); } #endif @@ -886,7 +892,8 @@ compare_sc(String a, char *b){ #if !defined(FSTRING_GUARD) FSTRING_INLINE int32_t compare_cs(char *a, String b){ - return -compare_sc(b,a); + int32_t r = -compare_sc(b,a); + return(r); } #endif @@ -894,16 +901,23 @@ compare_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) FSTRING_LINK int32_t compare_ss(String a, String b){ - int32_t i = 0; - while (i < a.size && i < b.size && a.str[i] == b.str[i]){ + int32_t i = 0, r = 0; + int32_t m = a.size; + if (b.size < m){ + m = b.size; + } + while (i < m && a.str[i] == b.str[i]){ ++i; } - if (i < a.size && i < b.size){ - return (a.str[i] > b.str[i]) - (a.str[i] < b.str[i]); + + if (i < m){ + r = (a.str[i] > b.str[i]) - (b.str[i] > a.str[i]); } else{ - return (a.size > b.size) - (a.size < b.size); + r = (a.size > b.size) - (a.size < b.size); } + + return(r); } #endif @@ -917,7 +931,7 @@ FSTRING_LINK int32_t find_c_char(char *str, int32_t start, char character){ int32_t i = start; while (str[i] != character && str[i] != 0) ++i; - return i; + return(i); } #endif @@ -927,7 +941,17 @@ FSTRING_LINK int32_t 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; + return(i); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) +FSTRING_LINK int32_t +rfind_s_char(String str, int32_t start, char character){ + int32_t i = start; + while (i >= 0 && str.str[i] != character) --i; + return(i); } #endif @@ -939,12 +963,12 @@ find_c_chars(char *str, int32_t start, char *characters){ while (str[i] != 0){ for (j = 0; characters[j]; ++j){ if (str[i] == characters[j]){ - return i; + return(i); } } ++i; } - return i; + return(i); } #endif @@ -956,12 +980,12 @@ find_s_chars(String str, int32_t start, char *characters){ while (i < str.size){ for (j = 0; characters[j]; ++j){ if (str.str[i] == characters[j]){ - return i; + return(i); } } ++i; } - return i; + return(i); } #endif @@ -973,7 +997,8 @@ find_substr_c(char *str, int32_t start, String seek){ fstr_bool hit; if (seek.size == 0){ - return str_size(str); + i = str_size(str); + return(i); } for (i = start; str[i]; ++i){ if (str[i] == seek.str[0]){ @@ -985,11 +1010,11 @@ find_substr_c(char *str, int32_t start, String seek){ } } if (hit){ - return i; + return(i); } } } - return i; + return(i); } #endif @@ -1018,7 +1043,7 @@ find_substr_s(String str, int32_t start, String seek){ } } } - return str.size; + return(str.size); } #endif diff --git a/TODO.txt b/TODO.txt index 16dee005..1448931e 100644 --- a/TODO.txt +++ b/TODO.txt @@ -70,14 +70,14 @@ ; [X] key presses that should be consumed in the GUI are now passed to the file! ; [X] paste snaps the cursor back into view! ; [X] clean whitespace doesn't appear to be cleaning trailing whitespace anymore??? +; [X] problem with end of line comments ; ; [] indication on failure to save ; [] history is broken, revist the entire system ; -; [] 8.0\Include\um\dsound.h -; [] paths with parens in them -; [] double check end of line comments -; [] paste external text from bug report (in email) (not repod, get more info) +; [] 8.0\Include\um\dsound.h (not reproduced, get more info) +; [] paths with parens in them +; [] paste external text from bug report (in email) (not reproduced, get more info) ; ; diff --git a/internal_4coder_string.cpp b/internal_4coder_string.cpp index 9a749e9e..ffee550e 100644 --- a/internal_4coder_string.cpp +++ b/internal_4coder_string.cpp @@ -511,10 +511,10 @@ DOC(This call performs the same partial matching rule as match_part under case i DOC_SEE(match_part) */{ for (int32_t i = 0; i != b.size; ++i){ if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ - return 0; + return(0); } } - return 1; + return(1); } CPP_NAME(match_part_insensitive) @@ -523,14 +523,14 @@ 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){ - return 0; + return(0); } for (int32_t i = 0; i < b.size; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ - return 0; + return(0); } } - return 1; + return(1); } CPP_NAME(compare) @@ -539,11 +539,12 @@ 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.) */{ - int32_t i = 0; + int32_t i = 0, r = 0; while (a[i] == b[i] && a[i] != 0){ ++i; } - return (a[i] > b[i]) - (a[i] < b[i]); + r = (a[i] > b[i]) - (a[i] < b[i]); + return(r); } CPP_NAME(compare) @@ -552,21 +553,22 @@ 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.) */{ - int32_t i = 0; + int32_t i = 0, r = 0; while (i < a.size && a.str[i] == b[i]){ ++i; } if (i < a.size){ - return (a.str[i] > b[i]) - (a.str[i] < b[i]); + r = (a.str[i] > b[i]) - (a.str[i] < b[i]); } else{ if (b[i] == 0){ - return 0; + r = 0; } else{ - return -1; + r = -1; } } + return(r); } CPP_NAME(compare) @@ -575,7 +577,8 @@ 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_sc(b,a); + int32_t r = -compare_sc(b,a); + return(r); } CPP_NAME(compare) @@ -584,16 +587,23 @@ 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.) */{ - int32_t i = 0; - while (i < a.size && i < b.size && a.str[i] == b.str[i]){ + int32_t i = 0, r = 0; + int32_t m = a.size; + if (b.size < m){ + m = b.size; + } + while (i < m && a.str[i] == b.str[i]){ ++i; } - if (i < a.size && i < b.size){ - return (a.str[i] > b.str[i]) - (a.str[i] < b.str[i]); + + if (i < m){ + r = (a.str[i] > b.str[i]) - (b.str[i] > a.str[i]); } else{ - return (a.size > b.size) - (a.size < b.size); + r = (a.size > b.size) - (a.size < b.size); } + + return(r); } // @@ -610,7 +620,7 @@ DOC(This call returns the index of the first occurance of character, or the size if the character is not found.) */{ int32_t i = start; while (str[i] != character && str[i] != 0) ++i; - return i; + return(i); } CPP_NAME(find) @@ -623,7 +633,20 @@ DOC(This call returns the index of the first occurance of character, or the size if the character is not found.) */{ int32_t i = start; while (i < str.size && str.str[i] != character) ++i; - return i; + return(i); +} + +CPP_NAME(rfind) +FSTRING_LINK int32_t +rfind_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.) +DOC(This call looks for the largest index less than or equal to the start position where +the given character occurs. If the index is found it is returned otherwise -1 is returned.) */{ + int32_t i = start; + while (i >= 0 && str.str[i] != character) --i; + return(i); } CPP_NAME(find) @@ -638,12 +661,12 @@ or the size of the string if no such character is not found.) */{ while (str[i] != 0){ for (j = 0; characters[j]; ++j){ if (str[i] == characters[j]){ - return i; + return(i); } } ++i; } - return i; + return(i); } CPP_NAME(find) @@ -658,12 +681,12 @@ or the size of the string if no such character is not found.) */{ while (i < str.size){ for (j = 0; characters[j]; ++j){ if (str.str[i] == characters[j]){ - return i; + return(i); } } ++i; } - return i; + return(i); } CPP_NAME(find_substr) @@ -678,7 +701,8 @@ size of str if no such substring in str is found.) */{ fstr_bool hit; if (seek.size == 0){ - return str_size(str); + i = str_size(str); + return(i); } for (i = start; str[i]; ++i){ if (str[i] == seek.str[0]){ @@ -690,11 +714,11 @@ size of str if no such substring in str is found.) */{ } } if (hit){ - return i; + return(i); } } } - return i; + return(i); } CPP_NAME(find_substr) @@ -726,7 +750,7 @@ size of str if no such substring in str is found.) */{ } } } - return str.size; + return(str.size); } CPP_NAME(rfind_substr)