Pre-resize fillparent
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
#include <stdlib.h> /* strtol */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// disable _s warnings
|
||||
/// disable _s warnings
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
// disable pragma warnings
|
||||
/// disable pragma warnings
|
||||
# pragma warning( disable : 4068 )
|
||||
# pragma warning( disable : 4996 )
|
||||
# include "MSUNIX/msunix.hpp"
|
||||
@@ -86,7 +86,7 @@ size_t cString::size() const
|
||||
return m_len;
|
||||
}
|
||||
|
||||
// string format
|
||||
/// string format
|
||||
cString& cString::format(const char* format, ...)
|
||||
{
|
||||
char * buffer;
|
||||
@@ -100,7 +100,7 @@ cString& cString::format(const char* format, ...)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// trim leading and trailing spaces
|
||||
/// trim leading and trailing spaces
|
||||
cString& cString::trim()
|
||||
{
|
||||
const static char * whitespace = "\x20\x1b\t\r\n\v\b\f\a";
|
||||
@@ -164,7 +164,7 @@ const char& cString::last_char() const
|
||||
return mp_str[length() - 1];
|
||||
}
|
||||
|
||||
// non-destructive split
|
||||
/// non-destructive split
|
||||
const std::vector<cString> cString::split(const char match) const
|
||||
{
|
||||
const char match_s[2] = { match, 0 };
|
||||
@@ -185,14 +185,14 @@ const std::vector<cString> cString::split(const char* match, int max_split) cons
|
||||
if (match_len >= __cString__MAX_LEN)
|
||||
return rtn;
|
||||
|
||||
char* mi; // match index
|
||||
char* pstr = mp_str; // string pointer
|
||||
char* mi; /// match index
|
||||
char* pstr = mp_str; /// string pointer
|
||||
while ((mi = strstr(pstr, match)) && (max_split < 0 || --max_split)) {
|
||||
if (mi != pstr) {
|
||||
size_t lhsz = mi - pstr;
|
||||
char* cslhs = (char *)malloc(lhsz + 1);
|
||||
cslhs[lhsz] = '\0'; // strncpy doesn't terminate it
|
||||
rtn.emplace_back(strncpy(cslhs, pstr, lhsz)); // calls cString copy ctor
|
||||
cslhs[lhsz] = '\0'; /// strncpy doesn't terminate it
|
||||
rtn.emplace_back(strncpy(cslhs, pstr, lhsz)); /// calls cString copy ctor
|
||||
pstr += lhsz;
|
||||
free(cslhs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user