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

📄 tc3d_string.h

📁 自己写的一些基本的3d引擎的基础的代码
💻 H
📖 第 1 页 / 共 2 页
字号:
					}

					i++;

					TC3D_F32 mul = 0.1f;
					for(; i < tSize; i++)
					{
						if(!MC3D_IS_DIGIT(TC3D_Array<T>::operator[](i)))
							break;
						resFloat += (TC3D_F32)((TC3D_Array<T, TAlloc>::operator [] (i) - '0') * mul);
						mul *= 0.1f;
					}

					indexOut = i;

					TC3D_F32 temp = (TC3D_F32)resInt;
					resFloat += temp;

					return negate ? -resFloat : resFloat;
				}

				/** Gets the size of the string */
				virtual TC3D_U32 Size() const
				{
					return tSize;
				}

				/** Checks if the string is empty */
				virtual TC3D_Bool Empty() const
				{
					return (tSize == 0);
				}

				/** Inserts to a string at any point */
				virtual void Insert(const CC3D_Iterator &destBegin, const CC3D_Iterator &srcBegin, const CC3D_Iterator &srcEnd)
				{
					if(srcEnd <= srcBegin)
						return;	

					for(CC3D_Iterator it = srcBegin; it < srcEnd; it++)
						TC3D_Array<T, TAlloc>::Insert(destBegin.tData, *it);

					tSize += (srcEnd - srcBegin);
				}

				/** Reverses the string */
				virtual TC3D_String<T, TAlloc> &Reverse()
				{
					return Reverse(0, tSize);
				}

				/** Reverses the string */
				virtual TC3D_String<T, TAlloc> &Reverse(TC3D_U32 index, TC3D_U32 size)
				{
					if(!size)
						return *this;

					for(TC3D_U32 i = 0; i < size / 2; i++)
					{
						T temp = TC3D_Array<T, TAlloc>::operator [](index + i);
						TC3D_Array<T, TAlloc>::operator [](index + i) =
							TC3D_Array<T, TAlloc>::operator [](index + (size - 1 - i));
						TC3D_Array<T, TAlloc>::operator [](index + (size - 1 - i)) = temp;
					}

					return *this;
				}

				/** Appends to the end of the string */
				virtual TC3D_String<T, TAlloc> &Append(TC3D_S32 integer)
				{
					T c;


					TC3D_S32 i = 0;
					TC3D_S32 index = tSize;
					while(integer)
					{
						c = (integer % 10) + (T)'0';
						Append(1, c);
						integer /= 10;
						i++;
					}

					Reverse(index, i);
					return *this;
				}

				/** Appends to the end of the string */
				virtual TC3D_String<T, TAlloc> &Append(const TC3D_String<T, TAlloc> &src)
				{
					return Append(src, 0, src.Size());
				}

				/** Appends to the end of the string */
				virtual TC3D_String<T, TAlloc> &Append(const TC3D_String<T, TAlloc> &src, TC3D_U32 index, TC3D_U32 len)
				{
					if(!len)
						return *this;

					if(TC3D_Array<T, TAlloc>::Size())
						TC3D_Array<T, TAlloc>::Erase(TC3D_Array<T, TAlloc>::End() - 1, TC3D_Array<T, TAlloc>::End());

					TC3D_U32 i;
					for(i = 0; i < len; i++)
					{
						if(!src[i])
							break;
						TC3D_Array<T, TAlloc>::Push_Back(src[index + i]);
					}
					TC3D_Array<T, TAlloc>::Push_Back('\0');

					tSize += i;

					return *this;
				}

				/** Appends to the end of the string */
				virtual TC3D_String<T, TAlloc> &Append(const T *str)
				{
					return Append(str, Get_Length(str));
				}

				/** Appends to the end of the string */
				virtual TC3D_String<T, TAlloc> &Append(const T *str, TC3D_U32 num)
				{
					if(!str || !*str || !num)
						return *this;

					if(TC3D_Array<T, TAlloc>::Size())
						TC3D_Array<T, TAlloc>::Erase(TC3D_Array<T, TAlloc>::End() - 1, TC3D_Array<T, TAlloc>::End());

					TC3D_U32 i;
					for(i = 0; i < num; i++)
					{
						if(!str[i])
							break;
						TC3D_Array<T, TAlloc>::Push_Back(str[i]);
					}
					TC3D_Array<T, TAlloc>::Push_Back('\0');

					tSize += i;

					return *this;
				}

				/** Appends to the end of the string */
				virtual TC3D_String<T, TAlloc> &Append(TC3D_U32 num, const T &c)
				{
					if(!num)
						return *this;

					if(TC3D_Array<T, TAlloc>::Size())
						TC3D_Array<T, TAlloc>::Erase(TC3D_Array<T, TAlloc>::End() - 1, TC3D_Array<T, TAlloc>::End());

					for(TC3D_U32 i = 0; i < num; i++)
						TC3D_Array<T, TAlloc>::Push_Back(c);
					TC3D_Array<T, TAlloc>::Push_Back('\0');

					tSize += num;

					return *this;
				}

				/** Appends to the end of the string */
				virtual TC3D_String<T, TAlloc> &Append(const CC3D_Iterator &srcBegin, const CC3D_Iterator &srcEnd)
				{
					if(srcEnd <= srcBegin)
						return *this;

					if(TC3D_Array<T, TAlloc>::Size())
						TC3D_Array<T, TAlloc>::Erase(TC3D_Array<T, TAlloc>::End() - 1, TC3D_Array<T, TAlloc>::End());

					for(CC3D_Iterator it = srcBegin; it < srcEnd; it++)
						TC3D_Array<T, TAlloc>::Push_Back(*it);
					TC3D_Array<T, TAlloc>::Push_Back('\0');

					tSize += (srcEnd - srcBegin);

					return *this;
				}

				/** Compares two strings */
				virtual TC3D_S32 Compare(const TC3D_String<T, TAlloc> &src) const
				{
					return Compare(0, tSize, src);
				}

				/** Compares two strings */
				virtual TC3D_S32 Compare(const T *str) const
				{
					return Compare(0, tSize, str, Get_Length(str));
				}

				/** Compares two strings */
				virtual TC3D_S32 Compare(TC3D_U32 thisIndex, TC3D_U32 thisLen, const TC3D_String<T, TAlloc> &src) const
				{
					return Compare(thisIndex, thisLen, src, 0, src.Size());
				}

				/** Compares two strings */
				virtual TC3D_S32 Compare(TC3D_U32 thisIndex, TC3D_U32 thisLen, 
					const TC3D_String<T, TAlloc> &src, TC3D_U32 thatIndex, TC3D_U32 thatLen) const
				{
					if(thisLen > thatLen)
						return 1;
					if(thisLen < thatLen)
						return -1;

					for(TC3D_U32 i = 0; i < thisLen; i++)
					{
						if(TC3D_Array<T, TAlloc>::operator [](thisIndex + i) > src[thatIndex + i])
							return 1;
						if(TC3D_Array<T, TAlloc>::operator [](thisIndex + i) < src[thatIndex + i])
							return -1;
					}

					return 0;
				}

				/** Compares two strings */
				virtual TC3D_S32 Compare(const T *str, TC3D_U32 thatLen)
				{
					return Compare(0, tSize, str, thatLen);
				}

				/** Compares two strings */
				virtual TC3D_S32 Compare(TC3D_U32 thisIndex, TC3D_U32 thisLen, const T *str) const
				{
					return Compare(thisIndex, thisLen, str, Get_Length(str));
				}

				/** Compares two strings */
				virtual TC3D_S32 Compare(TC3D_U32 thisIndex, TC3D_U32 thisLen, const T *str, TC3D_U32 thatLen) const
				{
					if(thisLen > thatLen)
						return 1;
					if(thisLen < thatLen)
						return -1;

					for(TC3D_U32 i = 0; i < thisLen; i++)
					{
						if(TC3D_Array<T, TAlloc>::operator [](thisIndex + i) > str[i])
							return 1;
						if(TC3D_Array<T, TAlloc>::operator [](thisIndex + i) < str[i])
							return -1;
					}

					return 0;
				}

				/** Converts to upper-case */
				virtual TC3D_String<T, TAlloc> To_Upper() const
				{
					return To_Upper(0, tSize);
				}

				/** Converts to upper-case */
				virtual TC3D_String<T, TAlloc> To_Upper(TC3D_U32 index, TC3D_U32 size) const
				{
					TC3D_String<T, TAlloc> temp(*this);
					for(TC3D_U32 i = 0; i < size; i++)
					{
						if(temp[i] >= 'a' && temp[i] <= 'z')
							temp[i] = (temp[i] - 'a') + 'A';
					}
					return temp;
				}

				/** String assignment */
				virtual TC3D_String<T, TAlloc> &operator = (const TC3D_String<T, TAlloc> &src)
				{
					if(this != &src)
					{
						Clear();
						Append(src);
					}
					return *this;
				}

				/** String assignment */
				virtual TC3D_String<T, TAlloc> &operator = (const T *str)
				{
					Clear();
					Append(str);						
					return *this;
				}

				/** String indexing */
				virtual T &operator [] (TC3D_U32 index) const
				{
					return TC3D_Array<T, TAlloc>::operator [](index);
				}

				/** Concatenate and assignment */
				virtual TC3D_String<T, TAlloc> &operator += (const TC3D_String<T, TAlloc> &src)
				{
					Append(src);
					return *this;
				}

				/** Concatenate and assignment */
				virtual TC3D_String<T, TAlloc> &operator += (const T *str)
				{
					Append(str);
					return *this;
				}

				/** Concatenate strings */
				virtual TC3D_String<T, TAlloc> operator + (const TC3D_String<T, TAlloc> &src) const
				{
					TC3D_String<T, TAlloc> temp(*this);
					temp.Append(src);
					return temp;
				}

				/** Concatenate strings */
				virtual TC3D_String<T, TAlloc> operator + (const T *str) const
				{
					TC3D_String<T, TAlloc> temp(*this);
					temp.Append(str);
					return temp;
				}

				/** Comparison operator */
				virtual TC3D_Bool operator == (const T *str) const
				{
					return (Compare(str) == 0);
				}

				/** Comparison operator */
				virtual TC3D_Bool operator != (const T *str) const
				{
					return (Compare(str) != 0);
				}

				/** Comparison operator */
				virtual TC3D_Bool operator == (const TC3D_String<T, TAlloc> &src) const
				{
					return (Compare(src) == 0);
				}

				/** Comparison operator */
				virtual TC3D_Bool operator != (const TC3D_String<T, TAlloc> &src) const
				{
					return (Compare(src) != 0);
				}

				/** Comparison operator */
				virtual TC3D_Bool operator > (const TC3D_String<T, TAlloc> &src) const
				{
					return (Compare(src) > 0);
				}

				/** Comparison operator */
				virtual TC3D_Bool operator < (const TC3D_String<T, TAlloc> &src) const
				{
					return (Compare(src) < 0);
				}

				/** Comparison operator */
				virtual TC3D_Bool operator <= (const TC3D_String<T, TAlloc> &src) const
				{
					return (Compare(src) <= 0);
				}

				/** Comparison operator */
				virtual TC3D_Bool operator >= (const TC3D_String<T, TAlloc> &src) const
				{
					return (Compare(src) >= 0);
				}
		};

		typedef TC3D_String<TC3D_AC> TC3D_StringA;	// Ascii string
		typedef TC3D_String<TC3D_WC> TC3D_StringW;	// Wide string

		const TC3D_StringA		CC3D_EmptyStringA = TC3D_StringA("");
		const TC3D_StringW		CC3D_EmptyStringW = TC3D_StringW((CPC3D_WC)"");

		DC3D_INLINE TC3D_Void __C3D_String_A_To_W(const TC3D_StringA &src, TC3D_StringW &dest)
		{
			dest.Clear();

			for(TC3D_U32 i = 0; i < src.Size(); i++)
				dest.Append(1, (TC3D_WC)(src[i]));
		}
	};
};

#endif

⌨️ 快捷键说明

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