diff options
-rw-r--r-- | config.c | 6 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | os-win.c | 2 | ||||
-rw-r--r-- | ted.c | 2 | ||||
-rw-r--r-- | ui.c | 4 | ||||
-rw-r--r-- | util.c | 14 |
6 files changed, 17 insertions, 14 deletions
@@ -558,7 +558,7 @@ static void get_config_path(Ted *ted, char *expanded, size_t expanded_sz, const assert(path != expanded); expanded[0] = '\0'; - if (path[0] == '~' && strchr(ALL_PATH_SEPARATORS, path[1])) { + if (path[0] == '~' && is_path_separator(path[1])) { str_printf(expanded, expanded_sz, "%s%c%s", ted->home, PATH_SEPARATOR, path + 1); } else if (!path_is_absolute(path)) { if (!ted_get_file(ted, path, expanded, expanded_sz)) { @@ -1278,7 +1278,7 @@ static char *editorconfig_glob_to_regex(ConfigReader *reader, const char *glob) assert(0); goto error; } - if (!strchr(ALL_PATH_SEPARATORS, dirname[strlen(dirname) - 1])) { + if (!is_path_separator(dirname[strlen(dirname) - 1])) { strbuf_catf(dirname, "%c", PATH_SEPARATOR); } for (const char *p = dirname; *p; ++p) @@ -1563,7 +1563,7 @@ void config_read(Ted *ted, const char *path, ConfigFormat format) { static char *last_separator(char *path) { for (int i = (int)strlen(path) - 1; i >= 0; --i) - if (strchr(ALL_PATH_SEPARATORS, path[i])) + if (is_path_separator(path[i])) return &path[i]; return NULL; } @@ -1,4 +1,7 @@ /* +TODO: +- editorconfig replace / with \ on windows + and fix path-specific settings (should use \\ not \ now that we're using regex) FUTURE FEATURES: - more tests - prepare rename support @@ -61,7 +61,7 @@ FsDirectoryEntry **fs_list_directory(const char *dirname) { HANDLE fhandle; assert(*dirname); sprintf_s(file_pattern, sizeof file_pattern, "%s%s*", dirname, - strchr(ALL_PATH_SEPARATORS, dirname[strlen(dirname) - 1]) ? "" : "\\"); + is_path_separator(dirname[strlen(dirname) - 1]) ? "" : "\\"); wchar_t wide_pattern[4100] = {0}; if (MultiByteToWideChar(CP_UTF8, 0, file_pattern, -1, wide_pattern, arr_count(wide_pattern)) == 0) return NULL; @@ -247,7 +247,7 @@ void ted_compute_settings(Ted *ted, const char *path, Language language, Setting editorconfig[i+1] = 0; ted_cfg[i] = path[i]; ted_cfg[i+1] = 0; - if (path[i] == 0 || strchr(ALL_PATH_SEPARATORS, path[i])) { + if (path[i] == 0 || is_path_separator(path[i])) { if (path[i] == 0) { // for the case where `path` is a directory strbuf_catf(editorconfig, "%c", PATH_SEPARATOR); strbuf_catf(ted_cfg, "%c", PATH_SEPARATOR); @@ -527,7 +527,7 @@ char *file_selector_update(Ted *ted, FileSelector *fs) { u32 first_path_sep = U32_MAX, last_path_sep = U32_MAX; for (u32 i = 0; i < search_term32.len; ++i) { char32_t c = search_term32.str[i]; - if (c < CHAR_MAX && strchr(ALL_PATH_SEPARATORS, (char)c)) { + if (c < CHAR_MAX && is_path_separator((char)c)) { last_path_sep = i; if (first_path_sep == U32_MAX) first_path_sep = i; @@ -541,7 +541,7 @@ char *file_selector_update(Ted *ted, FileSelector *fs) { if (dir_name) { // replace all members of ALL_PATH_SEPARATORS with PATH_SEPARATOR in dir_name (i.e. change / to \ on windows) for (char *p = dir_name; *p; ++p) - if (strchr(ALL_PATH_SEPARATORS, *p)) + if (is_path_separator(*p)) *p = PATH_SEPARATOR; if (file_selector_cd(ted, fs, dir_name)) { @@ -188,12 +188,12 @@ bool str_has_suffix(const char *str, const char *suffix) { bool str_has_path_prefix(const char *path, const char *prefix) { size_t prefix_len = strlen(prefix); for (size_t i = 0; i < prefix_len; ++i) { - if (strchr(ALL_PATH_SEPARATORS, path[i]) && strchr(ALL_PATH_SEPARATORS, prefix[i])) + if (is_path_separator(path[i]) && is_path_separator(prefix[i])) continue; // treat all path separators as the same if (prefix[i] != path[i]) return false; } - return path[prefix_len] == '\0' || strchr(ALL_PATH_SEPARATORS, path[prefix_len]); + return path[prefix_len] == '\0' || is_path_separator(path[prefix_len]); } bool streq(const char *a, const char *b) { @@ -469,7 +469,7 @@ bool is_path_separator(char c) { const char *path_filename(const char *path) { for (int i = (int)strlen(path) - 1; i >= 0; --i) { - if (strchr(ALL_PATH_SEPARATORS, path[i])) + if (is_path_separator(path[i])) return &path[i+1]; } // (a relative path with no path separators) @@ -477,7 +477,7 @@ const char *path_filename(const char *path) { } bool path_is_absolute(const char *path) { - return strchr(ALL_PATH_SEPARATORS, path[0]) != NULL + return is_path_separator(path[0]) #if _WIN32 || path[1] == ':' #endif @@ -490,7 +490,7 @@ void path_dirname(char *path) { return; } for (size_t i = strlen(path) - 1; i > 0; --i) { - if (strchr(ALL_PATH_SEPARATORS, path[i])) { + if (is_path_separator(path[i])) { if (strcspn(path, ALL_PATH_SEPARATORS) == i) { // only one path separator path[i+1] = '\0'; @@ -500,7 +500,7 @@ void path_dirname(char *path) { return; } } - if (strchr(ALL_PATH_SEPARATORS, path[0])) { + if (is_path_separator(path[0])) { path[1] = '\0'; return; } @@ -514,7 +514,7 @@ void path_full(const char *dir, const char *relpath, char *abspath, size_t abspa abspath[0] = '\0'; if (path_is_absolute(relpath)) { - if (strchr(ALL_PATH_SEPARATORS, relpath[0])) { + if (is_path_separator(relpath[0])) { // make sure that on windows, if dir's drive is C: the absolute path of \a is c:\a strn_cat(abspath, abspath_size, dir, strcspn(dir, ALL_PATH_SEPARATORS)); } else { |