Changeset 27648 in vbox for trunk/src/VBox/Runtime/common/string/strformatrt.cpp
- Timestamp:
- Mar 23, 2010 10:42:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/strformatrt.cpp
r26588 r27648 139 139 * 140 140 * - \%RDtimespec - Takes a PCRTTIMESPEC. 141 * 142 * 143 * Group 5, XML / HTML escapers. 144 * - \%RMas - Takes a string pointer (const char *) and outputs 145 * it as an attribute value with the proper escaping. 146 * This typically ends up in double quotes. 147 * 148 * - \%RMes - Takes a string pointer (const char *) and outputs 149 * it as an element with the necessary escaping. 141 150 * 142 151 * … … 1028 1037 1029 1038 /* 1039 * Group 5, XML / HTML escapers. 1040 */ 1041 case 'M': 1042 { 1043 char chWhat = (*ppszFormat)[0]; 1044 bool fAttr = chWhat == 'a'; 1045 char chType = (*ppszFormat)[1]; 1046 AssertMsgBreak(chWhat == 'a' || chWhat == 'e', ("Invalid IPRT format type '%.10s'!\n", pszFormatOrg)); 1047 *ppszFormat += 2; 1048 switch (chType) 1049 { 1050 case 's': 1051 { 1052 static const char s_szAttrEscape[] = "\n\""; /* more? */ 1053 static const char s_szElemEscape[] = "<>&'\""; 1054 const char *pszEscape = fAttr ? s_szAttrEscape : s_szElemEscape; 1055 int cchEscape = fAttr ? RT_ELEMENTS(s_szAttrEscape) - 1 : RT_ELEMENTS(s_szElemEscape) - 1; 1056 int cchOutput = 0; 1057 const char *pszStr = va_arg(*pArgs, char *); 1058 int cchStr; 1059 int offCur; 1060 int offLast; 1061 1062 if (!VALID_PTR(pszStr)) 1063 pszStr = "<NULL>"; 1064 cchStr = RTStrNLen(pszStr, (unsigned)cchPrecision); 1065 1066 if (fAttr) 1067 cchOutput += pfnOutput(pvArgOutput, "\"", 1); 1068 if (!(fFlags & RTSTR_F_LEFT)) 1069 while (--cchWidth >= cchStr) 1070 cchOutput += pfnOutput(pvArgOutput, " ", 1); 1071 1072 offLast = offCur = 0; 1073 while (offCur < cchStr) 1074 { 1075 if (memchr(pszEscape, pszStr[offCur], cchEscape)) 1076 { 1077 if (offLast < offCur) 1078 cchOutput += pfnOutput(pvArgOutput, &pszStr[offLast], offCur - offLast); 1079 if (fAttr) 1080 switch (pszStr[offCur]) 1081 { 1082 case '\n': cchOutput += pfnOutput(pvArgOutput, "\\\n", 2); break; 1083 case '"': cchOutput += pfnOutput(pvArgOutput, "\\\"", 2); break; 1084 default: 1085 AssertFailed(); 1086 } 1087 else 1088 switch (pszStr[offCur]) 1089 { 1090 case '<': cchOutput += pfnOutput(pvArgOutput, "<", 4); break; 1091 case '>': cchOutput += pfnOutput(pvArgOutput, ">", 4); break; 1092 case '&': cchOutput += pfnOutput(pvArgOutput, "&", 5); break; 1093 case '\'': cchOutput += pfnOutput(pvArgOutput, "'", 6); break; 1094 case '"': cchOutput += pfnOutput(pvArgOutput, "&qout;", 6); break; 1095 default: 1096 AssertFailed(); 1097 } 1098 offLast = offCur + 1; 1099 } 1100 offCur++; 1101 } 1102 if (offLast < offCur) 1103 cchOutput += pfnOutput(pvArgOutput, &pszStr[offLast], offCur - offLast); 1104 1105 while (--cchWidth >= cchStr) 1106 cchOutput += pfnOutput(pvArgOutput, " ", 1); 1107 if (fAttr) 1108 cchOutput += pfnOutput(pvArgOutput, "\"", 1); 1109 return cchOutput; 1110 } 1111 1112 default: 1113 AssertMsgFailed(("Invalid IPRT format type '%.10s'!\n", pszFormatOrg)); 1114 } 1115 break; 1116 } 1117 1118 /* 1030 1119 * Invalid/Unknown. Bitch about it. 1031 1120 */ 1032 1121 default: 1033 AssertMsgFailed(("Invalid VBoxformat type '%.10s'!\n", pszFormatOrg));1122 AssertMsgFailed(("Invalid IPRT format type '%.10s'!\n", pszFormatOrg)); 1034 1123 break; 1035 1124 } 1036 1125 } 1037 1126 else 1038 AssertMsgFailed(("Invalid VBoxformat type '%.10s'!\n", pszFormatOrg));1127 AssertMsgFailed(("Invalid IPRT format type '%.10s'!\n", pszFormatOrg)); 1039 1128 1040 1129 NOREF(pszFormatOrg);
Note:
See TracChangeset
for help on using the changeset viewer.