src/file.cpp

changeset 234
79b120b0aa51
parent 232
4e44c92e21dd
child 235
bb0a7bcca7eb
equal deleted inserted replaced
233:524cb0833027 234:79b120b0aa51
117 if (path[(size_t) lastpos] == DIRSLASH_CHAR) 117 if (path[(size_t) lastpos] == DIRSLASH_CHAR)
118 break; 118 break;
119 119
120 if (lastpos > 0) 120 if (lastpos > 0)
121 return path.substr (0, lastpos); 121 return path.substr (0, lastpos);
122
123 return "";
124 }
125
126 // =============================================================================
127 str basename (str path) {
128 long lastpos; // FIXME: why doesn't str::last () work here?
129 for (lastpos = path.len () - 1; lastpos >= 0; --lastpos)
130 if (path[(size_t) lastpos] == DIRSLASH_CHAR)
131 break;
132
133 if (lastpos < (log) path.len () - 1)
134 return path.substr (lastpos + 1, -1);
122 135
123 return ""; 136 return "";
124 } 137 }
125 138
126 // ============================================================================= 139 // =============================================================================

mercurial