Example #1
0
ArrayClass<int> computeNext(BString& pattern)
{
	int p;
	int q;
	ArrayClass<int> next(pattern.length(), 0);
	for (p = 2; p < pattern.length(); p++) //p is right end
	{
		q = next[p-1]; // q is presumed value of next[p]-1
		do
		{
			if(q >= 0)
			{
				if(pattern[q] == pattern[p])
				{
					next[p] = q + 1;
					break;
				}//(pattern[q] == pattern[p])
				else
				{
					if (q == 0)
						break;
					else
						q = next[q-1];
				}//(pattern[q] != pattern[p])
			}//(q>=0)
		} while (q >= 0);
	}//(p = 2; p < pattern.length(); p++)
	return next;
}
Example #2
0
			BOOTIL_EXPORT void FindAndReplace( BString& strIn, const BString& strFind, const BString& strReplace )
			{
				size_t pos = 0;
				while( ( pos = strIn.find( strFind, pos ) ) != std::string::npos )
				{
					strIn.replace( pos, strFind.length(), strReplace );
					pos += strReplace.length();
				}  
			}
Example #3
0
			BOOTIL_EXPORT void Split( const BString& str, const BString& seperator, String::List& outbits )
			{
				BString strBit;
				int iOffset = 0;
				int iLength = str.length();
				int iSepLen = seperator.length();

				int i = str.find( seperator, 0 );
				while ( i != std::string::npos )
				{
					outbits.push_back( str.substr( iOffset, i-iOffset ) );
					iOffset = i + iSepLen;

					i = str.find( seperator, iOffset );
				}

				outbits.push_back( str.substr( iOffset, iLength-iOffset ) );
			}
Example #4
0
		BOOTIL_EXPORT bool Write( const BString & strFileName, const BString & strOut )
		{
			std::ofstream f( strFileName.c_str(), std::ios_base::out );

			if ( !f.is_open() ) { return false; }

			f.write( strOut.c_str(), strOut.length() );
			f.close();
			return true;
		}
Example #5
0
		BOOTIL_EXPORT void SetupAssociation( BString ext )
		{
			//Write our file association to the registry -NOTE: must run in administrator mode once to work
			HKEY hKey;
			LPDWORD dwDisp = 0;
			BString strmv = "\"" + FullProgramName() + "\" %1";
			String::File::ToWindowsSlashes( strmv );
			BString keyName = ext + "\\shell\\open\\command";
			LONG lRet  = RegCreateKeyEx( HKEY_CLASSES_ROOT, keyName.c_str(), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, dwDisp );

			if ( !lRet )
			{ RegSetValueEx( hKey, NULL, 0, REG_SZ, ( BYTE* )strmv.c_str(), strmv.length() + 1 ); }
		}
Example #6
0
//returns index of start of P in T 
//or -1 if P is not a substring of T
int KMPStringMatch(BString& T, BString& P)
{
	if(P.length() == 0)
		return 0; //0 length string is always a substring
	if(T.length() == 0)
		return -1; //0 length string has no substrings
	ArrayClass<int> next = computeNext(P);
	int pPos = 0;
	int tPos = 0;
	while(tPos < T.length())
	{
		if(P[pPos] == T[tPos])//matched so far
		{
			pPos++;
			tPos++;
		}//(P[pPos] == T[tPos])
		else//mismatch
		{
			if(next[pPos] <= 0)
			{
				tPos++;
				pPos = 0;
			}//(next[pPos] <= 0)
			else
			{
				pPos = next[pPos-1];
			}//!(next[pPos] <= 0)
		}
	
		if(pPos == P.length())
		{
			//matched whole pattern. now return
			//starting position
			return(tPos - P.length());
		}//(pPos == P.length())
	
	}//while(tPos < T.length())	
	return -1;
}
Example #7
0
File: HTTP.cpp Project: Bo98/bootil
			void Query::Run()
			{
				m_bError = false;
				m_strError = "";

				m_Response.Clear();

				unsigned int iLastData = 0;

				try
				{
					Lock();

						happyhttp::Connection conn( m_strHost.c_str(), m_iPort );
						conn.setcallbacks( NULL, OnData, NULL, (void*) this );

						conn.putrequest( m_strMethod.c_str(), m_strRequest.c_str() );
						conn.putheader( "Accept", "*/*" );
						conn.putheader( "User-Agent", "Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36" );

						if ( m_PostBody.GetWritten() > 0 )
						{
							// Finish off the post body
							m_PostBody.WriteString( "\r\n--" + m_strBoundary + "--\r\n\r\n", false );

							// Add headers
							conn.putheader( "Content-Type", ("multipart/form-data; boundary=" + m_strBoundary).c_str() );
							conn.putheader( "Content-Length", m_PostBody.GetWritten() );
							conn.putheader( "Connection", "Close" );
							conn.putheader( "Cache-Control", "no-cache" );
						}

						conn.endheaders();

						if ( m_PostBody.GetWritten() > 0 )
						{
							conn.send( (const unsigned char*) m_PostBody.GetBase(), m_PostBody.GetWritten() );
						}
						else
						{
							BString strEmpty;
							conn.send( (const unsigned char*) strEmpty.c_str(), strEmpty.length() );
						}
			
					Unlock();
					
					Time::Timer timer;

					while( conn.outstanding() )
					{
						conn.pump();

						//
						// Don't time out if we got data this frame
						//
						if ( GetResponse().GetWritten() != iLastData )
						{
							timer.Reset();
							iLastData = GetResponse().GetWritten();
						}

						//
						// Time out connection after x seconds of no activity
						//
						if ( timer.Seconds() > (60 * 3) ) break;

						//
						// Breathe
						//
						Bootil::Platform::Sleep( 10 );
					}
				}
				catch ( happyhttp::Wobbly& e )
				{
					m_bError = true;
					m_strError = e.what();
				}
			}