|
From: <pst...@us...> - 2008-04-19 23:20:22
|
Revision: 464
http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=464&view=rev
Author: pstieber
Date: 2008-04-19 16:20:18 -0700 (Sat, 19 Apr 2008)
Log Message:
-----------
Added a string utility function that tokenizes a std::string based on the passed
delimiters.
Added Paths:
-----------
trunk/jazz/src/StringUtilities.cpp
trunk/jazz/src/StringUtilities.h
Added: trunk/jazz/src/StringUtilities.cpp
===================================================================
--- trunk/jazz/src/StringUtilities.cpp (rev 0)
+++ trunk/jazz/src/StringUtilities.cpp 2008-04-19 23:20:18 UTC (rev 464)
@@ -0,0 +1,63 @@
+//*****************************************************************************
+// The JAZZ++ Midi Sequencer
+//
+// Copyright (C) 2008 Peter J. Stieber, all rights reserved.
+//
+// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+//*****************************************************************************
+
+#include "StringUtilities.h"
+
+using namespace std;
+
+//-----------------------------------------------------------------------------
+// Decsription:
+// This function tokenizes the input string.
+//-----------------------------------------------------------------------------
+unsigned TNStringUtilities::Tokenize(
+ const string& Delimiters,
+ const string& InputString,
+ vector<string>& Tokens)
+{
+ // make sure the vector of tokens is empty.
+ Tokens.clear();
+
+ string::size_type Begin, End;
+
+ // Initialize the token index.
+ unsigned TokenIndex = 0;
+
+ // Search the beginning of the string for the first token.
+ Begin = InputString.find_first_not_of(Delimiters);
+
+ // While at the beginning of a word found.
+ while (Begin != string::npos)
+ {
+ // Search for the end of the actual token.
+ End = InputString.find_first_of(Delimiters, Begin);
+
+ if (End == string::npos)
+ {
+ End = InputString.length();
+ }
+
+ Tokens.push_back(InputString.substr(Begin, End - Begin));
+
+ ++TokenIndex;
+
+ Begin = InputString.find_first_not_of(Delimiters, End);
+ }
+ return TokenIndex;
+}
Property changes on: trunk/jazz/src/StringUtilities.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/jazz/src/StringUtilities.h
===================================================================
--- trunk/jazz/src/StringUtilities.h (rev 0)
+++ trunk/jazz/src/StringUtilities.h 2008-04-19 23:20:18 UTC (rev 464)
@@ -0,0 +1,41 @@
+//*****************************************************************************
+// The JAZZ++ Midi Sequencer
+//
+// Copyright (C) 2008 Peter J. Stieber, all rights reserved.
+//
+// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+//*****************************************************************************
+
+#ifndef TRC_STRINGUTILITIES_H
+#define TRC_STRINGUTILITIES_H
+
+#include <string>
+#include <vector>
+
+namespace TNStringUtilities
+{
+
+//-----------------------------------------------------------------------------
+// Decsription:
+// This function tokenizes the input string.
+//-----------------------------------------------------------------------------
+unsigned Tokenize(
+ const std::string& Delimiters,
+ const std::string& InputString,
+ std::vector<std::string>& Tokens);
+
+};
+
+#endif // !defined(TRC_STRINGUTILITIES_H)
Property changes on: trunk/jazz/src/StringUtilities.h
___________________________________________________________________
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|