libcsdbg  1.28
C++ exception (and generic) stack trace debug library
string & csdbg::string::trim ( i32  which = 0)
virtual

Remove leading and/or trailing whitespace characters.

Parameters
[in]which<0 to trim the leading, >0 for the trailing and 0 for both (default)
Returns
*this

Definition at line 529 of file string.cpp.

References clear(), likely, m_data, m_length, and unlikely.

Referenced by csdbg::dictionary::load_file().

530 {
531  if ( likely(which <= 0) ) {
532  /* Estimate the number of leading whitespace characters */
533  u32 i;
534  for (i = 0; likely(i < m_length); i++)
535  if ( likely(!isspace(m_data[i])) )
536  break;
537 
538  /* Remove them */
539  if ( unlikely(i > 0 && i < m_length) ) {
540  strcpy(m_data, m_data + i);
541  m_length -= i;
542  }
543 
544  /* If the string is filled with whitespace characters */
545  else if ( unlikely(i == m_length) )
546  return clear();
547  }
548 
549  if ( likely(which >= 0) ) {
550  /* Estimate the number of trailing whitespace characters */
551  i32 i;
552  for (i = m_length - 1; likely(i >= 0); i--)
553  if ( likely(!isspace(m_data[i])) )
554  break;
555 
556  m_data[++i] = '\0';
557  m_length = i;
558  }
559 
560  return *this;
561 }
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
virtual string & clear()
Clear contents.
Definition: string.cpp:387
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: