VirtualBox

Changeset 25596 in vbox


Ignore:
Timestamp:
Dec 30, 2009 10:53:20 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56287
Message:

iprt: Added new format extension: %Rbn - prints the base of a path name.

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/strformatrt.cpp

    r25000 r25596  
    131131 *      - \%Rfn             - Pretty printing of a function or method. It drops the
    132132 *                            return code and parameter list.
     133 *      - \%Rbn             - Prints the base name.  For dropping the path in
     134 *                            order to save space when printing a path name.
    133135 *
    134136 * On other platforms, \%Rw? simply prints the argument in a form of 0xXXXXXXXX.
     
    160162#include <iprt/time.h>
    161163#include <iprt/net.h>
     164#include <iprt/path.h>
    162165#include "internal/string.h"
    163166
     
    568571
    569572            /*
     573             * Base name printing.
     574             */
     575            case 'b':
     576            {
     577                switch (*(*ppszFormat)++)
     578                {
     579                    case 'n':
     580                    {
     581                        const char *pszLastSep;
     582                        const char *psz = pszLastSep = va_arg(*pArgs, const char *);
     583                        if (!VALID_PTR(psz))
     584                            return pfnOutput(pvArgOutput, "<null>", sizeof("<null>") - 1);
     585
     586                        while ((ch = *psz) != '\0')
     587                        {
     588                            if (RTPATH_IS_SEP(ch))
     589                            {
     590                                do
     591                                    psz++;
     592                                while ((ch = *psz) != '\0' && RTPATH_IS_SEP(ch));
     593                                if (!ch)
     594                                    break;
     595                                pszLastSep = psz;
     596                            }
     597                            psz++;
     598                        }
     599
     600                        return pfnOutput(pvArgOutput, pszLastSep, psz - pszLastSep);
     601                    }
     602
     603                    default:
     604                        AssertMsgFailed(("Invalid status code format type '%.10s'!\n", pszFormatOrg));
     605                        break;
     606                }
     607                break;
     608            }
     609
     610
     611            /*
    570612             * Pretty function / method name printing.
    571613             */
  • trunk/src/VBox/Runtime/testcase/tstRTStrFormat.cpp

    r23961 r25596  
    231231    CHECK42("%RI8", (int8_t)-128, "-128");
    232232
     233    CHECK42("%Rbn", "file.c", "file.c");
     234    CHECK42("%Rbn", "foo/file.c", "file.c");
     235    CHECK42("%Rbn", "/foo/file.c", "file.c");
     236    CHECK42("%Rbn", "/dir/subdir/", "subdir/");
     237
     238    CHECK42("%Rfn", "function", "function");
     239    CHECK42("%Rfn", "void function(void)", "function");
     240
    233241    CHECK42("%RTfile", (RTFILE)127, "127");
    234242    CHECK42("%RTfile", (RTFILE)12341234, "12341234");
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