yapf/str.hpp
branchcustombridgeheads
changeset 5619 a2f1d08e2215
parent 5616 0570ae953222
equal deleted inserted replaced
5618:a7db50b9f817 5619:a2f1d08e2215
     2 
     2 
     3 #ifndef  STR_HPP
     3 #ifndef  STR_HPP
     4 #define  STR_HPP
     4 #define  STR_HPP
     5 
     5 
     6 #include <errno.h>
     6 #include <errno.h>
       
     7 #include <stdarg.h>
     7 
     8 
     8 #include "blob.hpp"
     9 #include "blob.hpp"
     9 #include "strapi.hpp"
    10 #include "strapi.hpp"
    10 
    11 
    11 
    12 
    13 template <typename Tchar, bool TcaseInsensitive>
    14 template <typename Tchar, bool TcaseInsensitive>
    14 struct CStrT : public CBlobT<Tchar>
    15 struct CStrT : public CBlobT<Tchar>
    15 {
    16 {
    16 	typedef CBlobT<Tchar> base;
    17 	typedef CBlobT<Tchar> base;
    17 	typedef CStrApiT<Tchar, TcaseInsensitive> Api;
    18 	typedef CStrApiT<Tchar, TcaseInsensitive> Api;
       
    19 	typedef typename base::size_t size_t;
       
    20 	typedef typename base::OnTransfer OnTransfer;
       
    21 
    18 
    22 
    19 	FORCEINLINE CStrT(const Tchar* str = NULL) {AppendStr(str);}
    23 	FORCEINLINE CStrT(const Tchar* str = NULL) {AppendStr(str);}
    20 	FORCEINLINE CStrT(const Tchar* str, size_t num_chars) : base(str, num_chars) {FixTail();}
    24 	FORCEINLINE CStrT(const Tchar* str, size_t num_chars) : base(str, num_chars) {base::FixTail();}
    21 	FORCEINLINE CStrT(const Tchar* str, const Tchar* end) : base(str, end - str) {FixTail();}
    25 	FORCEINLINE CStrT(const Tchar* str, const Tchar* end) : base(str, end - str) {base::FixTail();}
    22 	FORCEINLINE CStrT(const CBlobBaseSimple& src) : base(src) {FixTail();}
    26 	FORCEINLINE CStrT(const CBlobBaseSimple& src) : base(src) {base::FixTail();}
    23 	/** Take ownership constructor */
    27 	/** Take ownership constructor */
    24 	FORCEINLINE CStrT(OnTransfer& ot) : base(ot) {}
    28 	FORCEINLINE CStrT(const OnTransfer& ot) : base(ot) {}
    25 	FORCEINLINE Titem* GrowSizeNC(size_t count) {Titem* ret = base::GrowSizeNC(count); FixTail(); return ret;}
    29 	FORCEINLINE Tchar* GrowSizeNC(size_t count) {Tchar* ret = base::GrowSizeNC(count); base::FixTail(); return ret;}
    26 	FORCEINLINE void AppendStr(const Tchar* str) {if (str != NULL && str[0] != '\0') base::Append(str, (size_t)Api::StrLen(str)); FixTail();}
    30 	FORCEINLINE void AppendStr(const Tchar* str) {if (str != NULL && str[0] != '\0') base::Append(str, (size_t)Api::StrLen(str)); base::FixTail();}
    27 	FORCEINLINE CStrT& operator = (const Tchar* src) {Clear(); Append(src); return *this;}
    31 	FORCEINLINE CStrT& operator = (const Tchar* src) {base::Clear(); Append(src); return *this;}
    28 	FORCEINLINE bool operator < (const CStrT &other) const {return (Api::StrCmp(Data(), other.Data()) < 0);}
    32 	FORCEINLINE bool operator < (const CStrT &other) const {return (Api::StrCmp(base::Data(), other.Data()) < 0);}
    29 
    33 
    30 	int FormatL(const Tchar *fmt, va_list args)
    34 	int FormatL(const Tchar *fmt, va_list args)
    31 	{
    35 	{
    32 		size_t addSize = Api::StrLen(fmt);
    36 		size_t addSize = Api::StrLen(fmt);
    33 		if (addSize < 16) addSize = 16;
    37 		if (addSize < 16) addSize = 16;
    34 		addSize += addSize > 1;
    38 		addSize += addSize > 1;
    35 		int ret;
    39 		int ret;
    36 		do {
    40 		do {
    37 			Tchar *buf = MakeFreeSpace(addSize);
    41 			Tchar *buf = MakeFreeSpace(addSize);
    38 			ret = Api::SPrintFL(buf, GetReserve(), fmt, args);
    42 			ret = Api::SPrintFL(buf, base::GetReserve(), fmt, args);
    39 			addSize *= 2;
    43 			addSize *= 2;
    40 		} while(ret < 0 && (errno == ERANGE || errno == 0));
    44 		} while(ret < 0 && (errno == ERANGE || errno == 0));
    41 		if (ret > 0) {
    45 		if (ret > 0) {
    42 			GrowSizeNC(ret);
    46 			GrowSizeNC(ret);
    43 		} else {
    47 		} else {
    44 			int err = errno;
    48 //			int err = errno;
    45 			FixTail();
    49 			base::FixTail();
    46 		}
    50 		}
    47 		return ret;
    51 		return ret;
    48 	}
    52 	}
    49 
    53 
    50 	int Format(const Tchar *format, ...)
    54 	int Format(const Tchar *format, ...)