+ /* Trim filename component (leaving containing directory).
+ *
+ * This function removes everything after the final path
+ * separator, as well as that separator itself if it is not the
+ * only remaining separator.
+ *
+ * Some specific consequences of the above:
+ *
+ * 1. A path with no separator at all is unchanged.
+ * 2. A path with a trailing separator has only that separator removed
+ * 3. A path of just the root directory is unchaged.
+ */
+ void trimFilename(void) {
+ Buffer::iterator first = find(OS_DIR_SEP);
+ Buffer::iterator last = rfind(OS_DIR_SEP);
+ if (last == buffer.end()) {
+ return;
+ }
+ if (last == first) {
+ buffer.erase(first + 1, buffer.end() - 1);
+ } else {
+ buffer.erase(last, buffer.end() - 1);
+ }
+ }
+