mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-23 19:33:12 +00:00
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:
parent
c36ad27618
commit
4fe9d79438
9 changed files with 20 additions and 25 deletions
|
@ -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<wcstring> 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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <vector>
|
||||
|
||||
#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<co
|
|||
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.
|
||||
/// Suitable for pretty-printing. The result must be free'd!
|
||||
/// Suitable for pretty-printing.
|
||||
///
|
||||
/// \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.
|
||||
///
|
||||
|
|
|
@ -78,13 +78,12 @@ static int load(const wcstring &name) {
|
|||
static void autoload_names(std::set<wcstring> &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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
/// 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<rgb_color_t> 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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<wcstring> 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);
|
||||
|
|
Loading…
Reference in a new issue