Changeset 33621 in vbox for trunk/include/VBox/com/string.h
- Timestamp:
- Oct 29, 2010 4:15:40 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 67232
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/string.h
r33073 r33621 431 431 } 432 432 433 /** 434 * Constructs a new string given the format string and the list of the 435 * arguments for the format string. 436 * 437 * @param a_pszFormat Pointer to the format string (UTF-8), 438 * @see pg_rt_str_format. 439 * @param a_va Argument vector containing the arguments 440 * specified by the format string. 441 * @sa iprt::MiniString::printfV 442 */ 443 Utf8Str(const char *a_pszFormat, va_list a_va) 444 : MiniString(a_pszFormat, a_va) 445 { 446 } 447 433 448 Utf8Str& operator=(const MiniString &that) 434 449 { … … 544 559 545 560 /** 546 * This class is a printf-like formatter for Utf8Str strings. Its purpose is 547 * to construct Utf8Str objects from a format string and a list of arguments 548 * for the format string. 549 * 550 * The usage of this class is like the following: 551 * <code> 552 * Utf8StrFmt string("program name = %s", argv[0]); 553 * </code> 561 * Class with iprt::MiniString::printf as constructor for your convenience. 562 * 563 * Constructing a Utf8Str string object from a format string and a variable 564 * number of arguments can easily be confused with the other Utf8Str 565 * constructures, thus this child class. 566 * 567 * The usage of this class is like the following: 568 * @code 569 Utf8StrFmt strName("program name = %s", argv[0]); 570 @endcode 554 571 */ 555 572 class Utf8StrFmt : public Utf8Str … … 558 575 559 576 /** 560 * Constructs a new string given the format string and the list 561 * of the arguments for the format string. 562 * 563 * @param format printf-like format string (in UTF-8 encoding) 564 * @param ... list of the arguments for the format string 565 */ 566 explicit Utf8StrFmt(const char *format, ...) 567 { 568 va_list args; 569 va_start(args, format); 570 init(format, args); 571 va_end(args); 577 * Constructs a new string given the format string and the list of the 578 * arguments for the format string. 579 * 580 * @param a_pszFormat Pointer to the format string (UTF-8), 581 * @see pg_rt_str_format. 582 * @param ... Ellipsis containing the arguments specified by 583 * the format string. 584 */ 585 explicit Utf8StrFmt(const char *a_pszFormat, ...) 586 { 587 va_list va; 588 va_start(va, a_pszFormat); 589 printfV(a_pszFormat, va); 590 va_end(va); 572 591 } 573 592 … … 576 595 { } 577 596 578 void init(const char *format, va_list args);579 580 597 private: 581 };582 583 /**584 * This class is a vprintf-like formatter for Utf8Str strings. It is585 * identical to Utf8StrFmt except that its constructor takes a va_list586 * argument instead of ellipsis.587 *588 * Note that a separate class is necessary because va_list is defined as589 * |char *| on most platforms. For this reason, if we had two overloaded590 * constructors in Utf8StrFmt (one taking ellipsis and another one taking591 * va_list) then composing a constructor call using exactly two |char *|592 * arguments would cause the compiler to use the va_list overload instead of593 * the ellipsis one which is obviously wrong. The compiler would choose594 * va_list because ellipsis has the lowest rank when it comes to resolving595 * overloads, as opposed to va_list which is an exact match for |char *|.596 */597 class Utf8StrFmtVA : public Utf8StrFmt598 {599 public:600 601 /**602 * Constructs a new string given the format string and the list603 * of the arguments for the format string.604 *605 * @param format printf-like format string (in UTF-8 encoding)606 * @param args list of arguments for the format string607 */608 Utf8StrFmtVA(const char *format, va_list args) { init(format, args); }609 598 }; 610 599 … … 627 616 va_list args; 628 617 va_start(args, aFormat); 629 copyFrom(Utf8Str FmtVA(aFormat, args).c_str());618 copyFrom(Utf8Str(aFormat, args).c_str()); 630 619 va_end(args); 631 620 } … … 633 622 634 623 /** 635 * The BstrFmtVA class is a shortcut to <tt>Bstr(Utf8Str FmtVA(...))</tt>.624 * The BstrFmtVA class is a shortcut to <tt>Bstr(Utf8Str(format,va))</tt>. 636 625 */ 637 626 class BstrFmtVA : public Bstr … … 648 637 BstrFmtVA(const char *aFormat, va_list aArgs) 649 638 { 650 copyFrom(Utf8Str FmtVA(aFormat, aArgs).c_str());639 copyFrom(Utf8Str(aFormat, aArgs).c_str()); 651 640 } 652 641 };
Note:
See TracChangeset
for help on using the changeset viewer.