| IDA SDK

Static Public Attributes | Public Member Functions | Static Public Member Functions | Public Types | List of all members
_qstring< qchar > Class Template Reference

## Detailed Description

template<class qchar>
class _qstring< qchar >

Reimplementation of the string class from STL.

Only the most essential functions are implemented. The reason why we have this is because it is not compiler dependent (hopefully) and therefore can be used in IDA API

## Static Public Attributes
static constexpr size_t | npos = (size_t) -1
| Invalid position.

## Public Member Functions
| _qstring (void)
| Constructor.
| _qstring (const qchar *ptr)
| Constructor - creates a new qstring from an existing char *.
| _qstring (const qchar *ptr, size_t len)
| Constructor - creates a new qstring using first 'len' chars from 'ptr'.
| _qstring (size_t count, qchar ch)
| Constructor - constructs the string with 'count' copies of character 'ch'.
| _qstring (_qstring &&x)
| Move constructor.
| _qstring (const _qstring &r)
| Copy constructor (if not declared, move constructor causes it to be deleted)
void | swap (_qstring< qchar > &r)
| Swap contents of two qstrings. see qvector::swap()
size_t | length (void) const
| Get number of chars in this qstring (not including terminating zero)
size_t | size (void) const
| Get number of chars in this qstring (including terminating zero)
size_t | capacity (void) const
| Get number of chars this qstring can contain (including terminating zero)
void | resize (size_t s, qchar c)
| Resize to the given size. More...
void | resize (size_t s)
| Similar to resize(size_t, qchar) - but any extra space is filled with zeroes.
void | remove_last (int cnt=1)
void | reserve (size_t cnt)
| Increase capacity the qstring. see qvector::reserve()
void | clear (void)
| Clear qstring and free memory.
void | qclear (void)
| Clear qstring but do not free memory yet.
bool | empty (void) const
| Does the qstring have 0 non-null elements?
const qchar * | c_str (void) const
| Convert the qstring to a char *.
iterator | begin (void)
| Get a pointer to the beginning of the qstring.
const_iterator | begin (void) const
| Get a const pointer to the beginning of the qstring.
iterator | end (void)
| Get a pointer to the end of the qstring (this is not the terminating zero)
const_iterator | end (void) const
| Get a const pointer to the end of the qstring (this is not the terminating zero)
_qstring & | operator= (const qchar *str)
| Allow assignment of qstrings using '='.
_qstring & | operator= (const _qstring &qstr)
_qstring & | operator= (_qstring &&x) noexcept
| Move assignment operator.
_qstring & | operator+= (qchar c)
| Append a char using '+='.
_qstring & | operator+= (const _qstring &r)
| Append another qstring using '+='.
_qstring | operator+ (const _qstring &r) const
| Get result of appending two qstrings using '+'.
bool | operator== (const qchar *r) const
| Test equality of a qstring and a const char* using '=='.
bool | operator!= (const qchar *r) const
| Test equality of a qstring and a const char* with '!='.
bool | operator< (const qchar *r) const
| Compare two qstrings using '<'. see qstrcmp()
bool | starts_with (const _qstring &str) const
| Does the string start with the specified prefix?
bool | starts_with (const qchar *ptr, ssize_t len=-1) const
bool | ends_with (const _qstring &str) const
| Does the string end with the specified suffix?
bool | ends_with (const qchar *ptr, ssize_t len=-1) const
const qchar & | operator[] (size_t idx) const
| Retrieve char at index 'idx' using '[]'.
qchar & | operator[] (size_t idx)
| Retrieve char at index 'idx' using '[]'.
const qchar & | at (size_t idx) const
| Retrieve const char at index 'idx'.
qchar & | at (size_t idx)
| Retrieve char at index 'idx'.
qchar * | extract (void)
| Extract C string from _qstring. Must qfree() it.
void | inject (qchar *s, size_t len)
| Assign this qstring to an existing char *. More...
void | inject (qchar *s)
| Same as to inject(qchar *, size_t), with len = strlen(s)
qchar | last (void) const
| Get the last qchar in the string (for concatenation checks)
size_t | find (const qchar *str, size_t pos=0) const
| Find a substring. More...
bool | replace (const qchar *what, const qchar *with)
| Replace all occurrences of 'what' with 'with'. More...
size_t | find (const _qstring &str, size_t pos=0) const
| Same as find(const qchar *, size_t), but takes a qstring parameter.
size_t | find (qchar c, size_t pos=0) const
| Find a character in the qstring. More...
size_t | rfind (qchar c, size_t pos=0) const
| Search backwards for a character in the qstring. More...
_qstring< qchar > | substr (size_t pos=0, size_t n=npos) const
| Get a substring. More...
_qstring & | remove (size_t idx, size_t cnt)
| Remove characters from the qstring. More...
_qstring & | insert (size_t idx, qchar c)
| Insert a character into the qstring. More...
_qstring & | insert (size_t idx, const qchar *str, size_t addlen)
| Insert a string into the qstring. More...
_qstring & | insert (size_t idx, const qchar *str)
| Same as insert(size_t, const qchar *, size_t), but all chars in str are inserted.
_qstring & | insert (size_t idx, const _qstring &qstr)
| Same as insert(size_t, const qchar *), but takes a qstring parameter.
_qstring & | insert (qchar c)
| Prepend the qstring with 'c'.
_qstring & | insert (const qchar *str)
| Prepend the qstring with 'str'.
_qstring & | insert (const _qstring &qstr)
| Prepend the qstring with 'qstr'.
_qstring & | append (qchar c)
| Append c to the end of the qstring.
_qstring & | append (const qchar *str, size_t addlen)
| Append a string to the qstring. More...
_qstring & | append (const qchar *str)
| Same as append(const qchar *, size_t), but all chars in 'str' are appended.
_qstring & | append (const _qstring &qstr)
| Same as append(const qchar *), but takes a qstring argument.
_qstring & | cat_vsprnt (const char *format, va_list va)
| Append result of qvsnprintf() to qstring.
_qstring & | vsprnt (const char *format, va_list va)
| Replace qstring with the result of qvsnprintf()
_qstring & | cat_sprnt (const char *format,...)
| Append result of qsnprintf() to qstring.
_qstring & | sprnt (const char *format,...)
| Replace qstring with the result of qsnprintf()
| GCC_DIAG_OFF (format-nonliteral)
| Replace qstring with the result of qsnprintf() More...
_qstring & | nowarn_sprnt (const char *format,...)
| GCC_DIAG_ON (format-nonliteral)
_qstring & | fill (size_t pos, qchar c, size_t len)
| Fill qstring with a character. More...
_qstring & | fill (qchar c, size_t len)
| Clear contents of qstring and fill with 'c'.
_qstring & | ltrim (qchar blank=' ')
| Remove all instances of the specified char from the beginning of the qstring.
_qstring & | rtrim (qchar blank, size_t minlen=0)
| Remove all instances of the specified char from the end of the qstring.
_qstring & | rtrim ()
| Remove all whitespace from the end of the qstring.
_qstring & | trim2 (qchar blank=' ')
| Remove all instances of the specified char from both ends of the qstring.
void | split (qvector< _qstring< qchar > > *out, const qchar *sep, uint32 flags=0) const
| Split a string on SEP, appending the parts to OUT. More...

