/[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

revision 31 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 16  Line 16 
16  #pragma once  #pragma once
17    
18  #include "Dependencies.h"  #include "Dependencies.h"
19    #include "SafeArray.h"
20    
21  #include <wx/tokenzr.h>  #include <wx/tokenzr.h>
22  #include <wx/gdicmn.h>          // for wxPoint/wxRect stuff  
23    
24    // --------------------------------------------------------------------------------------
25    //  pxToUTF8
26    // --------------------------------------------------------------------------------------
27    // Converts a string to UTF8 and provides an interface for getting its length.
28    class pxToUTF8
29    {
30            DeclareNoncopyableObject( pxToUTF8 );
31    
32    protected:
33            wxCharBuffer    m_result;
34            int                             m_length;
35    
36    public:
37            explicit pxToUTF8(const wxString& src)
38                    : m_result( src.ToUTF8() )
39            {
40                    m_length = -1;
41            }
42    
43            size_t Length()
44            {
45                    if( -1 == m_length )
46                            m_length = strlen( m_result );
47                    return m_length;
48            }
49    
50            void Convert( const wxString& src )
51            {
52                    m_result = src.ToUTF8();
53                    m_length = -1;
54            }
55            
56            const char* data() const { return m_result; }
57            
58            operator const char*() const
59            {
60                    return m_result.data();
61            }
62    };
63    
64  extern void px_fputs( FILE* fp, const char* src );  extern void px_fputs( FILE* fp, const char* src );
65    
# Line 29  extern wxString fromAscii( const char* s Line 70  extern wxString fromAscii( const char* s
70  extern const wxRect wxDefaultRect;  extern const wxRect wxDefaultRect;
71    
72  extern void SplitString( wxArrayString& dest, const wxString& src, const wxString& delims, wxStringTokenizerMode mode = wxTOKEN_RET_EMPTY_ALL );  extern void SplitString( wxArrayString& dest, const wxString& src, const wxString& delims, wxStringTokenizerMode mode = wxTOKEN_RET_EMPTY_ALL );
73  extern void JoinString( wxString& dest, const wxArrayString& src, const wxString& separator );  extern wxString JoinString( const wxArrayString& src, const wxString& separator );
74    extern wxString JoinString( const wxChar** src, const wxString& separator );
75    
76  extern wxString ToString( const wxPoint& src, const wxString& separator=L"," );  extern wxString ToString( const wxPoint& src, const wxString& separator=L"," );
77  extern wxString ToString( const wxSize& src, const wxString& separator=L"," );  extern wxString ToString( const wxSize& src, const wxString& separator=L"," );
# Line 65  struct ParsedAssignmentString Line 107  struct ParsedAssignmentString
107          ParsedAssignmentString( const wxString& src );          ParsedAssignmentString( const wxString& src );
108  };  };
109    
110  extern wxString FastFormatString_Ascii(const char* fmt, va_list argptr);  // --------------------------------------------------------------------------------------
111  extern wxString FastFormatString_Unicode(const wxChar* fmt, va_list argptr);  //  FastFormatAscii
112    // --------------------------------------------------------------------------------------
113    // Fast formatting of ASCII text.  This class uses a process-wide format buffer that is
114    // allocated only once and grown to accommodate string formatting needs.  The buffer is
115    // thread-safe.  This technique reduces the overhead of formatting strings by eliminating
116    // most or all heap allocation actions.
117    //
118    class FastFormatAscii
119    {
120    protected:
121            SafeArray<char>*        m_dest;
122            bool                            m_deleteDest;
123            
124    public:
125            FastFormatAscii();
126            ~FastFormatAscii() throw();
127            FastFormatAscii& Write( const char* fmt, ... );
128            FastFormatAscii& WriteV( const char* fmt, va_list argptr );
129    
130            bool IsEmpty() const;
131    
132            const char* c_str() const               { return m_dest->GetPtr(); }
133            operator const char*() const    { return m_dest->GetPtr(); }
134    
135            const wxString GetString() const;
136            //operator wxString() const;
137    };
138    
139    class FastFormatUnicode
140    {
141    protected:
142            SafeArray<char>*        m_dest;
143            bool                            m_deleteDest;
144    
145    public:
146            FastFormatUnicode();
147            ~FastFormatUnicode() throw();
148    
149            FastFormatUnicode& Write( const char* fmt, ... );
150            FastFormatUnicode& Write( const wxChar* fmt, ... );
151            FastFormatUnicode& WriteV( const char* fmt, va_list argptr );
152            FastFormatUnicode& WriteV( const wxChar* fmt, va_list argptr );
153    
154            bool IsEmpty() const;
155    
156            const wxChar* c_str() const             { return (const wxChar*)m_dest->GetPtr(); }
157            operator const wxChar*() const  { return (const wxChar*)m_dest->GetPtr(); }
158            operator wxString() const               { return (const wxChar*)m_dest->GetPtr(); }
159    };
160    
161    extern bool pxParseAssignmentString( const wxString& src, wxString& ldest, wxString& rdest );
162    
163    #define pxsFmt FastFormatUnicode().Write
164    #define pxsFmtV FastFormatUnicode().WriteV
165    
166  //////////////////////////////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////////////////////////////
167  // Custom internal sprintf functions, which are ASCII only (even in UNICODE builds)  // Custom internal sprintf functions, which are ASCII only (even in UNICODE builds)

Legend:
Removed from v.31  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22