/[pcsx2_0.9.7]/trunk/common/include/Utilities/StringHelpers.h
ViewVC logotype

Diff of /trunk/common/include/Utilities/StringHelpers.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/common/include/Utilities/StringHelpers.h	2010/09/07 06:28:05	61
+++ trunk/common/include/Utilities/StringHelpers.h	2010/09/07 11:08:22	62
@@ -16,9 +16,50 @@
 #pragma once
 
 #include "Dependencies.h"
+#include "SafeArray.h"
 
 #include <wx/tokenzr.h>
-#include <wx/gdicmn.h>		// for wxPoint/wxRect stuff
+
+
+// --------------------------------------------------------------------------------------
+//  pxToUTF8
+// --------------------------------------------------------------------------------------
+// Converts a string to UTF8 and provides an interface for getting its length.
+class pxToUTF8
+{
+	DeclareNoncopyableObject( pxToUTF8 );
+
+protected:
+	wxCharBuffer	m_result;
+	int				m_length;
+
+public:
+	explicit pxToUTF8(const wxString& src)
+		: m_result( src.ToUTF8() )
+	{
+		m_length = -1;
+	}
+
+	size_t Length()
+	{
+		if( -1 == m_length )
+			m_length = strlen( m_result );
+		return m_length;
+	}
+
+	void Convert( const wxString& src )
+	{
+		m_result = src.ToUTF8();
+		m_length = -1;
+	}
+	
+	const char* data() const { return m_result; }
+	
+	operator const char*() const
+	{
+		return m_result.data();
+	}
+};
 
 extern void px_fputs( FILE* fp, const char* src );
 
@@ -29,7 +70,8 @@
 extern const wxRect wxDefaultRect;
 
 extern void SplitString( wxArrayString& dest, const wxString& src, const wxString& delims, wxStringTokenizerMode mode = wxTOKEN_RET_EMPTY_ALL );
-extern void JoinString( wxString& dest, const wxArrayString& src, const wxString& separator );
+extern wxString JoinString( const wxArrayString& src, const wxString& separator );
+extern wxString JoinString( const wxChar** src, const wxString& separator );
 
 extern wxString ToString( const wxPoint& src, const wxString& separator=L"," );
 extern wxString ToString( const wxSize& src, const wxString& separator=L"," );
@@ -65,9 +107,61 @@
 	ParsedAssignmentString( const wxString& src );
 };
 
-extern wxString FastFormatString_Ascii(const char* fmt, va_list argptr);
-extern wxString FastFormatString_Unicode(const wxChar* fmt, va_list argptr);
+// --------------------------------------------------------------------------------------
+//  FastFormatAscii
+// --------------------------------------------------------------------------------------
+// Fast formatting of ASCII text.  This class uses a process-wide format buffer that is
+// allocated only once and grown to accommodate string formatting needs.  The buffer is
+// thread-safe.  This technique reduces the overhead of formatting strings by eliminating
+// most or all heap allocation actions.
+//
+class FastFormatAscii
+{
+protected:
+	SafeArray<char>*	m_dest;
+	bool				m_deleteDest;
+	
+public:
+	FastFormatAscii();
+	~FastFormatAscii() throw();
+	FastFormatAscii& Write( const char* fmt, ... );
+	FastFormatAscii& WriteV( const char* fmt, va_list argptr );
+
+	bool IsEmpty() const;
+
+	const char* c_str() const		{ return m_dest->GetPtr(); }
+	operator const char*() const	{ return m_dest->GetPtr(); }
+
+	const wxString GetString() const;
+	//operator wxString() const;
+};
+
+class FastFormatUnicode
+{
+protected:
+	SafeArray<char>*	m_dest;
+	bool				m_deleteDest;
+
+public:
+	FastFormatUnicode();
+	~FastFormatUnicode() throw();
+
+	FastFormatUnicode& Write( const char* fmt, ... );
+	FastFormatUnicode& Write( const wxChar* fmt, ... );
+	FastFormatUnicode& WriteV( const char* fmt, va_list argptr );
+	FastFormatUnicode& WriteV( const wxChar* fmt, va_list argptr );
+
+	bool IsEmpty() const;
+
+	const wxChar* c_str() const		{ return (const wxChar*)m_dest->GetPtr(); }
+	operator const wxChar*() const	{ return (const wxChar*)m_dest->GetPtr(); }
+	operator wxString() const		{ return (const wxChar*)m_dest->GetPtr(); }
+};
+
+extern bool pxParseAssignmentString( const wxString& src, wxString& ldest, wxString& rdest );
 
+#define pxsFmt FastFormatUnicode().Write
+#define pxsFmtV FastFormatUnicode().WriteV
 
 //////////////////////////////////////////////////////////////////////////////////////////
 // Custom internal sprintf functions, which are ASCII only (even in UNICODE builds)

 

  ViewVC Help
Powered by ViewVC 1.1.22