Implement Format functions using C ++

zhaozj2021-02-17  49

A few days ago, I found that it has a function of Format, I can return to the string directly, I feel very easy, I think about it, huh, I wrote a function of the same function with VC, the code is simple, only for Everyone Reference:

__inline Bool Trimright (LPTSTR D) {IF (D == Null) Return False; LPTSTR PSTR = NULL; Char * P = D; While (* P! = '/ 0') {IF (_ _istspace (* p) && PSTR == NULL) {PSTR = P;} else pstr = null; p = _tcsinc (p);} if (pstr! = Null) {* pstr = '/ 0';} return true;} __inline bool trimleft (lptstr D ) {If (d == null) returnaf false; lptstr pstr = null; char * p = d; while (* p! = '/ 0') {if (! _ USTspace (* p)) {if (pstr == NULL) {PSTR = P; Break;}} p = _tcsinc (p);} if (pstr! = Null && pstr! = D) {MoveMemory (D, PSTR, LSTRLEN (PSTR));} Return true;} Struct Fstring {Public: fString () {MEMSET (STR, 0, SIZEOF (TCHAR) * 5024);

FString (CHAR * SRC) {MEMSET (STR, 0, SIZEOF (TCHAR) * 5024); LSTRCPY (STR, SRC);}

FString (const char * src) {MEMSET (STR, 0, SIZEOF (TCHAR) * 5024); LSTRCPY (STR, SRC);}

FString (FString & SRC) {MEMSET (STR, 0, SIZEOF (TCHAR) * 5024); LSTRCPY (STR, SRC.STR);} Bool CopyFromBuffer (Pbyte PBUF, UINT NSIZE) {IF (nsize 1> 5024) Return False MEMSET (STR, 0, SIZEOF (TCHAR) * 5024); CopyMemory (STR, PBUF, NSize); STR [nsize 1] = '/ 0'; return true;} bool trimleft () {return__farfhy :: string :: Trimleft (STR);} Bool Trimright () {Return__farfhy :: String :: Trimright (STR);

Bool EmptyBuffer () {MEMSET (STR, 0, 5024); Return True;

bool ReadStrFromList (LPTSTR dst) {return __farfhy :: string :: ReadStrFromList (dst, str);} fstring & Format (LPCTSTR lpszText, ...) {va_list list; va_start (list, lpszText); memset (str, 0,5024 ); Format (LPSZTEXT, LIST); VA_END (List); return * this;} fstring & operator = (lpctstr src); fstring & operator = (char * src); fstring & operator = (const fstring s); __inline operator char * ( ); __inline operator const char * (); friend __inline fstring Format (LPCTSTR lpszText, ...); private: fstring & Format (LPTSTR lpszText, va_list & list) {memset (str, 0, sizeof (TCHAR) * 5024); vsprintf (STR, LPSZTEXT, LIST); RETURN * THIS;}

Tchar STR [5024];}; fstring :: operator char * () {return str;} fstring :: operator const char * () {return str;} __inline fstring format (lpctstr lpsztext, ...) {fstring fs; VA_LIST LIST; VA_START (LIST, LPSZTEXT); Char Teststr [5024], STR [5024]; MEMSET (STR, 0, 5024); MEMSET (Teststr, 0,5024); Sprintf (Teststr, "% S / N", Lpsztext); fs.format (teststr, list); va_end (list); returnif;

转载请注明原文地址:https://www.9cbs.com/read-28650.html

New Post(0)