xpath_string Class Reference

## Public Member Functions

| xpath_string ()
| xpath_string (const char_t *str, xpath_allocator *alloc)
| xpath_string (const char_t *str, bool use_heap)
| xpath_string (const char_t *begin, const char_t *end, xpath_allocator *alloc)
void | append (const xpath_string &o, xpath_allocator *alloc)
const char_t * | c_str () const
size_t | length () const
char_t * | data (xpath_allocator *alloc)
bool | empty () const
bool | operator== (const xpath_string &o) const
bool | operator!= (const xpath_string &o) const
bool | uses_heap () const

## Static Private Member Functions

static char_t * | duplicate_string (const char_t *string, size_t length, xpath_allocator *alloc)
static char_t * | duplicate_string (const char_t *string, xpath_allocator *alloc)

## Private Attributes

const char_t * | _buffer
bool | _uses_heap

## Detailed Description

Definition at line 6402 of file pugixml.cpp.

## Constructor & Destructor Documentation

## xpath_string() [1/4]

xpath_string::xpath_string | ( |  | ) |

inline

Definition at line 6424 of file pugixml.cpp.

: _buffer(PUGIXML_TEXT("")), _uses_heap(false)
{
}
xpath_string::_uses_heap
bool _uses_heap
Definition: pugixml.cpp:6405
xpath_string::_buffer
const char_t * _buffer
Definition: pugixml.cpp:6404

## xpath_string() [2/4]

xpath_string::xpath_string | ( | const char_t * | str,
|  | xpath_allocator * | alloc
| ) |  |

inline explicit

Definition at line 6428 of file pugixml.cpp.

{
bool empty_ = (*str == 0);
_buffer = empty_ ? PUGIXML_TEXT("") : duplicate_string(str, alloc);
_uses_heap = !empty_;
}
xpath_string::duplicate_string
static char_t * duplicate_string(const char_t *string, size_t length, xpath_allocator *alloc)
Definition: pugixml.cpp:6407

References _buffer, _uses_heap, and duplicate_string().

## xpath_string() [3/4]

xpath_string::xpath_string | ( | const char_t * | str,
|  | bool | use_heap
| ) |  |

inline explicit

Definition at line 6436 of file pugixml.cpp.

: _buffer(str), _uses_heap(use_heap)
{
}

## xpath_string() [4/4]

xpath_string::xpath_string | ( | const char_t * | begin,
|  | const char_t * | end,
|  | xpath_allocator * | alloc
| ) |  |

inline

Definition at line 6440 of file pugixml.cpp.

{
assert(begin <= end);
bool empty_ = (begin == end);
_buffer = empty_ ? PUGIXML_TEXT("") : duplicate_string(begin, static_cast<size_t>(end - begin), alloc);
_uses_heap = !empty_;
}

References _buffer, _uses_heap, and duplicate_string().

## Member Function Documentation

## append()

void xpath_string::append | ( | const xpath_string & | o,
|  | xpath_allocator * | alloc
| ) |  |

inline

Definition at line 6450 of file pugixml.cpp.

{
// skip empty sources
if (!*o._buffer) return;
// fast append for constant empty target and constant source
if (!*_buffer && !_uses_heap && !o._uses_heap)
{
_buffer = o._buffer;
}
else
{
// need to make heap copy
size_t target_length = strlength(_buffer);
size_t source_length = strlength(o._buffer);
size_t result_length = target_length + source_length;
// allocate new buffer
char_t* result = static_cast<char_t*>(alloc->reallocate(_uses_heap ? const_cast<char_t*>(_buffer) : 0, (target_length + 1) * sizeof(char_t), (result_length + 1) * sizeof(char_t)));
assert(result);
// append first string to the new buffer in case there was no reallocation
if (!_uses_heap) memcpy(result, _buffer, target_length * sizeof(char_t));
// append second string to the new buffer
memcpy(result + target_length, o._buffer, source_length * sizeof(char_t));
result[result_length] = 0;
// finalize
_buffer = result;
_uses_heap = true;
}
}
xpath_allocator::reallocate
void * reallocate(void *ptr, size_t old_size, size_t new_size)
Definition: pugixml.cpp:6267
strlength
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN size_t strlength(const char_t *s)
Definition: pugixml.cpp:176

