sources/mystring.cpp

changeset 83
08bfc3d9d2ae
parent 73
07dda51a7a8e
child 84
3bd32eec3d57
child 88
08ccaf26cffd
equal deleted inserted replaced
82:895088452014 83:08bfc3d9d2ae
29 */ 29 */
30 30
31 #include <cstring> 31 #include <cstring>
32 #include "main.h" 32 #include "main.h"
33 #include "mystring.h" 33 #include "mystring.h"
34 #include "format.h"
35 #include "md5.h" 34 #include "md5.h"
36 35
37 // ------------------------------------------------------------------------------------------------- 36 // -------------------------------------------------------------------------------------------------
38 // 37 //
39 int String::compare (const String& other) const 38 int String::compare (const String& other) const
311 return strncmp (chars(), other.chars(), other.length()) == 0; 310 return strncmp (chars(), other.chars(), other.length()) == 0;
312 } 311 }
313 312
314 // ------------------------------------------------------------------------------------------------- 313 // -------------------------------------------------------------------------------------------------
315 // 314 //
316 void String::sprintf (const char* fmtstr, ...) 315 void __cdecl String::sprintf (const char* fmtstr, ...)
316 {
317 va_list args;
318 va_start (args, fmtstr);
319 this->vsprintf (fmtstr, args);
320 va_end (args);
321 }
322
323 // -------------------------------------------------------------------------------------------------
324 //
325 void String::vsprintf (const char* fmtstr, va_list args)
317 { 326 {
318 char* buf = nullptr; 327 char* buf = nullptr;
319 int bufsize = 256; 328 int bufsize = 256;
320 va_list va;
321 va_start (va, fmtstr);
322 329
323 do 330 do
324 { 331 {
332 bufsize *= 2;
325 delete[] buf; 333 delete[] buf;
326 buf = new char[bufsize]; 334 buf = new char[bufsize];
327 } 335 }
328 while (vsnprintf (buf, bufsize, fmtstr, va) >= bufsize); 336 while (vsnprintf (buf, bufsize, fmtstr, args) >= bufsize);
329 337
330 va_end (va);
331 m_string = buf; 338 m_string = buf;
332 delete[] buf; 339 delete[] buf;
333 } 340 }
334 341
335 // ------------------------------------------------------------------------------------------------- 342 // -------------------------------------------------------------------------------------------------

mercurial