| 509 | | * @param args list of arguments for the format string |
|---|
| 510 | | */ |
|---|
| 511 | | explicit Utf8StrFmt (const char *format, va_list args) { init (format, args); } |
|---|
| | 509 | * @param ... list of the arguments for the format string |
|---|
| | 510 | */ |
|---|
| | 511 | explicit Utf8StrFmt (const char *format, ...) |
|---|
| | 512 | { |
|---|
| | 513 | va_list args; |
|---|
| | 514 | va_start (args, format); |
|---|
| | 515 | init (format, args); |
|---|
| | 516 | va_end (args); |
|---|
| | 517 | } |
|---|
| | 518 | |
|---|
| | 519 | protected: |
|---|
| | 520 | |
|---|
| | 521 | Utf8StrFmt() {} |
|---|
| | 522 | |
|---|
| | 523 | void init (const char *format, va_list args); |
|---|
| | 524 | |
|---|
| | 525 | private: |
|---|
| | 526 | |
|---|
| | 527 | static DECLCALLBACK(size_t) strOutput (void *pvArg, const char *pachChars, |
|---|
| | 528 | size_t cbChars); |
|---|
| | 529 | }; |
|---|
| | 530 | |
|---|
| | 531 | /** |
|---|
| | 532 | * This class is a vprintf-like formatter for Utf8Str strings. It is |
|---|
| | 533 | * identical to Utf8StrFmt except that its constructor takes a va_list |
|---|
| | 534 | * argument instead of ellipsis. |
|---|
| | 535 | * |
|---|
| | 536 | * Note that a separate class is necessary because va_list is defined as |
|---|
| | 537 | * |char *| on most platforms. For this reason, if we had two overloaded |
|---|
| | 538 | * constructors in Utf8StrFmt (one taking ellipsis and another one taking |
|---|
| | 539 | * va_list) then composing a constructor call using exactly two |char *| |
|---|
| | 540 | * arguments would cause the compiler to use the va_list overload instead of |
|---|
| | 541 | * the ellipsis one which is obviously wrong. The compiler would choose |
|---|
| | 542 | * va_list because ellipsis has the lowest rank when it comes to resolving |
|---|
| | 543 | * overloads, as opposed to va_list which is an exact match for |char *|. |
|---|
| | 544 | */ |
|---|
| | 545 | class Utf8StrFmtVA : public Utf8StrFmt |
|---|
| | 546 | { |
|---|
| | 547 | public: |
|---|
| 518 | | * @param ... list of the arguments for the format string |
|---|
| 519 | | * |
|---|
| 520 | | * @note Be extremely careful when passing exactly one argument in the |
|---|
| 521 | | * ellipsis. If this is a string the C++ could decide to use the |
|---|
| 522 | | * other constructor since va_list is defined as char * on some |
|---|
| 523 | | * platforms. If unsure, add an extra dummy argument. |
|---|
| 524 | | */ |
|---|
| 525 | | explicit Utf8StrFmt (const char *format, ...) |
|---|
| 526 | | { |
|---|
| 527 | | va_list args; |
|---|
| 528 | | va_start (args, format); |
|---|
| 529 | | init (format, args); |
|---|
| 530 | | va_end (args); |
|---|
| 531 | | } |
|---|
| 532 | | |
|---|
| 533 | | private: |
|---|
| 534 | | |
|---|
| 535 | | void init (const char *format, va_list args); |
|---|
| 536 | | |
|---|
| 537 | | static DECLCALLBACK(size_t) strOutput (void *pvArg, const char *pachChars, |
|---|
| 538 | | size_t cbChars); |
|---|
| | 554 | * @param args list of arguments for the format string |
|---|
| | 555 | */ |
|---|
| | 556 | Utf8StrFmtVA (const char *format, va_list args) { init (format, args); } |
|---|