diff options
Diffstat (limited to 'qtools/qgstring.cpp')
-rw-r--r-- | qtools/qgstring.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/qtools/qgstring.cpp b/qtools/qgstring.cpp index f43cd6b..f42eede 100644 --- a/qtools/qgstring.cpp +++ b/qtools/qgstring.cpp @@ -22,6 +22,7 @@ #define ROUND_SIZE(x) ((x)+BLOCK_SIZE-1)&~(BLOCK_SIZE-1) #define DBG_STR(x) do { } while(0) +//#define DBG_STR(x) printf x QGString::QGString() // make null string : m_data(0), m_len(0), m_memSize(0) @@ -123,6 +124,40 @@ bool QGString::resize( uint newlen ) return TRUE; } +bool QGString::enlarge( uint newlen ) +{ + if (newlen==0) + { + if (m_data) { free(m_data); m_data=0; } + m_memSize=0; + m_len=0; + return TRUE; + } + uint newMemSize = ROUND_SIZE(newlen+1); + if (newMemSize==m_memSize) return TRUE; + m_memSize = newMemSize; + if (m_data==0) + { + m_data = (char *)malloc(m_memSize); + } + else + { + m_data = (char *)realloc(m_data,m_memSize); + } + if (m_data==0) + { + return FALSE; + } + m_data[newlen-1]='\0'; + if (m_len>newlen) m_len=newlen; + return TRUE; +} + +void QGString::setLen( uint newlen ) +{ + m_len = newlen<=m_memSize ? newlen : m_memSize; +} + QGString &QGString::operator=( const QGString &s ) { if (m_data) free(m_data); |