24 static char *home_dir =
".";
34 split (
const char* src_, std::vector<std::string>& vec_)
36 std::istringstream input (src_);
37 vec_.erase (vec_.begin (), vec_.end ());
40 while (input >> token) {
41 vec_.push_back (token);
47 split_pair (
const string& text_,
char sep_,
string& lhs_,
string& rhs_)
50 if ((pos = text_.find (sep_)) == string::npos) {
53 lhs_ = text_.substr (0, pos);
54 rhs_ = text_.substr (pos+1, text_.size ());
55 pos = rhs_.size () -1;
56 if (rhs_[0] ==
'"' || rhs_[0] ==
'\'') {
59 if (rhs_[pos] ==
'"' || rhs_[pos] ==
'\'') {
67 ltrim (std::string& text_,
const std::string& delim_)
69 std::string::size_type idx;
70 idx = text_.find_first_of (delim_);
71 if (idx != std::string::npos) {
72 text_.replace (0, idx+1,
"");
80 rtrim (std::string& text_,
const std::string& delim_)
82 std::string::size_type idx;
83 idx = text_.find_last_of (delim_);
84 if (idx != std::string::npos) {
85 text_.replace (idx, text_.size (),
"");
95 std::string::size_type idx;
97 idx = text_.find_first_not_of (
" \t");
98 if (idx != std::string::npos) {
99 text_.replace (0, idx,
"");
102 idx = text_.find_last_not_of (
" \t");
103 if (idx != std::string::npos) {
104 text_.replace (idx + 1, text_.size (),
"");
112 string::iterator pos = text_.begin ();
113 while (pos != text_.end ()) {
114 if ((*pos) == src_) {
130 if ( *(in+1) == 0 || *(in+1) ==
'/' ) {
132 strcpy (ret, getenv (
"HOME") ? getenv (
"HOME") :
"");
139 const char* sp = strchr (in,
'/');
141 while (in != sp) *lp++ = *in++;
145 while (*in) *lp++ = *in++;
149 strcpy (ret, home_dir);
153 struct passwd* p = getpwnam (lname);
155 strcpy (ret, p->pw_dir ? p->pw_dir :
"");
167 const char *end = strchr (in,
')');
170 strncpy (varname, in, end-in);
171 varname [end-in] =
'\0';
174 else if (*in ==
'{') {
175 const char *end = strchr (in,
'}');
178 strncpy (varname, in, end-in);
179 varname [end-in] =
'\0';
184 while (isalnum (*in) || *in ==
'_' ) {
189 char* ep = ::getenv (varname);
190 while (ep && *ep) *r++ = *ep++;
193 else if (*in ==
'\\' && *(in+1)) {
211 chr_ptr =
new char [size];
212 if (::getcwd (chr_ptr, size-1) != NULL) {
217 if (errno != ERANGE) {