libcsdbg  1.28
C++ exception (and generic) stack trace debug library
string & csdbg::string::insert ( u32  pos,
const string rval 
)
virtual

Insert a string at a specified position.

Parameters
[in]posthe insertion position
[in]rvalthe inserted text
Returns
*this
Exceptions
std::bad_alloc

Definition at line 575 of file string.cpp.

References append(), likely, m_data, m_length, memalign(), and unlikely.

Referenced by csdbg::style::apply(), and insert().

576 {
577  if ( unlikely(pos >= m_length) )
578  return append(rval);
579 
580  u32 len = m_length + rval.m_length;
581  memalign(len, true);
582 
583  /* Shift the string to make place for the inserted text */
584  u32 i = m_length;
585  u32 j = len;
586  i32 tail = m_length - pos;
587  while ( likely(tail-- >= 0) )
588  m_data[j--] = m_data[i--];
589 
590  strncpy(m_data + pos, rval.m_data, rval.m_length);
591  m_length = len;
592  return *this;
593 }
virtual string & append(const string &)
Append a string.
Definition: string.cpp:404
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
virtual string & memalign(u32, bool=false)
Allocate aligned memory, mandate a minimum buffer size.
Definition: string.cpp:26
i8 * m_data
String data.
Definition: string.hpp:42
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
int i32
32-bit signed integer
Definition: config.hpp:82
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349
u32 m_length
Character count.
Definition: string.hpp:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function: