src/utils/file.cpp
/**
   * Path expansion
   *
   * `relative_to` must be a directory
   */
Path expansion
`relative_to` must be a directory
Path expansion ` relative_to ` must be a directory
string expand(const string& path, const string& relative_to) {
    bool is_absolute = !path.empty() && (path.at(0) == '/');
    vector<string> p_exploded = string_util::split(path, '/');
    for (auto& section : p_exploded) {
      switch (section[0]) {
        case '$':
          section = env_util::get(section.substr(1));
          break;
        case '~':
          section = env_util::get("HOME");
          break;
      }
    }
    string ret = string_util::join(p_exploded, "/");
    if (ret[0] != '/' && is_absolute) {
      ret.insert(0, 1, '/');
    }
    is_absolute = !ret.empty() && (ret.at(0) == '/');
    if (!is_absolute && !relative_to.empty()) {
      return relative_to + "/" + ret;
    }
    return ret;
  }
string expand ( const string & path , const string & relative_to ) { bool is_absolute = ! path . empty ( ) && ( path . at ( 0 ) == ' ' ) ; vector < string > p_exploded = string_util :: split ( path , ' ' ) ; for ( auto & section : p_exploded ) { switch ( section [ 0 ] ) { case ' ' : section = env_util :: get ( section . substr ( 1 ) ) ; break ; case ' ' : section = env_util :: get ( " " ) ; break ; } } string ret = string_util :: join ( p_exploded , " " ) ; if ( ret [ 0 ] != ' ' && is_absolute ) { ret . insert ( 0 , 1 , ' ' ) ; } is_absolute = ! ret . empty ( ) && ( ret . at ( 0 ) == ' ' ) ; if ( ! is_absolute && ! relative_to . empty ( ) ) { return relative_to + " " + ret ; } return ret ; }
Path expansion
 `relative_to` must be a directory
Path expansion ` relative_to ` must be a directory
/*
     * This doesn't capture all cases for absolute paths but the other cases
     * (tilde and env variable) have the initial '/' character in their
     * expansion already and will thus not require adding '/' to the beginning.
     */ // Don't add an initial slash for relative paths