Octane v1.01.20 - The Open Compression Toolkit for C++ http://octane.sourceforge.net/
Homepage | Main | Modules | Class Hierarchy | Compound List | File List | Compound Members | Related Pages

utilityclasses/stringparser/stringparser.hpp

Go to the documentation of this file.
00001 //
00002 // Simple string parser.
00003 //
00004 // Copyright (c) 2003 by Octane Project Group
00005 // All Rights Reserved
00006 //
00007 // http://octane.sourceforge.net/
00008 //
00009 
00014 
00015 #ifndef OCTANE_STRINGPARSER_HPP_INCLUDED
00016 #define OCTANE_STRINGPARSER_HPP_INCLUDED
00017 
00018 #include <string>
00019 
00033 class stringparser {
00034 
00035 public:
00038     stringparser(const std::string &_s) : s(_s), idx(0) { ; }
00039 
00043     std::string get_token()
00044     {
00045         if (idx == std::string::npos) return "";
00046 
00047         std::string::size_type p = s.find_first_not_of(' ', idx);
00048 
00049         if (p == std::string::npos) return "";
00050 
00051         idx = s.find_first_of(' ', p);
00052 
00053         if (idx == std::string::npos) return s.substr(p);
00054 
00055         return s.substr(p, idx - p);
00056     }
00057 
00058 private:
00059     const std::string s;
00060     std::string::size_type idx;
00061 };
00062 
00063 #endif // OCTANE_STRINGPARSER_HPP_INCLUDED
 
Generated on 20 May 2004 by doxygen 1.3.3