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.
This commit is contained in:
Kurtis Rader 2017-08-05 21:40:27 -07:00
parent c36ad27618
commit 4fe9d79438
9 changed files with 20 additions and 25 deletions

View file

@ -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. // Some forward declarations to make it easy to logically group the code.
static void init_locale(); static void init_locale();
static void init_curses(); 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. // Struct representing one level in the function variable stack.
// Only our variable stack should create and destroy these // Only our variable stack should create and destroy these
@ -1621,7 +1622,7 @@ std::unique_ptr<wcstring> list_to_array_val(const wchar_t **list) {
return val; 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 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. // Zero element arrays are internally encoded as this placeholder string.

View file

@ -69,12 +69,6 @@ void env_init(const struct config_paths_t *paths = NULL);
/// routines. /// routines.
void misc_init(); 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 { class env_var_t {
private: private:
bool is_missing; bool is_missing;

View file

@ -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()); } 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_list_t lst;
wcstring buff; wcstring buff;
tokenize_variable_array(in, lst); var.to_list(lst);
size_t size = lst.size(); size_t size = lst.size();
if (size == 0) { if (size == 0) {

View file

@ -13,6 +13,7 @@
#include <vector> #include <vector>
#include "common.h" #include "common.h"
#include "env.h"
#include "parse_constants.h" #include "parse_constants.h"
enum { enum {
@ -120,10 +121,10 @@ __warn_unused expand_error_t expand_string(const wcstring &input, std::vector<co
bool expand_one(wcstring &inout_str, expand_flags_t flags, parse_error_list_t *errors = NULL); bool expand_one(wcstring &inout_str, expand_flags_t flags, parse_error_list_t *errors = NULL);
/// Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc. /// Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc.
/// Suitable for pretty-printing. The result must be free'd! /// Suitable for pretty-printing.
/// ///
/// \param in the value to escape /// \param in the value to escape
wcstring expand_escape_variable(const wcstring &in); wcstring expand_escape_variable(const env_var_t &var);
/// Perform tilde expansion and nothing else on the specified string, which is modified in place. /// Perform tilde expansion and nothing else on the specified string, which is modified in place.
/// ///

View file

@ -78,13 +78,12 @@ static int load(const wcstring &name) {
static void autoload_names(std::set<wcstring> &names, int get_hidden) { static void autoload_names(std::set<wcstring> &names, int get_hidden) {
size_t i; size_t i;
const env_var_t path_var_wstr = env_get(L"fish_function_path"); const env_var_t path_var = env_get(L"fish_function_path");
if (path_var_wstr.missing()) return; if (path_var.missing_or_empty()) return;
const wchar_t *path_var = path_var_wstr.c_str();
wcstring_list_t path_list; 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++) { for (i = 0; i < path_list.size(); i++) {
const wcstring &ndir_str = path_list.at(i); const wcstring &ndir_str = path_list.at(i);
const wchar_t *ndir = (wchar_t *)ndir_str.c_str(); const wchar_t *ndir = (wchar_t *)ndir_str.c_str();

View file

@ -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()) 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. // Handle modifiers.
if (highlight & highlight_modifier_valid_path) { if (highlight & highlight_modifier_valid_path) {
env_var_t val2_wstr = env_get(L"fish_color_valid_path"); env_var_t var2 = env_get(L"fish_color_valid_path");
const wcstring val2 = val2_wstr.missing() ? L"" : val2_wstr.c_str(); 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()) if (result.is_normal())
result = result2; result = result2;
else { else {

View file

@ -486,8 +486,8 @@ rgb_color_t best_color(const std::vector<rgb_color_t> &candidates, color_support
} }
/// Return the internal color code representing the specified color. /// Return the internal color code representing the specified color.
/// XXX This code should be refactored to enable sharing with builtin_set_color. /// TODO: This code should be refactored to enable sharing with builtin_set_color.
rgb_color_t parse_color(const wcstring &val, bool is_background) { rgb_color_t parse_color(const env_var_t &var, bool is_background) {
int is_bold = 0; int is_bold = 0;
int is_underline = 0; int is_underline = 0;
int is_italics = 0; int is_italics = 0;
@ -497,7 +497,7 @@ rgb_color_t parse_color(const wcstring &val, bool is_background) {
std::vector<rgb_color_t> candidates; std::vector<rgb_color_t> candidates;
wcstring_list_t el; wcstring_list_t el;
tokenize_variable_array(val, el); var.to_list(el);
for (size_t j = 0; j < el.size(); j++) { for (size_t j = 0; j < el.size(); j++) {
const wcstring &next = el.at(j); const wcstring &next = el.at(j);

View file

@ -36,7 +36,7 @@ int writech(wint_t ch);
void writestr(const wchar_t *str); 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); int writeb(tputs_arg_t b);

View file

@ -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"})); bin_path = *list_to_array_val(wcstring_list_t({L"/bin", L"/usr/bin", PREFIX L"/bin"}));
} }
std::vector<wcstring> pathsv; wcstring_list_t pathsv;
tokenize_variable_array(bin_path, pathsv); bin_path_var.to_list(pathsv);
for (auto next_path : pathsv) { for (auto next_path : pathsv) {
if (next_path.empty()) continue; if (next_path.empty()) continue;
append_path_component(next_path, cmd); append_path_component(next_path, cmd);