VirtualBox

Changeset 33621 in vbox for trunk/include/VBox/com/string.h


Ignore:
Timestamp:
Oct 29, 2010 4:15:40 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67232
Message:

Utf8Str: Use printfV in Utf8StrFmt, eliminated Utf8StrFmtVA by replacing it by a Utf8Str(str,va) constructor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/string.h

    r33073 r33621  
    431431    }
    432432
     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
    433448    Utf8Str& operator=(const MiniString &that)
    434449    {
     
    544559
    545560/**
    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
    554571 */
    555572class Utf8StrFmt : public Utf8Str
     
    558575
    559576    /**
    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);
    572591    }
    573592
     
    576595    { }
    577596
    578     void init(const char *format, va_list args);
    579 
    580597private:
    581 };
    582 
    583 /**
    584  *  This class is a vprintf-like formatter for Utf8Str strings. It is
    585  *  identical to Utf8StrFmt except that its constructor takes a va_list
    586  *  argument instead of ellipsis.
    587  *
    588  *  Note that a separate class is necessary because va_list is defined as
    589  *  |char *| on most platforms. For this reason, if we had two overloaded
    590  *  constructors in Utf8StrFmt (one taking ellipsis and another one taking
    591  *  va_list) then composing a constructor call using exactly two |char *|
    592  *  arguments would cause the compiler to use the va_list overload instead of
    593  *  the ellipsis one which is obviously wrong. The compiler would choose
    594  *  va_list because ellipsis has the lowest rank when it comes to resolving
    595  *  overloads, as opposed to va_list which is an exact match for |char *|.
    596  */
    597 class Utf8StrFmtVA : public Utf8StrFmt
    598 {
    599 public:
    600 
    601     /**
    602      *  Constructs a new string given the format string and the list
    603      *  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 string
    607      */
    608     Utf8StrFmtVA(const char *format, va_list args) { init(format, args); }
    609598};
    610599
     
    627616        va_list args;
    628617        va_start(args, aFormat);
    629         copyFrom(Utf8StrFmtVA(aFormat, args).c_str());
     618        copyFrom(Utf8Str(aFormat, args).c_str());
    630619        va_end(args);
    631620    }
     
    633622
    634623/**
    635  * The BstrFmtVA class is a shortcut to <tt>Bstr(Utf8StrFmtVA(...))</tt>.
     624 * The BstrFmtVA class is a shortcut to <tt>Bstr(Utf8Str(format,va))</tt>.
    636625 */
    637626class BstrFmtVA : public Bstr
     
    648637    BstrFmtVA(const char *aFormat, va_list aArgs)
    649638    {
    650         copyFrom(Utf8StrFmtVA(aFormat, aArgs).c_str());
     639        copyFrom(Utf8Str(aFormat, aArgs).c_str());
    651640    }
    652641};
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette