String builder - truncate() method

This commit is contained in:
Emmanuel BENOîT 2017-11-29 09:24:51 +01:00
parent 5db261909a
commit 86a3fe34b4
3 changed files with 36 additions and 0 deletions
include/ebcl

View file

@ -391,6 +391,7 @@ class T_StringBuilder
T_StringBuilder& ensureCapacity( uint32_t minCap );
T_StringBuilder& clear( );
T_StringBuilder& free( );
T_StringBuilder& truncate( uint32_t maxLength ) noexcept;
// ---------------------------------------------------------------------

View file

@ -458,6 +458,16 @@ inline T_StringBuilder& T_StringBuilder::clear( )
return *this;
}
inline T_StringBuilder& T_StringBuilder::truncate(
const uint32_t maxLength ) noexcept
{
if ( maxLength < length_ ) {
size_ = UTF8GetMemoryOffset( data_ , maxLength );
length_ = maxLength;
}
return *this;
}
/*----------------------------------------------------------------------------*/
inline bool T_StringBuilder::operator== ( T_StringBuilder const& other ) const