]> git.tdb.fi Git - libs/core.git/blobdiff - source/path.cpp
Add Path::empty()
[libs/core.git] / source / path.cpp
index 1ff318101aea18a74b7d397b015fc5dfb58736b4..1a9460ac9c15f4496fd320adacf89d9aed36401a 100644 (file)
@@ -1,17 +1,17 @@
+/*
+This file is part of libmsppath
+Copyright © 2006  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
 #include <msp/strutils.h>
 #include "path.h"
+#include "utils.h"
 
 using namespace std;
-#include <iostream>
 
 namespace Msp {
 namespace Path {
 
-bool is_windows_drive(const std::string &p)
-{
-       return (p.size()==2 && ((p[0]>='A' && p[0]<='Z') || (p[0]>='a' && p[0]<='z')) && p[1]==':');
-}
-
 /**
 Returns the number of components in the path.
 */
@@ -141,10 +141,12 @@ Path::iterator::iterator(const Path &p):
        path(p),
        start(0)
 {
-       if(path.path[0]==DIRCHAR)
+       if(path.path.empty())
+               start=end=string::npos;
+       else if(path.path[0]==DIRCHAR)
                end=1;
 #ifdef WIN32
-       else if(path.path[2]==DIRCHAR && is_windows_drive(path.path.substr(0,2)))
+       else if(path.path.size()>2 && path.path[2]==DIRCHAR && is_windows_drive(path.path.substr(0,2)))
                end=2;
 #endif
        else