[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2879 - branches/pingus_sdl/src
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r2879 - branches/pingus_sdl/src |
Date: |
Mon, 13 Aug 2007 04:27:29 +0200 |
Author: grumbel
Date: 2007-08-13 04:27:28 +0200 (Mon, 13 Aug 2007)
New Revision: 2879
Added:
branches/pingus_sdl/src/line_iterator.cpp
branches/pingus_sdl/src/line_iterator.hpp
Modified:
branches/pingus_sdl/src/
branches/pingus_sdl/src/SConscript
branches/pingus_sdl/src/col_map.cpp
Log:
- added little helper class for string splitting
Property changes on: branches/pingus_sdl/src
___________________________________________________________________
Name: svn:ignore
-
*.a
aclocal.m4
autom4te.cache
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
.deps
*.gmo
Makefile
Makefile.in
missing
*.o
old
old/
pingus
pingus_level_test
.sconsign
semantic.cache
stamp-h1
xmleval
+
*.a
aclocal.m4
autom4te.cache
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
.deps
*.gmo
line_iterator
Makefile
Makefile.in
missing
*.o
old
old/
pingus
pingus_level_test
.sconsign
semantic.cache
stamp-h1
xmleval
Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript 2007-08-13 02:13:21 UTC (rev 2878)
+++ branches/pingus_sdl/src/SConscript 2007-08-13 02:27:28 UTC (rev 2879)
@@ -167,6 +167,8 @@
'gui/screen_ptr.cpp',
'gui/surface_button.cpp',
+'line_iterator.cpp',
+
'lisp/getters.cpp',
'lisp/lexer.cpp',
'lisp/lisp.cpp',
Modified: branches/pingus_sdl/src/col_map.cpp
===================================================================
--- branches/pingus_sdl/src/col_map.cpp 2007-08-13 02:13:21 UTC (rev 2878)
+++ branches/pingus_sdl/src/col_map.cpp 2007-08-13 02:27:28 UTC (rev 2879)
@@ -128,7 +128,7 @@
// FIXME: Inline me
if (gtype == Groundtype::GP_BRIDGE)
{
- int pixel = getpixel (x, y);
+ int pixel = getpixel(x, y);
return pixel == Groundtype::GP_NOTHING;
}
else
Added: branches/pingus_sdl/src/line_iterator.cpp
===================================================================
--- branches/pingus_sdl/src/line_iterator.cpp 2007-08-13 02:13:21 UTC (rev
2878)
+++ branches/pingus_sdl/src/line_iterator.cpp 2007-08-13 02:27:28 UTC (rev
2879)
@@ -0,0 +1,96 @@
+/* $Id$
+**
+** Pingus - A free Lemmings clone
+** Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+** This program is free software; you can redistribute it and/or
+** modify it under the terms of the GNU General Public License
+** as published by the Free Software Foundation; either version 2
+** of the License, or (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+** 02111-1307, USA.
+*/
+
+#include "line_iterator.hpp"
+
+LineIterator::LineIterator(const std::string& str)
+ : first(str.begin()),
+ last(str.end()),
+ line_end(str.begin())
+{
+}
+
+LineIterator::LineIterator(std::string::const_iterator first_,
+ std::string::const_iterator last_)
+ : first(first_),
+ last(last_),
+ line_end(first_)
+{
+}
+
+bool
+LineIterator::next()
+{
+ if (line_end == last || line_end+1 == last)
+ {
+ return false;
+ }
+ else
+ {
+ if (first != line_end)
+ first = line_end + 1;
+
+ do {
+ ++line_end;
+ } while(line_end != last && *line_end != '\n');
+
+ return true;
+ }
+}
+
+std::string
+LineIterator::get()
+{
+ return std::string(first, line_end);
+}
+
+#ifdef __TEST__
+// g++ line_iterator.cpp -o line_iterator -D__TEST__ -Wall -Werror -ansi
-pedantic
+#include <iostream>
+
+void test(const std::string& str)
+{
+ std::cout << "Testing: " << std::endl;
+ std::cout << "in: \"" << str << "\"" << std::endl;
+
+ std::cout << "out: " << std::flush;
+
+ LineIterator it(str);
+ while(it.next())
+ std::cout << "\"" << it.get() << "\" " << std::flush;
+
+ std::cout << std::endl;
+ std::cout << std::endl;
+}
+
+int main()
+{
+ test("Test One");
+ test("Test\nTwo");
+ test("\nHello\nThree");
+ test("Hello Four\n");
+ test("Hello\nWorld\nFooBar\n");
+ test("Hello\nWorld\nFooBar\n\n");
+ return 0;
+}
+#endif
+
+/* EOF */
Property changes on: branches/pingus_sdl/src/line_iterator.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: branches/pingus_sdl/src/line_iterator.hpp
===================================================================
--- branches/pingus_sdl/src/line_iterator.hpp 2007-08-13 02:13:21 UTC (rev
2878)
+++ branches/pingus_sdl/src/line_iterator.hpp 2007-08-13 02:27:28 UTC (rev
2879)
@@ -0,0 +1,57 @@
+/* $Id$
+**
+** Pingus - A free Lemmings clone
+** Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+** This program is free software; you can redistribute it and/or
+** modify it under the terms of the GNU General Public License
+** as published by the Free Software Foundation; either version 2
+** of the License, or (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+** 02111-1307, USA.
+*/
+
+#ifndef HEADER_LINE_ITERATOR_HPP
+#define HEADER_LINE_ITERATOR_HPP
+
+#include <string>
+
+/** Splits a given string at newlines, a new line at the end of the
+ * string is ignored, others are returned as empty lines. Newlines
+ * aren't included in the returned string.Use via:
+ *
+ * LineIterator it("Hello\nWorld);
+ * while(it.next())
+ * std::cout << it.get() << std::endl;
+ */
+class LineIterator
+{
+private:
+ std::string::const_iterator first;
+ std::string::const_iterator last;
+ std::string::const_iterator line_end;
+
+public:
+ LineIterator(const std::string& str);
+ LineIterator(std::string::const_iterator first,
+ std::string::const_iterator last);
+
+ /** @return false when no characters are left in the string, true
+ otherwise */
+ bool next();
+
+ /** @return the current line */
+ std::string get();
+};
+
+#endif
+
+/* EOF */
Property changes on: branches/pingus_sdl/src/line_iterator.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2879 - branches/pingus_sdl/src,
grumbel at BerliOS <=