1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 #ifndef __SPLITSTRING_HXX__
17 #define __SPLITSTRING_HXX__
18 
19 #include <string>
20 #include <vector>
21 
22 namespace org_modules_xml
23 {
24 /**
25  * @file
26  * @author Calixte DENIZET <calixte.denizet@scilab.org>
27  *
28  * Split a string into lines
29  */
30 class SplitString
31 {
32 
33 public:
34     /**
35      * Split string into lines
36      * @param str the string to split
37      * @param lines a vector which will contain lines
38      */
split(const std::string & str,std::vector<std::string> & lines)39     static void split(const std::string & str, std::vector < std::string > &lines)
40     {
41         std::string::size_type lastPos = str.find_first_not_of("\n", 0);
42         std::string::size_type pos = str.find_first_of("\n", lastPos);
43 
44         while (std::string::npos != pos || std::string::npos != lastPos)
45         {
46             lines.push_back(str.substr(lastPos, pos - lastPos));
47             lastPos = str.find_first_not_of("\n", pos);
48             pos = str.find_first_of("\n", lastPos);
49         }
50     }
51 };
52 }
53 
54 #endif
55