Changeset 33862 in vbox for trunk/include/iprt/cpp
- Timestamp:
- Nov 8, 2010 5:07:49 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/ministring.h
r33818 r33862 102 102 * Create a partial copy of another MiniString. 103 103 * 104 * @param a_rSrc The source string. 105 * @param a_offSrc The byte offset into the source string. 104 106 * @param a_cchSrc The max number of chars (encoded UTF-8 bytes) 105 107 * to copy from the source string. 106 * @param a_rSrc The source string. 107 */ 108 MiniString(size_t a_cchSrc, const MiniString &a_rSrc) 109 { 110 Assert(a_cchSrc <= a_rSrc.m_cch); 111 copyFromN(a_rSrc.m_psz, RT_MIN(a_cchSrc, a_rSrc.m_cch)); 108 */ 109 MiniString(const MiniString &a_rSrc, size_t a_offSrc, size_t a_cchSrc = npos) 110 { 111 if (a_offSrc < a_rSrc.m_cch) 112 copyFromN(&a_rSrc.m_psz[a_offSrc], RT_MIN(a_cchSrc, a_rSrc.m_cch - a_offSrc)); 113 else 114 { 115 m_psz = NULL; 116 m_cch = 0; 117 m_cbAllocated = 0; 118 } 112 119 } 113 120 … … 115 122 * Create a partial copy of a C string. 116 123 * 124 * @param a_pszSrc The source string (UTF-8). 117 125 * @param a_cchSrc The max number of chars (encoded UTF-8 bytes) 118 * to copy from the source string. 119 * @param a_pszSrc The source string (UTF-8). 120 */ 121 MiniString(size_t a_cchSrc, const char *a_pszSrc) 126 * to copy from the source string. This must not 127 * be '0' as the compiler could easily mistake 128 * that for the va_list constructor. 129 */ 130 MiniString(const char *a_pszSrc, size_t a_cchSrc) 122 131 { 123 132 size_t cchMax = a_pszSrc ? RTStrNLen(a_pszSrc, a_cchSrc) : 0; 124 Assert(a_cchSrc <= cchMax);125 133 copyFromN(a_pszSrc, RT_MIN(a_cchSrc, cchMax)); 134 } 135 136 /** 137 * Create a string containing @a a_cTimes repetitions of the character @a 138 * a_ch. 139 * 140 * @param a_cTimes The number of times the character is repeated. 141 * @param a_ch The character to fill the string with. 142 */ 143 MiniString(size_t a_cTimes, char a_ch) 144 : m_psz(NULL), 145 m_cch(0), 146 m_cbAllocated(0) 147 { 148 Assert((unsigned)a_ch < 0x80); 149 if (a_cTimes) 150 { 151 reserve(a_cTimes + 1); 152 memset(m_psz, a_ch, a_cTimes); 153 m_psz[a_cTimes] = '\0'; 154 m_cch = a_cTimes; 155 } 126 156 } 127 157 … … 134 164 * specified by the format string. 135 165 * @sa printfV 166 * @remarks Not part of std::string. 136 167 */ 137 168 MiniString(const char *a_pszFormat, va_list a_va) … … 139 170 m_cch(0), 140 171 m_cbAllocated(0) 141 142 172 { 143 173 printfV(a_pszFormat, a_va); … … 783 813 m_cch = cchSrc; 784 814 m_cbAllocated = cchSrc + 1; 785 memcpy(m_psz, pcszSrc, cchSrc + 1); 815 memcpy(m_psz, pcszSrc, cchSrc); 816 m_psz[cchSrc] = '\0'; 786 817 } 787 818 else
Note:
See TracChangeset
for help on using the changeset viewer.