From 7876bc6ef37bcaf65fa2b8efc7500fcecf269b70 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 13 Aug 2017 15:30:54 -0700 Subject: [PATCH] Revert "make `tokenize_variable_array()` private" This reverts commit 4fe9d794382b6b81967e6ee88c76403bb8a69541. It was meant for the major branch. --- 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, 25 insertions(+), 20 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index f3db6495a..7a6ef56d5 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -105,7 +105,6 @@ 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 @@ -1622,7 +1621,7 @@ std::unique_ptr list_to_array_val(const wchar_t **list) { return val; } -static void tokenize_variable_array(const wcstring &val, wcstring_list_t &out) { +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 b7f3c2158..64a2327df 100644 --- a/src/env.h +++ b/src/env.h @@ -69,6 +69,12 @@ 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 f265485d4..aa972a458 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 env_var_t &var) { +wcstring expand_escape_variable(const wcstring &in) { wcstring_list_t lst; wcstring buff; - var.to_list(lst); + tokenize_variable_array(in, lst); size_t size = lst.size(); if (size == 0) { diff --git a/src/expand.h b/src/expand.h index 2fd0423bd..10fc88df5 100644 --- a/src/expand.h +++ b/src/expand.h @@ -13,7 +13,6 @@ #include #include "common.h" -#include "env.h" #include "parse_constants.h" enum { @@ -121,10 +120,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 = env_get(L"fish_function_path"); - if (path_var.missing_or_empty()) return; + 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(); 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 2a64336f9..69c9d0a45 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, treat_as_background); + if (!var.missing()) result = parse_color(var.as_string(), treat_as_background); // Handle modifiers. if (highlight & highlight_modifier_valid_path) { - env_var_t var2 = env_get(L"fish_color_valid_path"); - const wcstring val2 = var2.missing() ? L"" : var2.c_str(); + env_var_t val2_wstr = env_get(L"fish_color_valid_path"); + const wcstring val2 = val2_wstr.missing() ? L"" : val2_wstr.c_str(); - rgb_color_t result2 = parse_color(var2, is_background); + rgb_color_t result2 = parse_color(val2, is_background); if (result.is_normal()) result = result2; else { diff --git a/src/output.cpp b/src/output.cpp index 9ec4a29cd..94252223b 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. -/// 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) { +/// XXX This code should be refactored to enable sharing with builtin_set_color. +rgb_color_t parse_color(const wcstring &val, 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 env_var_t &var, bool is_background) { std::vector candidates; wcstring_list_t el; - var.to_list(el); + tokenize_variable_array(val, 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 58a871450..26fbdc260 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 env_var_t &val, bool is_background); +rgb_color_t parse_color(const wcstring &val, bool is_background); int writeb(tputs_arg_t b); diff --git a/src/path.cpp b/src/path.cpp index 40ecd0757..1b20d8fc6 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"})); } - wcstring_list_t pathsv; - bin_path_var.to_list(pathsv); + std::vector pathsv; + tokenize_variable_array(bin_path, pathsv); for (auto next_path : pathsv) { if (next_path.empty()) continue; append_path_component(next_path, cmd);