References _buffer, _uses_heap, xpath_allocator::reallocate(), and strlength().

Referenced by string_value().

## c_str()

const char_t* xpath_string::c_str | ( |  | ) | const

inline

Definition at line 6484 of file pugixml.cpp.

{
return _buffer;
}

References _buffer.

Referenced by xpath_ast_node::compare_eq(), xpath_ast_node::compare_rel(), xpath_ast_node::eval_boolean(), xpath_ast_node::eval_number(), and xpath_ast_node::eval_string().

## data()

char_t* xpath_string::data | ( | xpath_allocator * | alloc | ) |

inline

Definition at line 6494 of file pugixml.cpp.

{
// make private heap copy
if (!_uses_heap)
{
_buffer = duplicate_string(_buffer, alloc);
_uses_heap = true;
}
return const_cast<char_t*>(_buffer);
}

References _buffer, _uses_heap, and duplicate_string().

Referenced by xpath_ast_node::eval_string().

## duplicate_string() [1/2]

static char_t* xpath_string::duplicate_string | ( | const char_t * | string,
|  | size_t | length,
|  | xpath_allocator * | alloc
| ) |  |

inline static private

Definition at line 6407 of file pugixml.cpp.

{
char_t* result = static_cast<char_t*>(alloc->allocate((length + 1) * sizeof(char_t)));
assert(result);
memcpy(result, string, length * sizeof(char_t));
result[length] = 0;
return result;
}
xpath_allocator::allocate
void * allocate(size_t size)
Definition: pugixml.cpp:6250
xpath_string::length
size_t length() const
Definition: pugixml.cpp:6489

References xpath_allocator::allocate(), and length().

Referenced by data(), duplicate_string(), and xpath_string().

## duplicate_string() [2/2]

static char_t* xpath_string::duplicate_string | ( | const char_t * | string,
|  | xpath_allocator * | alloc
| ) |  |

inline static private

Definition at line 6418 of file pugixml.cpp.

{
return duplicate_string(string, strlength(string), alloc);
}

References duplicate_string(), and strlength().

## empty()

bool xpath_string::empty | ( |  | ) | const

inline

Definition at line 6506 of file pugixml.cpp.

{
return *_buffer == 0;
}

References _buffer.

Referenced by xpath_ast_node::eval_boolean().

## length()

size_t xpath_string::length | ( |  | ) | const

inline

Definition at line 6489 of file pugixml.cpp.

{
return strlength(_buffer);
}

References _buffer, and strlength().

Referenced by duplicate_string(), xpath_ast_node::eval_number(), and xpath_ast_node::eval_string().

## operator!=()

bool xpath_string::operator!= | ( | const xpath_string & | o | ) | const

inline

Definition at line 6516 of file pugixml.cpp.

{
return !strequal(_buffer, o._buffer);
}
strequal
PUGI__FN bool strequal(const char_t *src, const char_t *dst)
Definition: pugixml.cpp:188

References _buffer, and strequal().

## operator==()

bool xpath_string::operator== | ( | const xpath_string & | o | ) | const

inline

Definition at line 6511 of file pugixml.cpp.

{
return strequal(_buffer, o._buffer);
}

References _buffer, and strequal().

## uses_heap()

bool xpath_string::uses_heap | ( |  | ) | const

inline

Definition at line 6521 of file pugixml.cpp.

{
return _uses_heap;
}

References _uses_heap.

Referenced by xpath_ast_node::eval_string().

## Member Data Documentation

## _buffer

const char_t* xpath_string::_buffer

private

Definition at line 6404 of file pugixml.cpp.

Referenced by append(), c_str(), data(), empty(), length(), operator!=(), operator==(), and xpath_string().

## _uses_heap

bool xpath_string::_uses_heap

private

Definition at line 6405 of file pugixml.cpp.

Referenced by append(), data(), uses_heap(), and xpath_string().

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

- pugixml.cpp