From: Christian P. <cp...@us...> - 2005-06-22 11:33:30
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12693/src/Unicode Modified Files: String.cpp Log Message: - Added String::insert(size_t pos, size_t n, const Char& ch) - Added String::insert(size_t pos, const String& str) Index: String.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/String.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- String.cpp 24 May 2005 04:41:21 -0000 1.10 +++ String.cpp 22 Jun 2005 11:33:18 -0000 1.11 @@ -301,6 +301,59 @@ #define getUCharOffset(data, pos, offset) U16_FWD_N(data->str, offset, data->length, pos) +String& String::insert(size_t pos, size_t n, const Char& ch) +{ + if(_data.null()) + { + _data = alloc(pos + n); + //@todo .. zero all chars + } + else if(_data->size <= _data->length + pos + n) + resize(_data->length + pos + n); + else + deepCopy(); + + // get the initial uchar16 offset specified by codepoint pos + size_t offset = 0; + getUCharOffset(_data, pos, offset); + + u_strncpy(_data->str + offset + n, + _data->str + n, + _data->length - offset); + + for(size_t i = 0; i < n; ++i) + *(_data->str + offset + i) = ch; + + _data->length += n; + return *this; +} + +String& String::insert(size_t pos, const String& str) +{ + if(_data.null()) + { + _data = alloc(pos + str._data->length); + //@todo .. zero all chars + } + else if(_data->size <= _data->length + pos + str._data->length) + resize(_data->length + pos + str._data->length); + else + deepCopy(); + + // get the initial uchar16 offset specified by codepoint pos + size_t offset = 0; + getUCharOffset(_data, pos, offset); + + u_strncpy(_data->str + offset + str._data->length, + _data->str + str._data->length, + _data->length - offset); + + u_strncpy(_data->str + offset, str._data->str, str._data->length); + + _data->length += str._data->length; + return *this; +} + size_t String::find(const String& str, size_t pos/*=0*/) const { if(str._data.null() || !str._data->length) |