## Static Public Member Functions
static _qstring< qchar > | join (const qvector< _qstring< qchar > > &parts, const qchar *sep)
| Join the provided parts into a single string with each element separated by SEP. More...

## Public Types
typedef qchar * | iterator
typedef const qchar * | const_iterator

## Member Function Documentation

## ◆ resize()

template<class qchar >

void _qstring< qchar >::resize | ( | size_t | s,
|  | qchar | c
| ) |  |
| inline

Resize to the given size.

The resulting qstring will have length() = s, and size() = s+1
if 's' is greater than the current size then the extra space is filled with 'c'.
if 's' is less than the current size then the trailing chars are removed

## ◆ inject()

template<class qchar >

void _qstring< qchar >::inject | ( | qchar * | s,
|  | size_t | len
| ) |  |
| inline

Assign this qstring to an existing char *.

See qvector::inject(T *, size_t)

## ◆ find() [1/2]

template<class qchar >

size_t _qstring< qchar >::find | ( | const qchar * | str,
|  | size_t | pos = `0`
| ) |  | const
| inline

Find a substring.

Parameters

  str | the substring to look for
  pos | starting position

Returns
  the position of the beginning of the first occurrence of str, _qstring::npos of none exists

## ◆ replace()

template<class qchar >

bool _qstring< qchar >::replace | ( | const qchar * | what,
|  | const qchar * | with
| ) |  |
| inline

