]> git.tdb.fi Git - libs/core.git/blobdiff - source/utils.cpp
Add copyright notices and Id tags
[libs/core.git] / source / utils.cpp
index 55b191f5216dcd2a60f92c3b878f23248e9e5722..1feb08659bff1a54d0360ca196287af04919821b 100644 (file)
@@ -1,3 +1,10 @@
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
 #include <list>
 #include "utils.h"
 
@@ -59,17 +66,29 @@ Splits a string to parts.
 vector<string> split(const string &str, const string &sep, bool allow_empty)
 {
        vector<string> result;
-       unsigned start=str.find_first_not_of(sep);
+       
+       unsigned start=0;
+       if(!allow_empty)
+               start=str.find_first_not_of(sep);
+       
        while(start<str.size())
        {
                unsigned end=str.find_first_of(sep, start);
                result.push_back(str.substr(start, end-start));
-               if(end==string::npos) break;
+               
+               if(end==string::npos)
+                       break;
+               
                if(allow_empty)
+               {
                        start=end+1;
+                       if(start==str.size())
+                               result.push_back(string());
+               }
                else
                        start=str.find_first_not_of(sep, end);
        }
+
        return result;
 }