|
From: <cn...@us...> - 2009-06-28 21:59:33
|
Revision: 387
http://hgengine.svn.sourceforge.net/hgengine/?rev=387&view=rev
Author: cnlohr
Date: 2009-06-28 21:59:32 +0000 (Sun, 28 Jun 2009)
Log Message:
-----------
add utility String functions (this is taken mostly from HG1, these functions proved highly useful and
did not appear to cause problems)
Modified Paths:
--------------
Mercury2/src/MercuryUtil.cpp
Mercury2/src/MercuryUtil.h
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2009-06-28 21:58:37 UTC (rev 386)
+++ Mercury2/src/MercuryUtil.cpp 2009-06-28 21:59:32 UTC (rev 387)
@@ -1,6 +1,7 @@
#include <MercuryUtil.h>
#include <MercuryFile.h>
#include <Mint.h>
+#include <MercuryVector.h>
MString ToUpper(const MString& s)
{
@@ -87,6 +88,55 @@
return (ith<0)?3:(ith>15)?GeneralUsePrimes[15]:GeneralUsePrimes[ith];
}
+//String processing functions
+long BytesUntil( const char* strin, const char * termin, long start, long slen, long termlen )
+{
+ int i;
+ for ( i = start; i < slen; i++ )
+ for ( int j = 0; j < termlen; j++ )
+ if ( termin[j] == strin[i] )
+ return i - start;
+ return i - start;
+}
+
+long BytesNUntil( const char* strin, const char * termin, long start, long slen, long termlen )
+{
+ int i;
+ for ( i = start; i < slen; i++ )
+ {
+ bool found = false;
+ for ( int j = 0; j < termlen; j++ )
+ {
+ if ( termin[j] == strin[i] )
+ found = true;
+ }
+ if ( !found )
+ return i - start;
+ }
+ return i - start;
+}
+
+void SplitStrings( const MString & in, MVector < MString > & out,
+ const char * termin, const char * whitespace,
+ long termlen, long wslen )
+{
+ const char * inStr = in.c_str();
+ long curPos = 0;
+ long inLen = in.length();
+ while ( curPos < inLen )
+ {
+ curPos += BytesNUntil( inStr, whitespace, curPos, inLen, wslen );
+ long NextPos = BytesUntil( inStr, termin, curPos, inLen, termlen );
+ out.push_back( in.substr( curPos, NextPos ) );
+ curPos += NextPos + 1;
+ }
+}
+
+
+
+
+
+
/* Copyright (c) 2009, Joshua Allen and Charles Lohr
* All rights reserved.
*
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2009-06-28 21:58:37 UTC (rev 386)
+++ Mercury2/src/MercuryUtil.h 2009-06-28 21:59:32 UTC (rev 387)
@@ -104,6 +104,24 @@
///pattern is the next prime number that's roughly two times the last.
int GetAPrime( int ith );
+
+
+
+//String processing functions
+//XXX: This may not be portable. We do not in fact need to include the header for MVector yet.
+template<typename T>
+class MVector;
+
+///Bytes until desired terminal
+long BytesUntil( const char* strin, const char * termin, long start, long slen, long termlen );
+
+///Bytes until something other than a terminal
+long BytesNUntil( const char* strin, const char * termin, long start, long slen, long termlen );
+
+///Split given string into other strings using delimiters from termin
+void SplitStrings( const MString & in, MVector < MString > & out, const char * termin, const char * whitespace, long termlen, long wslen );
+
+
#endif
/* Copyright (c) 2009, Joshua Allen and Charles Lohr
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|