Replace all occurrences of 'what' with 'with'.

Returns
  false if 'what' is not found in the qstring, true otherwise

## ◆ find() [2/2]

template<class qchar >

size_t _qstring< qchar >::find | ( | qchar | c,
|  | size_t | pos = `0`
| ) |  | const
| inline

Find a character in the qstring.

Parameters

  c | the character to look for
  pos | starting position

Returns
  index of first occurrence of 'c' if c is found, _qstring::npos otherwise

## ◆ rfind()

template<class qchar >

size_t _qstring< qchar >::rfind | ( | qchar | c,
|  | size_t | pos = `0`
| ) |  | const
| inline

Search backwards for a character in the qstring.

Parameters

  c | the char to look for
  pos | starting position

Returns
  index of first occurrence of 'c' if c is found, _qstring::npos otherwise

## ◆ substr()

template<class qchar >

_qstring< qchar > _qstring< qchar >::substr | ( | size_t | pos = `0`,
|  | size_t | n = `npos`
| ) |  | const
| inline

Get a substring.

Parameters

  pos | starting position
  n | ending position (non-inclusive)

Returns
  the resulting substring

## ◆ remove()

template<class qchar >

_qstring & _qstring< qchar >::remove | ( | size_t | idx,
|  | size_t | cnt
| ) |  |
| inline

Remove characters from the qstring.

Parameters

  idx | starting position
  cnt | number of characters to remove

## ◆ insert() [1/2]

template<class qchar >

_qstring & _qstring< qchar >::insert | ( | size_t | idx,
|  | qchar | c
| ) |  |
| inline

Insert a character into the qstring.

Parameters

  idx | position of insertion (if idx >= length(), the effect is the same as append)
  c | char to insert

## ◆ insert() [2/2]

template<class qchar >

_qstring & _qstring< qchar >::insert | ( | size_t | idx,
|  | const qchar * | str,
|  | size_t | addlen
| ) |  |
| inline

Insert a string into the qstring.

Parameters

  idx | position of insertion (if idx >= length(), the effect is the same as append)
  str | the string to insert
  addlen | number of chars from 'str' to insert

## ◆ append()

template<class qchar >

_qstring & _qstring< qchar >::append | ( | const qchar * | str,
|  | size_t | addlen
| ) |  |
| inline

Append a string to the qstring.

Parameters

  str | the string to append
  addlen | number of characters from 'str' to append

## ◆ GCC_DIAG_OFF()

template<class qchar >

_qstring< qchar >::GCC_DIAG_OFF | ( | format- | nonliteral | ) |

Replace qstring with the result of qsnprintf()

See also
  inline int nowarn_qsnprintf(char *buf, size_t size, const char *format, ...)

## ◆ fill()

template<class qchar >

_qstring & _qstring< qchar >::fill | ( | size_t | pos,
|  | qchar | c,
|  | size_t | len
| ) |  |
| inline

Fill qstring with a character.

The qstring is resized if necessary until 'len' chars have been filled

Parameters

  pos | starting position
  c | the character to fill
  len | number of positions to fill with 'c'

## ◆ split()

template<class qchar >

void _qstring< qchar >::split | ( | qvector< _qstring< qchar > > * | out,
|  | const qchar * | sep,
|  | uint32 | flags = `0`
| ) |  | const

Split a string on SEP, appending the parts to OUT.

Parameters

  out | storage
  sep | the separator to split on
  flags | a combination of Flags for _qstring::split

## ◆ join()

template<class qchar >

static _qstring< qchar > _qstring< qchar >::join | ( | const qvector< _qstring< qchar > > & | parts,
|  | const qchar * | sep
| ) |  |
| static

Join the provided parts into a single string with each element separated by SEP.

Parameters

  parts | the parts to join
  sep | the separator to join on (it can be an empty string)

Returns
  the combined string

The documentation for this class was generated from the following file:

- pro.h