From 4fe9d794382b6b81967e6ee88c76403bb8a69541 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sat, 5 Aug 2017 21:40:27 -0700 Subject: [PATCH] make `tokenize_variable_array()` private Another step towards implementing issue #4200 is to make the `tokenize_variable_array()` function private to the env.cpp module. --- src/env.cpp | 3 ++- src/env.h | 6 ------ src/expand.cpp | 4 ++-- src/expand.h | 5 +++-- src/function.cpp | 7 +++---- src/highlight.cpp | 8 ++++---- src/output.cpp | 6 +++--- src/output.h | 2 +- src/path.cpp | 4 ++-- 9 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index 7a6ef56d5..f3db6495a 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -105,6 +105,7 @@ static const wcstring_list_t colon_delimited_variable({L"PATH", L"MANPATH", L"CD // Some forward declarations to make it easy to logically group the code. static void init_locale(); static void init_curses(); +static void tokenize_variable_array(const wcstring &val, wcstring_list_t &out); // Struct representing one level in the function variable stack. // Only our variable stack should create and destroy these @@ -1621,7 +1622,7 @@ std::unique_ptr list_to_array_val(const wchar_t **list) { return val; } -void tokenize_variable_array(const wcstring &val, wcstring_list_t &out) { +static void tokenize_variable_array(const wcstring &val, wcstring_list_t &out) { out.clear(); // ensure the output var is empty -- this will normally be a no-op // Zero element arrays are internally encoded as this placeholder string. diff --git a/src/env.h b/src/env.h index 64a2327df..b7f3c2158 100644 --- a/src/env.h +++ b/src/env.h @@ -69,12 +69,6 @@ void env_init(const struct config_paths_t *paths = NULL); /// routines. void misc_init(); -/// Tokenize the specified string into the specified wcstring_list_t. -/// -/// \param val the input string. The contents of this string is not changed. -/// \param out the list in which to place the elements. -void tokenize_variable_array(const wcstring &val, wcstring_list_t &out); - class env_var_t { private: bool is_missing; diff --git a/src/expand.cpp b/src/expand.cpp index aa972a458..f265485d4 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -168,11 +168,11 @@ static int is_quotable(const wchar_t *str) { static int is_quotable(const wcstring &str) { return is_quotable(str.c_str()); } -wcstring expand_escape_variable(const wcstring &in) { +wcstring expand_escape_variable(const env_var_t &var) { wcstring_list_t lst; wcstring buff; - tokenize_variable_array(in, lst); + var.to_list(lst); size_t size = lst.size(); if (size == 0) { diff --git a/src/expand.h b/src/expand.h index 10fc88df5..2fd0423bd 100644 --- a/src/expand.h +++ b/src/expand.h @@ -13,6 +13,7 @@ #include #include "common.h" +#include "env.h" #include "parse_constants.h" enum { @@ -120,10 +121,10 @@ __warn_unused expand_error_t expand_string(const wcstring &input, std::vector &names, int get_hidden) { size_t i; - const env_var_t path_var_wstr = env_get(L"fish_function_path"); - if (path_var_wstr.missing()) return; - const wchar_t *path_var = path_var_wstr.c_str(); + const env_var_t path_var = env_get(L"fish_function_path"); + if (path_var.missing_or_empty()) return; wcstring_list_t path_list; + path_var.to_list(path_list); - tokenize_variable_array(path_var, path_list); for (i = 0; i < path_list.size(); i++) { const wcstring &ndir_str = path_list.at(i); const wchar_t *ndir = (wchar_t *)ndir_str.c_str(); diff --git a/src/highlight.cpp b/src/highlight.cpp index 69c9d0a45..2a64336f9 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -274,14 +274,14 @@ rgb_color_t highlight_get_color(highlight_spec_t highlight, bool is_background) if (var.missing()) var = env_get(highlight_var[0]); - if (!var.missing()) result = parse_color(var.as_string(), treat_as_background); + if (!var.missing()) result = parse_color(var, treat_as_background); // Handle modifiers. if (highlight & highlight_modifier_valid_path) { - env_var_t val2_wstr = env_get(L"fish_color_valid_path"); - const wcstring val2 = val2_wstr.missing() ? L"" : val2_wstr.c_str(); + env_var_t var2 = env_get(L"fish_color_valid_path"); + const wcstring val2 = var2.missing() ? L"" : var2.c_str(); - rgb_color_t result2 = parse_color(val2, is_background); + rgb_color_t result2 = parse_color(var2, is_background); if (result.is_normal()) result = result2; else { diff --git a/src/output.cpp b/src/output.cpp index 94252223b..9ec4a29cd 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -486,8 +486,8 @@ rgb_color_t best_color(const std::vector &candidates, color_support } /// Return the internal color code representing the specified color. -/// XXX This code should be refactored to enable sharing with builtin_set_color. -rgb_color_t parse_color(const wcstring &val, bool is_background) { +/// TODO: This code should be refactored to enable sharing with builtin_set_color. +rgb_color_t parse_color(const env_var_t &var, bool is_background) { int is_bold = 0; int is_underline = 0; int is_italics = 0; @@ -497,7 +497,7 @@ rgb_color_t parse_color(const wcstring &val, bool is_background) { std::vector candidates; wcstring_list_t el; - tokenize_variable_array(val, el); + var.to_list(el); for (size_t j = 0; j < el.size(); j++) { const wcstring &next = el.at(j); diff --git a/src/output.h b/src/output.h index 26fbdc260..58a871450 100644 --- a/src/output.h +++ b/src/output.h @@ -36,7 +36,7 @@ int writech(wint_t ch); void writestr(const wchar_t *str); -rgb_color_t parse_color(const wcstring &val, bool is_background); +rgb_color_t parse_color(const env_var_t &val, bool is_background); int writeb(tputs_arg_t b); diff --git a/src/path.cpp b/src/path.cpp index adba7451d..bee6ed8b1 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -60,8 +60,8 @@ static bool path_get_path_core(const wcstring &cmd, wcstring *out_path, bin_path = *list_to_array_val(wcstring_list_t({L"/bin", L"/usr/bin", PREFIX L"/bin"})); } - std::vector pathsv; - tokenize_variable_array(bin_path, pathsv); + wcstring_list_t pathsv; + bin_path_var.to_list(pathsv); for (auto next_path : pathsv) { if (next_path.empty()) continue; append_path_component(next_path, cmd);