⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringbuffer.h

📁 五行MMORPG引擎系统V1.0
💻 H
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#ifndef _STRINGBUFFER_H_
#define _STRINGBUFFER_H_

//Includes
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#endif

#ifndef _TVECTOR_H_
#include "core/tVector.h"
#endif

/// Utility class to wrap string manipulation in a representation
/// independent way.
///
/// Length does NOT include the null terminator.
class StringBuffer
{
	/// Chinese
//#ifdef TGE_CHINESE
//   Vector<UTF8>	mBuffer;
//#else
   Vector<UTF16>  mBuffer;
//#endif

public:
   StringBuffer() : mBuffer() 
   {
      mBuffer.push_back(0);
   };

   /// Copy constructor. Very important.
   StringBuffer(const StringBuffer &copy) : mBuffer()
   {
      set(&copy);
   };

   StringBuffer(const StringBuffer *in);
//   StringBuffer(const char *in);
   StringBuffer(const UTF8 *in);
   StringBuffer(const UTF16 *in);

   ~StringBuffer();

   void append(const StringBuffer &in);
   void insert(const U32 charOffset, const StringBuffer &in);
   StringBuffer substring(const U32 start, const U32 len) const;
   StringBuffer cut(const U32 start, const U32 len);

   const UTF16 getChar(const U32 offset) const;
   UTF16* getBuffer(const U32 offset=0) ;		/// Chinese
	
   // No setChar because even a UTF16 char might potentially involve 
   // surrogate pairs, so rather than allow broken behavior, we'll just 
   // ONLY accept substrings in mutable operations.

   void set(const StringBuffer *in);
//   void set(const char *in);
   void set(const UTF8 *in);
   void set(const UTF16 *in);

   const U32 length() const 
   { 
      return mBuffer.size() - 1; // Don't count the NULL of course.
   }

   void get(UTF8 *buff, const U32 buffSize) const;
   void get(UTF16 *buff, const U32 buffSize) const;
};


/// Chinese
//=======================================================
inline const UTF16 StringBuffer::getChar(const U32 offset) const
{
   // Allow them to grab the null terminator if they want.
   AssertFatal(offset<mBuffer.size(), "StringBuffer::getChar - outside of range.");

   return mBuffer[offset];
}

inline  UTF16* StringBuffer::getBuffer(const U32 offset) 
{
   return &mBuffer[offset];
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -