ランタイム
String.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <vector>
7 
8 namespace Mix
9 {
13  {
14  private:
15  enum { VA_TEMP_NUM = 2048 };
16  static wchar_t empty;
17 
18  private:
19  wchar_t* m_pStr; //文字列
20  UIntT m_Num; //文字数
21  UIntT m_Size; //NULLを含む文字列のサイズ(バイト単位)
22  UIntT m_AllocateSize; //NULLを含まない文字列のサイズ(バイト単位)
23  UIntT m_Capacity; //キャパシティ(バイト単位)
24 
25  private:
26  void Allocate( UIntT num );
27  void Copy( const wchar_t* pStr );
28  void Copy( const wchar_t* pStr, UIntT num );
29  void Convert( const char* pStr );
30  void Add( const wchar_t* pStr );
31 
32  public:
34  StringW( void );
37  StringW( const char* pStr );
40  StringW( const wchar_t* pStr );
44  StringW( const wchar_t* pStr, UIntT sizeInWords );
47  StringW( const StringW& str );
49  ~StringW( void );
50 
54  wchar_t& operator [] ( UIntT index );
58  Boolean operator == ( const StringW& str ) const;
62  Boolean operator == ( const wchar_t* pStr ) const;
66  Boolean operator == ( wchar_t code ) const;
70  Boolean operator == ( UIntT nullValue ) const;
74  Boolean operator != ( const StringW& str ) const;
78  Boolean operator != ( const wchar_t* pStr ) const;
82  Boolean operator != ( UIntT nullValue ) const;
86  StringW& operator = ( const StringW& str );
90  StringW& operator = ( const wchar_t* pStr );
94  StringW& operator = ( const char* pStr );
98  StringW& operator = ( const wchar_t code );
102  StringW& operator = ( UIntT nullValue );
106  StringW& operator += ( const wchar_t* pStr );
110  StringW& operator += ( const StringW& str );
114  StringW& operator += ( const wchar_t code );
118  StringW operator + ( const StringW& str );
123  friend const StringW operator + ( const wchar_t* ls, const StringW& rs )
124  {
125  StringW tmp( ls );
126  tmp.Add( rs.m_pStr );
127 
128  return tmp;
129  }
130 
135  friend bool operator < ( const StringW& l, const StringW& r )
136  {
137  return ( ::wcscmp( l.m_pStr, r.m_pStr ) < 0 );
138  }
143  friend bool operator > ( const StringW& l, const StringW& r )
144  {
145  return ( ::wcscmp( l.m_pStr, r.m_pStr ) > 0 );
146  }
151  friend bool operator <= ( const StringW& l, const StringW& r )
152  {
153  return ( ::wcscmp( l.m_pStr, r.m_pStr ) <= 0 );
154  }
159  friend bool operator >= ( const StringW& l, const StringW& r )
160  {
161  return ( ::wcscmp( l.m_pStr, r.m_pStr ) >= 0 );
162  }
163 
169  Float64 ToDouble( Boolean* pbRet = NULL ) const;
175  Float32 ToFloat( Boolean* pbRet = NULL ) const;
181  Int32 ToInt( Boolean* pbRet = NULL ) const;
187  UInt32 ToUInt( Boolean* pbRet = NULL ) const;
188 
191  StringW ToUpper( void );
194  StringW ToLower( void );
195 
197  void Upper( void );
199  void Lower( void );
200 
205  wchar_t* Sprintf( const wchar_t* format, ... );
206 
210  StringW Left( UIntT sizeInWords );
214  StringW Right( UIntT sizeInWords );
219  StringW Mid( UIntT startPos, UIntT sizeInWords );
220 
224  UIntT IndexOf( wchar_t value );
228  UIntT LastIndexOf( wchar_t value );
229 
233  template<Mix::Memory::SECTION_TYPE ST>
234  void Split( const wchar_t* pSeparator, std::vector<Mix::StringW, std::vector<Mix::StringW, Mix::Memory::STLAllocator<ST, Mix::StringW>>>& list )
235  {
236  MIX_ASSERT( pSeparator != NULL );
237 
238  Mix::StringW tmpStr( m_pStr );
239 
240  wchar_t* pCtx = NULL;
241  wchar_t* pPart = wcstok_s( tmpStr.m_pStr, pSeparator, &pCtx );
242 
243  while( pt != NULL )
244  {
245  list.push_back( Mix::StringW( pPart ) );
246  pPart = wcstok_s( NULL, pSeparator, &pCtx );
247  }
248  }
249 
252  wchar_t* GetPtr( void ) const;
255  const wchar_t* GetConstPtr( void ) const;
258  UIntT GetNum( void ) const;
261  UIntT GetSize( void ) const;
264  UIntT GetAllocateSize( void ) const;
267  UIntT GetCapacity( void ) const;
268  };
269 
270 
274  {
275  private:
276  enum { VA_TEMP_NUM = 2048 };
277  static char empty;
278 
279  private:
280  char* m_pStr;
281  UIntT m_Num;
282  UIntT m_Size;
283  UIntT m_AllocateSize;
284  UIntT m_Capacity;
285 
286  private:
287  void Allocate( UIntT num );
288  void Copy( const char* pStr );
289  void Copy( const char* pStr, UIntT num );
290  void Convert( const wchar_t* pStr );
291  void Add( const char* pStr );
292  UIntT CalcStrNum( const char* pStr );
293 
294  public:
296  StringA( void );
299  StringA( const wchar_t* pStr );
302  StringA( const char* pStr );
306  StringA( const char* pStr, UIntT size );
309  StringA( const StringA& str );
311  ~StringA( void );
312 
316  char& operator [] ( UIntT index );
320  Boolean operator == ( const StringA& str ) const;
324  Boolean operator == ( const char* pStr ) const;
328  Boolean operator == ( char code ) const;
332  Boolean operator == ( UIntT nullValue ) const;
336  Boolean operator != ( const StringA& str ) const;
340  Boolean operator != ( const char* pStr ) const;
344  Boolean operator != ( UIntT nullValue ) const;
348  StringA& operator = ( const StringA& str );
352  StringA& operator = ( const char* pStr );
356  StringA& operator = ( const wchar_t* pStr );
360  StringA& operator = ( char code );
364  StringA& operator += ( const char* pStr );
368  StringA& operator += ( const StringA& str );
372  StringA& operator += ( char code );
376  StringA operator + ( const StringA& str );
381  friend const StringA operator + ( const char* ls, const StringA& rs )
382  {
383  StringA tmp( ls );
384  tmp.Add( rs.m_pStr );
385 
386  return tmp;
387  }
388 
393  friend bool operator < ( const StringA& l, const StringA& r )
394  {
395  return ( ::strcmp( l.m_pStr, r.m_pStr ) < 0 );
396  }
401  friend bool operator > ( const StringA& l, const StringA& r )
402  {
403  return ( ::strcmp( l.m_pStr, r.m_pStr ) > 0 );
404  }
409  friend bool operator <= ( const StringA& l, const StringA& r )
410  {
411  return ( ::strcmp( l.m_pStr, r.m_pStr ) <= 0 );
412  }
417  friend bool operator >= ( const StringA& l, const StringA& r )
418  {
419  return ( ::strcmp( l.m_pStr, r.m_pStr ) >= 0 );
420  }
421 
427  Float64 ToDouble( Boolean* pbRet = NULL ) const;
433  Float32 ToFloat( Boolean* pbRet = NULL ) const;
439  Int32 ToInt( Boolean* pbRet = NULL ) const;
445  UInt32 ToUInt( Boolean* pbRet = NULL ) const;
446 
449  StringA ToUpper( void );
452  StringA ToLower( void );
453 
455  void Upper( void );
457  void Lower( void );
458 
463  char* Sprintf( const char* format, ... );
467  StringA Left( UIntT size );
471  StringA Right( UIntT size );
476  StringA Mid( UIntT startPos, UIntT size );
477 
481  UIntT IndexOf( char value );
485  UIntT LastIndexOf( char value );
486 
490  template<Mix::Memory::SECTION_TYPE ST>
491  void Split( const char* pSeparator, std::vector<Mix::StringA, std::vector<Mix::StringA, Mix::Memory::STLAllocator<ST, Mix::StringA>>>& list )
492  {
493  MIX_ASSERT( pSeparator != NULL );
494 
495  Mix::StringA tmpStr( m_pStr );
496 
497  char* pCtx = NULL;
498  char* pPart = strtok_s( tmpStr.m_pStr, pSeparator, &pCtx );
499 
500  while( pPart != NULL )
501  {
502  list.push_back( Mix::StringA( pPart ) );
503  pPart = strtok_s( NULL, pSeparator, &pCtx );
504  }
505  }
506 
509  char* GetPtr( void ) const;
512  const char* GetConstPtr( void ) const;
515  UIntT GetNum( void ) const;
518  UIntT GetSize( void ) const;
521  UIntT GetAllocateSize( void ) const;
524  UIntT GetCapacity( void ) const;
525  };
526 
529  typedef StringW String;
530 
533  typedef std::vector<Mix::StringA, Mix::Memory::STLAllocator<Mix::Memory::SECTION_GENERAL, Mix::StringA>> StringListA;
536  typedef std::vector<Mix::StringW, Mix::Memory::STLAllocator<Mix::Memory::SECTION_GENERAL, Mix::StringW>> StringListW;
537 
540  typedef StringListW StringList;
541 };
_MIX_DLL_API void * Allocate(UInt16 section, UIntT size, const wchar_t *pSrcFile, Int32 srcLine)
メモリを確保します
size_t UIntT
符号無し整数
Definition: Common.h:98
文字列クラス( マルチバイト )
Definition: String.h:273
int Int32
符号有り32ビット整数
Definition: Common.h:65
unsigned int UInt32
符号無し32ビット整数
Definition: Common.h:68
STL アロケータテンプレートクラス
Definition: Common.h:592
StringListW StringList
文字列リスト
Definition: String.h:540
文字列クラス( ユニコード )
Definition: String.h:12
std::vector< Mix::StringA, Mix::Memory::STLAllocator< Mix::Memory::SECTION_GENERAL, Mix::StringA > > StringListA
マルチバイト文字列リスト
Definition: String.h:533
ミックス
Definition: AtomicValue.h:6
double Float64
64ビット浮動小数点
Definition: Common.h:86
float Float32
32ビット浮動小数点
Definition: Common.h:83
void Split(const char *pSeparator, std::vector< Mix::StringA, std::vector< Mix::StringA, Mix::Memory::STLAllocator< ST, Mix::StringA >>> &list)
指定したセパレータで文字列を分割します
Definition: String.h:491
void Split(const wchar_t *pSeparator, std::vector< Mix::StringW, std::vector< Mix::StringW, Mix::Memory::STLAllocator< ST, Mix::StringW >>> &list)
指定したセパレータで文字列を分割します
Definition: String.h:234
BOOL Boolean
32ビットブーリアン
Definition: Common.h:102
std::vector< Mix::StringW, Mix::Memory::STLAllocator< Mix::Memory::SECTION_GENERAL, Mix::StringW > > StringListW
ワイド文字列リスト
Definition: String.h:536
#define MIX_ASSERT(cnd)
標準のアサート
Definition: Common.h:120
_MIX_DLL_API void Copy(void *dst, const void *src, UIntT size)
メモリをコピーします
#define _MIX_DLL_API
DLLインポート定義
Definition: Common.h:38
StringW String
文字列
Definition: String.h:529