Changeset 64343 in vbox for trunk/src/VBox/Runtime/common/string/strprintf.cpp
- Timestamp:
- Oct 20, 2016 7:28:31 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/strprintf.cpp
r62477 r64343 67 67 { 68 68 PSTRBUFARG pArg = (PSTRBUFARG)pvArg; 69 char *pszCur = pArg->psz; /* We actually have to spell this out for VS2010, or it will load for each case. */ 69 70 70 71 cbChars = RT_MIN(pArg->cch, cbChars); 71 72 if (cbChars) 72 73 { 73 memcpy(pArg->psz, pachChars, cbChars);74 74 pArg->cch -= cbChars; 75 pArg->psz += cbChars; 75 76 /* Note! For VS2010/64 we need at least 7 case statements before it generates a jump table. */ 77 switch (cbChars) 78 { 79 default: 80 memcpy(pszCur, pachChars, cbChars); 81 break; 82 case 8: pszCur[7] = pachChars[7]; 83 case 7: pszCur[6] = pachChars[6]; 84 case 6: pszCur[5] = pachChars[5]; 85 case 5: pszCur[4] = pachChars[4]; 86 case 4: pszCur[3] = pachChars[3]; 87 case 3: pszCur[2] = pachChars[2]; 88 case 2: pszCur[1] = pachChars[1]; 89 case 1: pszCur[0] = pachChars[0]; 90 case 0: 91 break; 92 } 93 pArg->psz = pszCur += cbChars; 76 94 } 77 *p Arg->psz= '\0';95 *pszCur = '\0'; 78 96 79 97 return cbChars; … … 81 99 82 100 101 RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...) 102 { 103 /* Explicitly inline RTStrPrintfV + RTStrPrintfExV here because this is a frequently use API. */ 104 STRBUFARG Arg; 105 va_list args; 106 size_t cbRet; 107 108 AssertMsgReturn(cchBuffer, ("Excellent idea! Format a string with no space for the output!\n"), 0); 109 Arg.psz = pszBuffer; 110 Arg.cch = cchBuffer - 1; 111 112 va_start(args, pszFormat); 113 cbRet = RTStrFormatV(strbufoutput, &Arg, NULL, NULL, pszFormat, args); 114 va_end(args); 115 116 return cbRet; 117 } 118 RT_EXPORT_SYMBOL(RTStrPrintf); 119 120 83 121 RTDECL(size_t) RTStrPrintfExV(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffer, size_t cchBuffer, const char *pszFormat, va_list args) 84 122 { 85 123 STRBUFARG Arg; 86 87 if (!cchBuffer) 88 { 89 AssertMsgFailed(("Excellent idea! Format a string with no space for the output!\n")); 90 return 0; 91 } 92 124 AssertMsgReturn(cchBuffer, ("Excellent idea! Format a string with no space for the output!\n"), 0); 93 125 Arg.psz = pszBuffer; 94 126 Arg.cch = cchBuffer - 1; … … 116 148 RT_EXPORT_SYMBOL(RTStrPrintfEx); 117 149 118 119 RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...)120 {121 va_list args;122 size_t cbRet;123 va_start(args, pszFormat);124 cbRet = RTStrPrintfV(pszBuffer, cchBuffer, pszFormat, args);125 va_end(args);126 return cbRet;127 }128 RT_EXPORT_SYMBOL(RTStrPrintf);129
Note:
See TracChangeset
for help on using the changeset viewer.