Classes | Namespaces | Defines | Typedefs | Enumerations | Functions | Variables
pugixml.cpp File Reference

Go to the source code of this file.

Classes

struct  xml_memory_management_function_storage< T >
struct  buffer_holder
struct  xml_memory_page
struct  xml_memory_string_header
struct  xml_allocator
struct  pugi::xml_attribute_struct
 A 'name=value' XML attribute structure. More...
struct  pugi::xml_node_struct
 An XML document tree node. More...
struct  xml_extra_buffer
struct  xml_document_struct
struct  opt_false
struct  opt_true
struct  utf8_counter
struct  utf8_writer
struct  utf16_counter
struct  utf16_writer
struct  utf32_counter
struct  utf32_writer
struct  latin1_writer
struct  wchar_selector< 2 >
struct  wchar_selector< 4 >
struct  utf_decoder< Traits, opt_swap >
struct  gap
struct  strconv_pcdata_impl< opt_trim, opt_eol, opt_escape >
struct  strconv_attribute_impl< opt_escape >
struct  xml_parser
class  xml_buffered_writer
struct  xml_stream_chunk< T >
struct  equal_to
struct  not_equal_to
struct  less
struct  less_equal
struct  xpath_memory_block
class  xpath_allocator
struct  xpath_allocator_capture
struct  xpath_stack
struct  xpath_stack_data
class  xpath_string
struct  document_order_comparator
struct  duplicate_comparator
struct  namespace_uri_predicate
struct  xpath_variable_boolean
struct  xpath_variable_number
struct  xpath_variable_string
struct  xpath_variable_node_set
class  xpath_node_set_raw
struct  xpath_context
struct  xpath_lexer_string
class  xpath_lexer
struct  axis_to_type< N >
class  xpath_ast_node
struct  xpath_parser
struct  xpath_parser::binary_op_t
struct  xpath_query_impl

Namespaces

namespace  pugi

Defines

#define SOURCE_PUGIXML_CPP
 pugixml parser - version 1.4
#define PUGI__NO_INLINE
#define PUGI__UNLIKELY(cond)   (cond)
#define PUGI__STATIC_ASSERT(cond)   { static const char condition_failed[(cond) ? 1 : -1] = {0}; (void)condition_failed[0]; }
#define PUGI__DMC_VOLATILE
#define PUGI__NS_BEGIN   namespace pugi { namespace impl { namespace {
#define PUGI__NS_END   } } }
#define PUGI__FN
#define PUGI__FN_NO_INLINE   PUGI__NO_INLINE
#define PUGI__IS_CHARTYPE_IMPL(c, ct, table)   (table[static_cast<unsigned char>(c)] & (ct))
#define PUGI__IS_CHARTYPE(c, ct)   PUGI__IS_CHARTYPE_IMPL(c, ct, chartype_table)
#define PUGI__IS_CHARTYPEX(c, ct)   PUGI__IS_CHARTYPE_IMPL(c, ct, chartypex_table)
#define PUGI__ENDSWITH(c, e)   ((c) == (e) || ((c) == 0 && endch == (e)))
#define PUGI__SKIPWS()   { while (PUGI__IS_CHARTYPE(*s, ct_space)) ++s; }
#define PUGI__OPTSET(OPT)   ( optmsk & (OPT) )
#define PUGI__PUSHNODE(TYPE)   { cursor = append_new_node(cursor, alloc, TYPE); if (!cursor) PUGI__THROW_ERROR(status_out_of_memory, s); }
#define PUGI__POPNODE()   { cursor = cursor->parent; }
#define PUGI__SCANFOR(X)   { while (*s != 0 && !(X)) ++s; }
#define PUGI__SCANWHILE(X)   { while (X) ++s; }
#define PUGI__SCANWHILE_UNROLL(X)   { while (X) { ++s; if (PUGI__UNLIKELY(!(X))) break; ++s; if (PUGI__UNLIKELY(!(X))) break; ++s; if (PUGI__UNLIKELY(!(X))) break; ++s; } }
#define PUGI__ENDSEG()   { ch = *s; *s = 0; ++s; }
#define PUGI__THROW_ERROR(err, m)   return error_offset = m, error_status = err, static_cast<char_t*>(0)
#define PUGI__CHECK_ERROR(err, m)   { if (*s == 0) PUGI__THROW_ERROR(err, m); }

Typedefs

typedef
xml_memory_management_function_storage
< int > 
xml_memory
typedef wchar_selector< sizeof(wchar_t)>
::counter 
wchar_counter
typedef wchar_selector< sizeof(wchar_t)>
::writer 
wchar_writer
typedef char_t *(* strconv_pcdata_t )(char_t *)
typedef char_t *(* strconv_attribute_t )(char_t *, char_t)

Enumerations

enum  chartype_t {
  ct_parse_pcdata = 1, ct_parse_attr = 2, ct_parse_attr_ws = 4, ct_space = 8,
  ct_parse_cdata = 16, ct_parse_comment = 32, ct_symbol = 64, ct_start_symbol = 128
}
enum  chartypex_t {
  ctx_special_pcdata = 1, ctx_special_attr = 2, ctx_start_symbol = 4, ctx_digit = 8,
  ctx_symbol = 16
}
enum  lexeme_t {
  lex_none = 0, lex_equal, lex_not_equal, lex_less,
  lex_greater, lex_less_or_equal, lex_greater_or_equal, lex_plus,
  lex_minus, lex_multiply, lex_union, lex_var_ref,
  lex_open_brace, lex_close_brace, lex_quoted_string, lex_number,
  lex_slash, lex_double_slash, lex_open_square_brace, lex_close_square_brace,
  lex_string, lex_comma, lex_axis_attribute, lex_dot,
  lex_double_dot, lex_double_colon, lex_eof
}
enum  ast_type_t {
  ast_unknown, ast_op_or, ast_op_and, ast_op_equal,
  ast_op_not_equal, ast_op_less, ast_op_greater, ast_op_less_or_equal,
  ast_op_greater_or_equal, ast_op_add, ast_op_subtract, ast_op_multiply,
  ast_op_divide, ast_op_mod, ast_op_negate, ast_op_union,
  ast_predicate, ast_filter, ast_filter_posinv, ast_string_constant,
  ast_number_constant, ast_variable, ast_func_last, ast_func_position,
  ast_func_count, ast_func_id, ast_func_local_name_0, ast_func_local_name_1,
  ast_func_namespace_uri_0, ast_func_namespace_uri_1, ast_func_name_0, ast_func_name_1,
  ast_func_string_0, ast_func_string_1, ast_func_concat, ast_func_starts_with,
  ast_func_contains, ast_func_substring_before, ast_func_substring_after, ast_func_substring_2,
  ast_func_substring_3, ast_func_string_length_0, ast_func_string_length_1, ast_func_normalize_space_0,
  ast_func_normalize_space_1, ast_func_translate, ast_func_boolean, ast_func_not,
  ast_func_true, ast_func_false, ast_func_lang, ast_func_number_0,
  ast_func_number_1, ast_func_sum, ast_func_floor, ast_func_ceiling,
  ast_func_round, ast_step, ast_step_root
}
enum  axis_t {
  axis_ancestor, axis_ancestor_or_self, axis_attribute, axis_child,
  axis_descendant, axis_descendant_or_self, axis_following, axis_following_sibling,
  axis_namespace, axis_parent, axis_preceding, axis_preceding_sibling,
  axis_self
}
enum  nodetest_t {
  nodetest_none, nodetest_name, nodetest_type_node, nodetest_type_comment,
  nodetest_type_pi, nodetest_type_text, nodetest_pi, nodetest_all,
  nodetest_all_in_namespace
}

Functions

PUGI__NS_BEGIN PUGI__FN void * default_allocate (size_t size)
PUGI__FN void default_deallocate (void *ptr)
PUGI__NS_END PUGI__NS_BEGIN
PUGI__FN size_t 
strlength (const char_t *s)
PUGI__FN bool strequal (const char_t *src, const char_t *dst)
PUGI__FN bool strequalrange (const char_t *lhs, const char_t *rhs, size_t count)
PUGI__FN size_t strlength_wide (const wchar_t *s)
xml_allocatorget_allocator (const xml_node_struct *node)
PUGI__NS_END PUGI__NS_BEGIN
xml_attribute_struct * 
allocate_attribute (xml_allocator &alloc)
xml_node_struct * allocate_node (xml_allocator &alloc, xml_node_type type)
void destroy_attribute (xml_attribute_struct *a, xml_allocator &alloc)
void destroy_node (xml_node_struct *n, xml_allocator &alloc)
void append_node (xml_node_struct *child, xml_node_struct *node)
void prepend_node (xml_node_struct *child, xml_node_struct *node)
void insert_node_after (xml_node_struct *child, xml_node_struct *node)
void insert_node_before (xml_node_struct *child, xml_node_struct *node)
void remove_node (xml_node_struct *node)
PUGI__FN_NO_INLINE
xml_node_struct * 
append_new_node (xml_node_struct *node, xml_allocator &alloc, xml_node_type type=node_element)
PUGI__FN_NO_INLINE
xml_attribute_struct * 
append_new_attribute (xml_node_struct *node, xml_allocator &alloc)
PUGI__NS_END PUGI__NS_BEGIN
uint16_t 
endian_swap (uint16_t value)
uint32_t endian_swap (uint32_t value)
template<typename T >
PUGI__FN void convert_utf_endian_swap (T *result, const T *data, size_t length)
PUGI__FN bool is_little_endian ()
PUGI__FN xml_encoding get_wchar_encoding ()
PUGI__FN xml_encoding guess_buffer_encoding (uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
PUGI__FN xml_encoding get_buffer_encoding (xml_encoding encoding, const void *contents, size_t size)
PUGI__FN bool get_mutable_buffer (char_t *&out_buffer, size_t &out_length, const void *contents, size_t size, bool is_mutable)
template<typename opt_swap >
PUGI__FN bool convert_buffer_utf16 (char_t *&out_buffer, size_t &out_length, const void *contents, size_t size, opt_swap)
template<typename opt_swap >
PUGI__FN bool convert_buffer_utf32 (char_t *&out_buffer, size_t &out_length, const void *contents, size_t size, opt_swap)
PUGI__FN size_t get_latin1_7bit_prefix_length (const uint8_t *data, size_t size)
PUGI__FN bool convert_buffer_latin1 (char_t *&out_buffer, size_t &out_length, const void *contents, size_t size, bool is_mutable)
PUGI__FN bool convert_buffer (char_t *&out_buffer, size_t &out_length, xml_encoding encoding, const void *contents, size_t size, bool is_mutable)
PUGI__FN size_t as_utf8_begin (const wchar_t *str, size_t length)
PUGI__FN void as_utf8_end (char *buffer, size_t size, const wchar_t *str, size_t length)
PUGI__FN std::string as_utf8_impl (const wchar_t *str, size_t length)
PUGI__FN std::basic_string
< wchar_t > 
as_wide_impl (const char *str, size_t size)
bool strcpy_insitu_allow (size_t length, uintptr_t allocated, char_t *target)
PUGI__FN bool strcpy_insitu (char_t *&dest, uintptr_t &header, uintptr_t header_mask, const char_t *source)
PUGI__FN char_t * strconv_escape (char_t *s, gap &g)
PUGI__FN char_t * strconv_comment (char_t *s, char_t endch)
PUGI__FN char_t * strconv_cdata (char_t *s, char_t endch)
PUGI__FN strconv_pcdata_t get_strconv_pcdata (unsigned int optmask)
PUGI__FN strconv_attribute_t get_strconv_attribute (unsigned int optmask)
xml_parse_result make_parse_result (xml_parse_status status, ptrdiff_t offset=0)
PUGI__FN xml_encoding get_write_native_encoding ()
PUGI__FN xml_encoding get_write_encoding (xml_encoding encoding)
PUGI__FN size_t get_valid_length (const char_t *data, size_t length)
PUGI__FN size_t convert_buffer_output (char_t *, uint8_t *r_u8, uint16_t *r_u16, uint32_t *r_u32, const char_t *data, size_t length, xml_encoding encoding)
PUGI__FN void text_output_escaped (xml_buffered_writer &writer, const char_t *s, chartypex_t type)
PUGI__FN void text_output (xml_buffered_writer &writer, const char_t *s, chartypex_t type, unsigned int flags)
PUGI__FN void text_output_cdata (xml_buffered_writer &writer, const char_t *s)
PUGI__FN void node_output_attributes (xml_buffered_writer &writer, const xml_node &node, unsigned int flags)
PUGI__FN void node_output (xml_buffered_writer &writer, const xml_node &node, const char_t *indent, unsigned int flags, unsigned int depth)
bool has_declaration (const xml_node &node)
bool allow_insert_child (xml_node_type parent, xml_node_type child)
PUGI__FN bool allow_move (const xml_node &parent, const xml_node &child)
PUGI__FN void recursive_copy_skip (xml_node &dest, const xml_node &source, const xml_node &skip)
bool is_text_node (xml_node_struct *node)
PUGI__FN int get_integer_base (const char_t *value)
PUGI__FN int get_value_int (const char_t *value, int def)
PUGI__FN unsigned int get_value_uint (const char_t *value, unsigned int def)
PUGI__FN double get_value_double (const char_t *value, double def)
PUGI__FN float get_value_float (const char_t *value, float def)
PUGI__FN bool get_value_bool (const char_t *value, bool def)
PUGI__FN bool set_value_buffer (char_t *&dest, uintptr_t &header, uintptr_t header_mask, char(&buf)[128])
PUGI__FN bool set_value_convert (char_t *&dest, uintptr_t &header, uintptr_t header_mask, int value)
PUGI__FN bool set_value_convert (char_t *&dest, uintptr_t &header, uintptr_t header_mask, unsigned int value)
PUGI__FN bool set_value_convert (char_t *&dest, uintptr_t &header, uintptr_t header_mask, double value)
PUGI__FN bool set_value_convert (char_t *&dest, uintptr_t &header, uintptr_t header_mask, bool value)
PUGI__FN xml_parse_status get_file_size (FILE *file, size_t &out_result)
PUGI__FN size_t zero_terminate_buffer (void *buffer, size_t size, xml_encoding encoding)
PUGI__FN xml_parse_result load_file_impl (xml_document &doc, FILE *file, unsigned int options, xml_encoding encoding)
template<typename T >
PUGI__FN xml_parse_status load_stream_data_noseek (std::basic_istream< T > &stream, void **out_buffer, size_t *out_size)
template<typename T >
PUGI__FN xml_parse_status load_stream_data_seek (std::basic_istream< T > &stream, void **out_buffer, size_t *out_size)
template<typename T >
PUGI__FN xml_parse_result load_stream_impl (xml_document &doc, std::basic_istream< T > &stream, unsigned int options, xml_encoding encoding)
PUGI__FN char * convert_path_heap (const wchar_t *str)
PUGI__FN FILE * open_file_wide (const wchar_t *path, const wchar_t *mode)
PUGI__FN bool save_file_impl (const xml_document &doc, FILE *file, const char_t *indent, unsigned int flags, xml_encoding encoding)
PUGI__FN xml_parse_result load_buffer_impl (xml_document_struct *doc, xml_node_struct *root, void *contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own, char_t **out_buffer)
static PUGI__FN void pugi::unspecified_bool_xml_attribute (xml_attribute ***)
static PUGI__FN void pugi::unspecified_bool_xml_node (xml_node ***)
static PUGI__FN void pugi::unspecified_bool_xml_text (xml_text ***)
PUGI__FN std::string
PUGIXML_FUNCTION 
pugi::as_utf8 (const wchar_t *str)
PUGI__FN std::string
PUGIXML_FUNCTION 
pugi::as_utf8 (const std::basic_string< wchar_t > &str)
PUGI__FN std::basic_string
< wchar_t > PUGIXML_FUNCTION 
pugi::as_wide (const char *str)
PUGI__FN std::basic_string
< wchar_t > PUGIXML_FUNCTION 
pugi::as_wide (const std::string &str)
PUGI__FN void PUGIXML_FUNCTION pugi::set_memory_management_functions (allocation_function allocate, deallocation_function deallocate)
PUGI__FN allocation_function
PUGIXML_FUNCTION 
pugi::get_memory_allocation_function ()
PUGI__FN deallocation_function
PUGIXML_FUNCTION 
pugi::get_memory_deallocation_function ()
template<typename T >
void swap (T &lhs, T &rhs)
template<typename I , typename Pred >
min_element (I begin, I end, const Pred &pred)
template<typename I >
void reverse (I begin, I end)
template<typename I >
unique (I begin, I end)
template<typename I >
void copy_backwards (I begin, I end, I target)
template<typename I , typename Pred , typename T >
void insertion_sort (I begin, I end, const Pred &pred, T *)
template<typename I , typename Pred >
void partition (I begin, I middle, I end, const Pred &pred, I *out_eqbeg, I *out_eqend)
template<typename I , typename Pred >
void median3 (I first, I middle, I last, const Pred &pred)
template<typename I , typename Pred >
void median (I first, I middle, I last, const Pred &pred)
template<typename I , typename Pred >
void sort (I begin, I end, const Pred &pred)
PUGI__FN xpath_string xpath_string_const (const char_t *str)
PUGI__NS_END PUGI__NS_BEGIN
PUGI__FN bool 
starts_with (const char_t *string, const char_t *pattern)
PUGI__FN const char_t * find_char (const char_t *s, char_t c)
PUGI__FN const char_t * find_substring (const char_t *s, const char_t *p)
PUGI__FN char_t tolower_ascii (char_t ch)
PUGI__FN xpath_string string_value (const xpath_node &na, xpath_allocator *alloc)
PUGI__FN unsigned int node_height (xml_node n)
PUGI__FN bool node_is_before (xml_node ln, unsigned int lh, xml_node rn, unsigned int rh)
PUGI__FN bool node_is_ancestor (xml_node parent, xml_node node)
PUGI__FN const void * document_order (const xpath_node &xnode)
PUGI__FN double gen_nan ()
PUGI__FN bool is_nan (double value)
PUGI__FN const char_t * convert_number_to_string_special (double value)
PUGI__FN bool convert_number_to_boolean (double value)
PUGI__FN void truncate_zeros (char *begin, char *end)
PUGI__FN void convert_number_to_mantissa_exponent (double value, char *buffer, size_t buffer_size, char **out_mantissa, int *out_exponent)
PUGI__FN xpath_string convert_number_to_string (double value, xpath_allocator *alloc)
PUGI__FN bool check_string_to_number_format (const char_t *string)
PUGI__FN double convert_string_to_number (const char_t *string)
PUGI__FN bool convert_string_to_number_scratch (char_t(&buffer)[32], const char_t *begin, const char_t *end, double *out_result)
PUGI__FN double round_nearest (double value)
PUGI__FN double round_nearest_nzero (double value)
PUGI__FN const char_t * qualified_name (const xpath_node &node)
PUGI__FN const char_t * local_name (const xpath_node &node)
PUGI__FN const char_t * namespace_uri (const xml_node &node)
PUGI__FN const char_t * namespace_uri (const xml_attribute &attr, const xml_node &parent)
PUGI__FN const char_t * namespace_uri (const xpath_node &node)
PUGI__FN void normalize_space (char_t *buffer)
PUGI__FN void translate (char_t *buffer, const char_t *from, const char_t *to)
PUGI__FN unsigned int hash_string (const char_t *str)
template<typename T >
PUGI__FN T * new_xpath_variable (const char_t *name)
PUGI__FN xpath_variable * new_xpath_variable (xpath_value_type type, const char_t *name)
template<typename T >
PUGI__FN void delete_xpath_variable (T *var)
PUGI__FN void delete_xpath_variable (xpath_value_type type, xpath_variable *var)
PUGI__FN xpath_variable * get_variable_scratch (char_t(&buffer)[32], xpath_variable_set *set, const char_t *begin, const char_t *end)
PUGI__NS_END PUGI__NS_BEGIN
PUGI__FN
xpath_node_set::type_t 
xpath_sort (xpath_node *begin, xpath_node *end, xpath_node_set::type_t type, bool rev)
PUGI__FN xpath_node xpath_first (const xpath_node *begin, const xpath_node *end, xpath_node_set::type_t type)
PUGI__FN xpath_string evaluate_string_impl (xpath_query_impl *impl, const xpath_node &n, xpath_stack_data &sd)
static PUGI__FN void pugi::unspecified_bool_xpath_node (xpath_node ***)
static PUGI__FN void pugi::unspecified_bool_xpath_query (xpath_query ***)

Variables

PUGI__NS_END static
PUGI__NS_BEGIN const size_t 
xml_memory_page_size
static const uintptr_t xml_memory_page_alignment = 32
static const uintptr_t xml_memory_page_pointer_mask = ~(xml_memory_page_alignment - 1)
static const uintptr_t xml_memory_page_name_allocated_mask = 16
static const uintptr_t xml_memory_page_value_allocated_mask = 8
static const uintptr_t xml_memory_page_type_mask = 7
static const unsigned char chartype_table [256]
static const unsigned char chartypex_table [256]
static const xpath_node_set dummy_node_set

Define Documentation

#define PUGI__CHECK_ERROR (   err,
 
)    { if (*s == 0) PUGI__THROW_ERROR(err, m); }

Definition at line 101 of file pugixml.cpp.

Referenced by get_buffer_encoding(), and translate().

#define PUGI__ENDSEG ( )    { ch = *s; *s = 0; ++s; }

Definition at line 1907 of file pugixml.cpp.

Referenced by xml_parser::parse_question(), and xml_parser::parse_tree().

#define PUGI__ENDSWITH (   c,
 
)    ((c) == (e) || ((c) == 0 && endch == (e)))
#define PUGI__FN

Definition at line 128 of file pugixml.cpp.

Definition at line 129 of file pugixml.cpp.

#define PUGI__IS_CHARTYPE (   c,
  ct 
)    PUGI__IS_CHARTYPE_IMPL(c, ct, chartype_table)
#define PUGI__IS_CHARTYPE_IMPL (   c,
  ct,
  table 
)    (table[static_cast<unsigned char>(c)] & (ct))

Definition at line 1192 of file pugixml.cpp.

#define PUGI__IS_CHARTYPEX (   c,
  ct 
)    PUGI__IS_CHARTYPE_IMPL(c, ct, chartypex_table)
#define PUGI__NO_INLINE

Definition at line 84 of file pugixml.cpp.

#define PUGI__NS_BEGIN   namespace pugi { namespace impl { namespace {

Definition at line 125 of file pugixml.cpp.

#define PUGI__NS_END   } } }

Definition at line 126 of file pugixml.cpp.

#define PUGI__OPTSET (   OPT)    ( optmsk & (OPT) )
#define PUGI__POPNODE ( )    { cursor = cursor->parent; }
#define PUGI__PUSHNODE (   TYPE)    { cursor = append_new_node(cursor, alloc, TYPE); if (!cursor) PUGI__THROW_ERROR(status_out_of_memory, s); }
#define PUGI__SCANFOR (   X)    { while (*s != 0 && !(X)) ++s; }
#define PUGI__SCANWHILE (   X)    { while (X) ++s; }

Definition at line 1905 of file pugixml.cpp.

Referenced by xml_parser::parse_question().

#define PUGI__SCANWHILE_UNROLL (   X)    { while (X) { ++s; if (PUGI__UNLIKELY(!(X))) break; ++s; if (PUGI__UNLIKELY(!(X))) break; ++s; if (PUGI__UNLIKELY(!(X))) break; ++s; } }
#define PUGI__SKIPWS ( )    { while (PUGI__IS_CHARTYPE(*s, ct_space)) ++s; }

Definition at line 1900 of file pugixml.cpp.

Referenced by xml_parser::parse_question(), and xml_parser::parse_tree().

#define PUGI__STATIC_ASSERT (   cond)    { static const char condition_failed[(cond) ? 1 : -1] = {0}; (void)condition_failed[0]; }
#define PUGI__THROW_ERROR (   err,
 
)    return error_offset = m, error_status = err, static_cast<char_t*>(0)
#define PUGI__UNLIKELY (   cond)    (cond)

Definition at line 91 of file pugixml.cpp.

pugixml parser - version 1.4

-------------------------------------------------------- Copyright (C) 2006-2014, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) Report bugs and download new versions at http://pugixml.org/

This library is distributed under the MIT License. See notice at the end of this file.

This work is based on the pugxml parser, which is: Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)

Definition at line 15 of file pugixml.cpp.


Typedef Documentation

typedef char_t*(* strconv_attribute_t)(char_t *, char_t)

Definition at line 2038 of file pugixml.cpp.

typedef char_t*(* strconv_pcdata_t)(char_t *)

Definition at line 1967 of file pugixml.cpp.

typedef wchar_selector<sizeof(wchar_t)>::counter wchar_counter

Definition at line 949 of file pugixml.cpp.

typedef wchar_selector<sizeof(wchar_t)>::writer wchar_writer

Definition at line 950 of file pugixml.cpp.

Definition at line 170 of file pugixml.cpp.


Enumeration Type Documentation

enum ast_type_t
Enumerator:
ast_unknown 
ast_op_or 
ast_op_and 
ast_op_equal 
ast_op_not_equal 
ast_op_less 
ast_op_greater 
ast_op_less_or_equal 
ast_op_greater_or_equal 
ast_op_add 
ast_op_subtract 
ast_op_multiply 
ast_op_divide 
ast_op_mod 
ast_op_negate 
ast_op_union 
ast_predicate 
ast_filter 
ast_filter_posinv 
ast_string_constant 
ast_number_constant 
ast_variable 
ast_func_last 
ast_func_position 
ast_func_count 
ast_func_id 
ast_func_local_name_0 
ast_func_local_name_1 
ast_func_namespace_uri_0 
ast_func_namespace_uri_1 
ast_func_name_0 
ast_func_name_1 
ast_func_string_0 
ast_func_string_1 
ast_func_concat 
ast_func_starts_with 
ast_func_contains 
ast_func_substring_before 
ast_func_substring_after 
ast_func_substring_2 
ast_func_substring_3 
ast_func_string_length_0 
ast_func_string_length_1 
ast_func_normalize_space_0 
ast_func_normalize_space_1 
ast_func_translate 
ast_func_boolean 
ast_func_not 
ast_func_true 
ast_func_false 
ast_func_lang 
ast_func_number_0 
ast_func_number_1 
ast_func_sum 
ast_func_floor 
ast_func_ceiling 
ast_func_round 
ast_step 
ast_step_root 

Definition at line 7818 of file pugixml.cpp.

        {
                ast_unknown,
                ast_op_or,                                              // left or right
                ast_op_and,                                             // left and right
                ast_op_equal,                                   // left = right
                ast_op_not_equal,                               // left != right
                ast_op_less,                                    // left < right
                ast_op_greater,                                 // left > right
                ast_op_less_or_equal,                   // left <= right
                ast_op_greater_or_equal,                // left >= right
                ast_op_add,                                             // left + right
                ast_op_subtract,                                // left - right
                ast_op_multiply,                                // left * right
                ast_op_divide,                                  // left / right
                ast_op_mod,                                             // left % right
                ast_op_negate,                                  // left - right
                ast_op_union,                                   // left | right
                ast_predicate,                                  // apply predicate to set; next points to next predicate
                ast_filter,                                             // select * from left where right
                ast_filter_posinv,                              // select * from left where right; proximity position invariant
                ast_string_constant,                    // string constant
                ast_number_constant,                    // number constant
                ast_variable,                                   // variable
                ast_func_last,                                  // last()
                ast_func_position,                              // position()
                ast_func_count,                                 // count(left)
                ast_func_id,                                    // id(left)
                ast_func_local_name_0,                  // local-name()
                ast_func_local_name_1,                  // local-name(left)
                ast_func_namespace_uri_0,               // namespace-uri()
                ast_func_namespace_uri_1,               // namespace-uri(left)
                ast_func_name_0,                                // name()
                ast_func_name_1,                                // name(left)
                ast_func_string_0,                              // string()
                ast_func_string_1,                              // string(left)
                ast_func_concat,                                // concat(left, right, siblings)
                ast_func_starts_with,                   // starts_with(left, right)
                ast_func_contains,                              // contains(left, right)
                ast_func_substring_before,              // substring-before(left, right)
                ast_func_substring_after,               // substring-after(left, right)
                ast_func_substring_2,                   // substring(left, right)
                ast_func_substring_3,                   // substring(left, right, third)
                ast_func_string_length_0,               // string-length()
                ast_func_string_length_1,               // string-length(left)
                ast_func_normalize_space_0,             // normalize-space()
                ast_func_normalize_space_1,             // normalize-space(left)
                ast_func_translate,                             // translate(left, right, third)
                ast_func_boolean,                               // boolean(left)
                ast_func_not,                                   // not(left)
                ast_func_true,                                  // true()
                ast_func_false,                                 // false()
                ast_func_lang,                                  // lang(left)
                ast_func_number_0,                              // number()
                ast_func_number_1,                              // number(left)
                ast_func_sum,                                   // sum(left)
                ast_func_floor,                                 // floor(left)
                ast_func_ceiling,                               // ceiling(left)
                ast_func_round,                                 // round(left)
                ast_step,                                               // process set left with step
                ast_step_root                                   // select root node
        };
enum axis_t
Enumerator:
axis_ancestor 
axis_ancestor_or_self 
axis_attribute 
axis_child 
axis_descendant 
axis_descendant_or_self 
axis_following 
axis_following_sibling 
axis_namespace 
axis_parent 
axis_preceding 
axis_preceding_sibling 
axis_self 

Definition at line 7881 of file pugixml.cpp.

enum chartype_t
Enumerator:
ct_parse_pcdata 
ct_parse_attr 
ct_parse_attr_ws 
ct_space 
ct_parse_cdata 
ct_parse_comment 
ct_symbol 
ct_start_symbol 

Definition at line 1125 of file pugixml.cpp.

        {
                ct_parse_pcdata = 1,    // \0, &, \r, <
                ct_parse_attr = 2,              // \0, &, \r, ', "
                ct_parse_attr_ws = 4,   // \0, &, \r, ', ", \n, tab
                ct_space = 8,                   // \r, \n, space, tab
                ct_parse_cdata = 16,    // \0, ], >, \r
                ct_parse_comment = 32,  // \0, -, >, \r
                ct_symbol = 64,                 // Any symbol > 127, a-z, A-Z, 0-9, _, :, -, .
                ct_start_symbol = 128   // Any symbol > 127, a-z, A-Z, _, :
        };
Enumerator:
ctx_special_pcdata 
ctx_special_attr 
ctx_start_symbol 
ctx_digit 
ctx_symbol 

Definition at line 1158 of file pugixml.cpp.

        {
                ctx_special_pcdata = 1,   // Any symbol >= 0 and < 32 (except \t, \r, \n), &, <, >
                ctx_special_attr = 2,     // Any symbol >= 0 and < 32 (except \t), &, <, >, "
                ctx_start_symbol = 4,     // Any symbol > 127, a-z, A-Z, _
                ctx_digit = 8,                    // 0-9
                ctx_symbol = 16                   // Any symbol > 127, a-z, A-Z, 0-9, _, -, .
        };
enum lexeme_t
Enumerator:
lex_none 
lex_equal 
lex_not_equal 
lex_less 
lex_greater 
lex_less_or_equal 
lex_greater_or_equal 
lex_plus 
lex_minus 
lex_multiply 
lex_union 
lex_var_ref 
lex_open_brace 
lex_close_brace 
lex_quoted_string 
lex_number 
lex_slash 
lex_double_slash 
lex_open_square_brace 
lex_close_square_brace 
lex_string 
lex_comma 
lex_axis_attribute 
lex_dot 
lex_double_dot 
lex_double_colon 
lex_eof 

Definition at line 7464 of file pugixml.cpp.

enum nodetest_t
Enumerator:
nodetest_none 
nodetest_name 
nodetest_type_node 
nodetest_type_comment 
nodetest_type_pi 
nodetest_type_text 
nodetest_pi 
nodetest_all 
nodetest_all_in_namespace 

Definition at line 7898 of file pugixml.cpp.


Function Documentation

PUGI__NS_END PUGI__NS_BEGIN xml_attribute_struct* allocate_attribute ( xml_allocator alloc) [inline]

Definition at line 558 of file pugixml.cpp.

References xml_allocator::allocate_memory().

Referenced by append_new_attribute().

        {
                xml_memory_page* page;
                void* memory = alloc.allocate_memory(sizeof(xml_attribute_struct), page);

                return new (memory) xml_attribute_struct(page);
        }
xml_node_struct* allocate_node ( xml_allocator alloc,
xml_node_type  type 
) [inline]

Definition at line 566 of file pugixml.cpp.

References xml_allocator::allocate_memory().

Referenced by append_new_node().

        {
                xml_memory_page* page;
                void* memory = alloc.allocate_memory(sizeof(xml_node_struct), page);

                return new (memory) xml_node_struct(page, type);
        }
bool allow_insert_child ( xml_node_type  parent,
xml_node_type  child 
) [inline]

Definition at line 3430 of file pugixml.cpp.

Referenced by allow_move().

        {
                if (parent != node_document && parent != node_element) return false;
                if (child == node_document || child == node_null) return false;
                if (parent != node_document && (child == node_declaration || child == node_doctype)) return false;

                return true;
        }
PUGI__FN bool allow_move ( const xml_node &  parent,
const xml_node &  child 
)

Definition at line 3439 of file pugixml.cpp.

References allow_insert_child().

        {
                // check that child can be a child of parent
                if (!allow_insert_child(parent.type(), child.type()))
                        return false;

                // check that node is not moved between documents
                if (parent.root() != child.root())
                        return false;

                // check that new parent is not in the child subtree
                xml_node cur = parent;

                while (cur)
                {
                        if (cur == child)
                                return false;

                        cur = cur.parent();
                }

                return true;
        }
PUGI__FN_NO_INLINE xml_attribute_struct* append_new_attribute ( xml_node_struct *  node,
xml_allocator alloc 
)

Definition at line 712 of file pugixml.cpp.

References allocate_attribute().

Referenced by xml_parser::parse_tree().

        {
                xml_attribute_struct* a = allocate_attribute(alloc);
                if (!a) return 0;

                xml_attribute_struct* first_attribute = node->first_attribute;

                if (first_attribute)
                {
                        xml_attribute_struct* last_attribute = first_attribute->prev_attribute_c;

                        last_attribute->next_attribute = a;
                        a->prev_attribute_c = last_attribute;
                        first_attribute->prev_attribute_c = a;
                }
                else
                {
                        node->first_attribute = a;
                        a->prev_attribute_c = a;
                }
                        
                return a;
        }
PUGI__FN_NO_INLINE xml_node_struct* append_new_node ( xml_node_struct *  node,
xml_allocator alloc,
xml_node_type  type = node_element 
)

Definition at line 702 of file pugixml.cpp.

References allocate_node(), and append_node().

        {
                xml_node_struct* child = allocate_node(alloc, type);
                if (!child) return 0;

                append_node(child, node);

                return child;
        }
void append_node ( xml_node_struct *  child,
xml_node_struct *  node 
) [inline]

Definition at line 612 of file pugixml.cpp.

Referenced by append_new_node().

        {
                child->parent = node;

                xml_node_struct* head = node->first_child;

                if (head)
                {
                        xml_node_struct* tail = head->prev_sibling_c;

                        tail->next_sibling = child;
                        child->prev_sibling_c = tail;
                        head->prev_sibling_c = child;
                }
                else
                {
                        node->first_child = child;
                        child->prev_sibling_c = child;
                }

                child->next_sibling = 0;
        }
PUGI__FN size_t as_utf8_begin ( const wchar_t *  str,
size_t  length 
)

Definition at line 1594 of file pugixml.cpp.

References utf_decoder< Traits, opt_swap >::decode_wchar_block().

Referenced by as_utf8_impl(), and convert_path_heap().

        {
                // get length in utf8 characters
                return utf_decoder<utf8_counter>::decode_wchar_block(str, length, 0);
        }
PUGI__FN void as_utf8_end ( char *  buffer,
size_t  size,
const wchar_t *  str,
size_t  length 
)

Definition at line 1600 of file pugixml.cpp.

References utf_decoder< Traits, opt_swap >::decode_wchar_block().

Referenced by as_utf8_impl(), and convert_path_heap().

        {
                // convert to utf8
                uint8_t* begin = reinterpret_cast<uint8_t*>(buffer);
                uint8_t* end = utf_decoder<utf8_writer>::decode_wchar_block(str, length, begin);
        
                assert(begin + size == end);
                (void)!end;

                // zero-terminate
                buffer[size] = 0;
        }
PUGI__FN std::string as_utf8_impl ( const wchar_t *  str,
size_t  length 
)

Definition at line 1614 of file pugixml.cpp.

References as_utf8_begin(), and as_utf8_end().

Referenced by pugi::as_utf8().

        {
                // first pass: get length in utf8 characters
                size_t size = as_utf8_begin(str, length);

                // allocate resulting string
                std::string result;
                result.resize(size);

                // second pass: convert to utf8
                if (size > 0) as_utf8_end(&result[0], size, str, length);

                return result;
        }
PUGI__FN std::basic_string<wchar_t> as_wide_impl ( const char *  str,
size_t  size 
)

Definition at line 1629 of file pugixml.cpp.

References utf_decoder< Traits, opt_swap >::decode_utf8_block().

Referenced by pugi::as_wide().

        {
                const uint8_t* data = reinterpret_cast<const uint8_t*>(str);

                // first pass: get length in wchar_t units
                size_t length = utf_decoder<wchar_counter>::decode_utf8_block(data, size, 0);

                // allocate resulting string
                std::basic_string<wchar_t> result;
                result.resize(length);

                // second pass: convert to wchar_t
                if (length > 0)
                {
                        wchar_writer::value_type begin = reinterpret_cast<wchar_writer::value_type>(&result[0]);
                        wchar_writer::value_type end = utf_decoder<wchar_writer>::decode_utf8_block(data, size, begin);

                        assert(begin + length == end);
                        (void)!end;
                }

                return result;
        }
PUGI__FN bool check_string_to_number_format ( const char_t *  string)

Definition at line 6938 of file pugixml.cpp.

References ct_space, ctx_digit, PUGI__IS_CHARTYPE, and PUGI__IS_CHARTYPEX.

Referenced by convert_string_to_number().

        {
                // parse leading whitespace
                while (PUGI__IS_CHARTYPE(*string, ct_space)) ++string;

                // parse sign
                if (*string == '-') ++string;

                if (!*string) return false;

                // if there is no integer part, there should be a decimal part with at least one digit
                if (!PUGI__IS_CHARTYPEX(string[0], ctx_digit) && (string[0] != '.' || !PUGI__IS_CHARTYPEX(string[1], ctx_digit))) return false;

                // parse integer part
                while (PUGI__IS_CHARTYPEX(*string, ctx_digit)) ++string;

                // parse decimal part
                if (*string == '.')
                {
                        ++string;

                        while (PUGI__IS_CHARTYPEX(*string, ctx_digit)) ++string;
                }

                // parse trailing whitespace
                while (PUGI__IS_CHARTYPE(*string, ct_space)) ++string;

                return *string == 0;
        }
PUGI__FN bool convert_buffer ( char_t *&  out_buffer,
size_t &  out_length,
xml_encoding  encoding,
const void *  contents,
size_t  size,
bool  is_mutable 
)

Definition at line 1561 of file pugixml.cpp.

References convert_buffer_latin1(), convert_buffer_utf16(), convert_buffer_utf32(), get_mutable_buffer(), and is_little_endian().

Referenced by load_buffer_impl().

        {
                // fast path: no conversion required
                if (encoding == encoding_utf8) return get_mutable_buffer(out_buffer, out_length, contents, size, is_mutable);

                // source encoding is utf16
                if (encoding == encoding_utf16_be || encoding == encoding_utf16_le)
                {
                        xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be;

                        return (native_encoding == encoding) ?
                                convert_buffer_utf16(out_buffer, out_length, contents, size, opt_false()) :
                                convert_buffer_utf16(out_buffer, out_length, contents, size, opt_true());
                }

                // source encoding is utf32
                if (encoding == encoding_utf32_be || encoding == encoding_utf32_le)
                {
                        xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be;

                        return (native_encoding == encoding) ?
                                convert_buffer_utf32(out_buffer, out_length, contents, size, opt_false()) :
                                convert_buffer_utf32(out_buffer, out_length, contents, size, opt_true());
                }

                // source encoding is latin1
                if (encoding == encoding_latin1) return convert_buffer_latin1(out_buffer, out_length, contents, size, is_mutable);

                assert(!"Invalid encoding");
                return false;
        }
PUGI__FN bool convert_buffer_latin1 ( char_t *&  out_buffer,
size_t &  out_length,
const void *  contents,
size_t  size,
bool  is_mutable 
)

Definition at line 1524 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, utf_decoder< Traits, opt_swap >::decode_latin1_block(), get_latin1_7bit_prefix_length(), and get_mutable_buffer().

Referenced by convert_buffer().

        {
                const uint8_t* data = static_cast<const uint8_t*>(contents);
                size_t data_length = size;

                // get size of prefix that does not need utf8 conversion
                size_t prefix_length = get_latin1_7bit_prefix_length(data, data_length);
                assert(prefix_length <= data_length);

                const uint8_t* postfix = data + prefix_length;
                size_t postfix_length = data_length - prefix_length;

                // if no conversion is needed, just return the original buffer
                if (postfix_length == 0) return get_mutable_buffer(out_buffer, out_length, contents, size, is_mutable);

                // first pass: get length in utf8 units
                size_t length = prefix_length + utf_decoder<utf8_counter>::decode_latin1_block(postfix, postfix_length, 0);

                // allocate buffer of suitable length
                char_t* buffer = static_cast<char_t*>(xml_memory::allocate((length + 1) * sizeof(char_t)));
                if (!buffer) return false;

                // second pass: convert latin1 input to utf8
                memcpy(buffer, data, prefix_length);

                uint8_t* obegin = reinterpret_cast<uint8_t*>(buffer);
                uint8_t* oend = utf_decoder<utf8_writer>::decode_latin1_block(postfix, postfix_length, obegin + prefix_length);

                assert(oend == obegin + length);
                *oend = 0;

                out_buffer = buffer;
                out_length = length + 1;

                return true;
        }
PUGI__FN size_t convert_buffer_output ( char_t *  ,
uint8_t *  r_u8,
uint16_t *  r_u16,
uint32_t *  r_u32,
const char_t *  data,
size_t  length,
xml_encoding  encoding 
)

Definition at line 2977 of file pugixml.cpp.

References convert_utf_endian_swap(), utf_decoder< Traits, opt_swap >::decode_utf8_block(), and is_little_endian().

Referenced by xml_buffered_writer::flush().

        {
                if (encoding == encoding_utf16_be || encoding == encoding_utf16_le)
                {
                        uint16_t* dest = r_u16;

                        // convert to native utf16
                        uint16_t* end = utf_decoder<utf16_writer>::decode_utf8_block(reinterpret_cast<const uint8_t*>(data), length, dest);

                        // swap if necessary
                        xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be;

                        if (native_encoding != encoding) convert_utf_endian_swap(dest, dest, static_cast<size_t>(end - dest));

                        return static_cast<size_t>(end - dest) * sizeof(uint16_t);
                }

                if (encoding == encoding_utf32_be || encoding == encoding_utf32_le)
                {
                        uint32_t* dest = r_u32;

                        // convert to native utf32
                        uint32_t* end = utf_decoder<utf32_writer>::decode_utf8_block(reinterpret_cast<const uint8_t*>(data), length, dest);

                        // swap if necessary
                        xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be;

                        if (native_encoding != encoding) convert_utf_endian_swap(dest, dest, static_cast<size_t>(end - dest));

                        return static_cast<size_t>(end - dest) * sizeof(uint32_t);
                }

                if (encoding == encoding_latin1)
                {
                        uint8_t* dest = r_u8;
                        uint8_t* end = utf_decoder<latin1_writer>::decode_utf8_block(reinterpret_cast<const uint8_t*>(data), length, dest);

                        return static_cast<size_t>(end - dest);
                }

                assert(!"Invalid encoding");
                return 0;
        }
template<typename opt_swap >
PUGI__FN bool convert_buffer_utf16 ( char_t *&  out_buffer,
size_t &  out_length,
const void *  contents,
size_t  size,
opt_swap   
)

Definition at line 1465 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, and utf_decoder< Traits, opt_swap >::decode_utf16_block().

Referenced by convert_buffer().

        {
                const uint16_t* data = static_cast<const uint16_t*>(contents);
                size_t data_length = size / sizeof(uint16_t);

                // first pass: get length in utf8 units
                size_t length = utf_decoder<utf8_counter, opt_swap>::decode_utf16_block(data, data_length, 0);

                // allocate buffer of suitable length
                char_t* buffer = static_cast<char_t*>(xml_memory::allocate((length + 1) * sizeof(char_t)));
                if (!buffer) return false;

                // second pass: convert utf16 input to utf8
                uint8_t* obegin = reinterpret_cast<uint8_t*>(buffer);
                uint8_t* oend = utf_decoder<utf8_writer, opt_swap>::decode_utf16_block(data, data_length, obegin);

                assert(oend == obegin + length);
                *oend = 0;

                out_buffer = buffer;
                out_length = length + 1;

                return true;
        }
template<typename opt_swap >
PUGI__FN bool convert_buffer_utf32 ( char_t *&  out_buffer,
size_t &  out_length,
const void *  contents,
size_t  size,
opt_swap   
)

Definition at line 1490 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, and utf_decoder< Traits, opt_swap >::decode_utf32_block().

Referenced by convert_buffer().

        {
                const uint32_t* data = static_cast<const uint32_t*>(contents);
                size_t data_length = size / sizeof(uint32_t);

                // first pass: get length in utf8 units
                size_t length = utf_decoder<utf8_counter, opt_swap>::decode_utf32_block(data, data_length, 0);

                // allocate buffer of suitable length
                char_t* buffer = static_cast<char_t*>(xml_memory::allocate((length + 1) * sizeof(char_t)));
                if (!buffer) return false;

                // second pass: convert utf32 input to utf8
                uint8_t* obegin = reinterpret_cast<uint8_t*>(buffer);
                uint8_t* oend = utf_decoder<utf8_writer, opt_swap>::decode_utf32_block(data, data_length, obegin);

                assert(oend == obegin + length);
                *oend = 0;

                out_buffer = buffer;
                out_length = length + 1;

                return true;
        }
PUGI__FN bool convert_number_to_boolean ( double  value)

Definition at line 6812 of file pugixml.cpp.

References is_nan().

Referenced by xpath_ast_node::eval_boolean().

        {
                return (value != 0 && !is_nan(value));
        }
PUGI__FN void convert_number_to_mantissa_exponent ( double  value,
char *  buffer,
size_t  buffer_size,
char **  out_mantissa,
int *  out_exponent 
)

Definition at line 6840 of file pugixml.cpp.

References truncate_zeros().

Referenced by convert_number_to_string().

        {
                // get a scientific notation value with IEEE DBL_DIG decimals
                sprintf(buffer, "%.*e", DBL_DIG, value);
                assert(strlen(buffer) < buffer_size);
                (void)!buffer_size;

                // get the exponent (possibly negative)
                char* exponent_string = strchr(buffer, 'e');
                assert(exponent_string);

                int exponent = atoi(exponent_string + 1);

                // extract mantissa string: skip sign
                char* mantissa = buffer[0] == '-' ? buffer + 1 : buffer;
                assert(mantissa[0] != '0' && mantissa[1] == '.');

                // divide mantissa by 10 to eliminate integer part
                mantissa[1] = mantissa[0];
                mantissa++;
                exponent++;

                // remove extra mantissa digits and zero-terminate mantissa
                truncate_zeros(mantissa, exponent_string);

                // fill results
                *out_mantissa = mantissa;
                *out_exponent = exponent;
        }

Definition at line 6871 of file pugixml.cpp.

References xpath_allocator::allocate(), convert_number_to_mantissa_exponent(), convert_number_to_string_special(), and xpath_string_const().

Referenced by xpath_ast_node::eval_string().

        {
                // try special number conversion
                const char_t* special = convert_number_to_string_special(value);
                if (special) return xpath_string_const(special);

                // get mantissa + exponent form
                char mantissa_buffer[32];

                char* mantissa;
                int exponent;
                convert_number_to_mantissa_exponent(value, mantissa_buffer, sizeof(mantissa_buffer), &mantissa, &exponent);

                // allocate a buffer of suitable length for the number
                size_t result_size = strlen(mantissa_buffer) + (exponent > 0 ? exponent : -exponent) + 4;
                char_t* result = static_cast<char_t*>(alloc->allocate(sizeof(char_t) * result_size));
                assert(result);

                // make the number!
                char_t* s = result;

                // sign
                if (value < 0) *s++ = '-';

                // integer part
                if (exponent <= 0)
                {
                        *s++ = '0';
                }
                else
                {
                        while (exponent > 0)
                        {
                                assert(*mantissa == 0 || static_cast<unsigned int>(static_cast<unsigned int>(*mantissa) - '0') <= 9);
                                *s++ = *mantissa ? *mantissa++ : '0';
                                exponent--;
                        }
                }

                // fractional part
                if (*mantissa)
                {
                        // decimal point
                        *s++ = '.';

                        // extra zeroes from negative exponent
                        while (exponent < 0)
                        {
                                *s++ = '0';
                                exponent++;
                        }

                        // extra mantissa digits
                        while (*mantissa)
                        {
                                assert(static_cast<unsigned int>(*mantissa - '0') <= 9);
                                *s++ = *mantissa++;
                        }
                }

                // zero-terminate
                assert(s < result + result_size);
                *s = 0;

                return xpath_string(result, true);
        }
PUGI__FN const char_t* convert_number_to_string_special ( double  value)

Definition at line 6780 of file pugixml.cpp.

Referenced by convert_number_to_string().

        {
        #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__)
                if (_finite(value)) return (value == 0) ? PUGIXML_TEXT("0") : 0;
                if (_isnan(value)) return PUGIXML_TEXT("NaN");
                return value > 0 ? PUGIXML_TEXT("Infinity") : PUGIXML_TEXT("-Infinity");
        #elif defined(fpclassify) && defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO)
                switch (fpclassify(value))
                {
                case FP_NAN:
                        return PUGIXML_TEXT("NaN");

                case FP_INFINITE:
                        return value > 0 ? PUGIXML_TEXT("Infinity") : PUGIXML_TEXT("-Infinity");

                case FP_ZERO:
                        return PUGIXML_TEXT("0");

                default:
                        return 0;
                }
        #else
                // fallback
                const volatile double v = value;

                if (v == 0) return PUGIXML_TEXT("0");
                if (v != v) return PUGIXML_TEXT("NaN");
                if (v * 2 == v) return value > 0 ? PUGIXML_TEXT("Infinity") : PUGIXML_TEXT("-Infinity");
                return 0;
        #endif
        }
PUGI__FN char* convert_path_heap ( const wchar_t *  str)

Definition at line 3959 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, as_utf8_begin(), as_utf8_end(), and strlength_wide().

Referenced by open_file_wide().

        {
                assert(str);

                // first pass: get length in utf8 characters
                size_t length = strlength_wide(str);
                size_t size = as_utf8_begin(str, length);

                // allocate resulting string
                char* result = static_cast<char*>(xml_memory::allocate(size + 1));
                if (!result) return 0;

                // second pass: convert to utf8
                as_utf8_end(result, size, str, length);

                return result;
        }
PUGI__FN double convert_string_to_number ( const char_t *  string)

Definition at line 6968 of file pugixml.cpp.

References check_string_to_number_format(), and gen_nan().

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

        {
                // check string format
                if (!check_string_to_number_format(string)) return gen_nan();

                // parse string
        #ifdef PUGIXML_WCHAR_MODE
                return wcstod(string, 0);
        #else
                return atof(string);
        #endif
        }
PUGI__FN bool convert_string_to_number_scratch ( char_t(&)  buffer[32],
const char_t *  begin,
const char_t *  end,
double *  out_result 
)

Definition at line 6981 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, convert_string_to_number(), and xml_memory_management_function_storage< T >::deallocate.

Referenced by xpath_parser::parse_primary_expression().

        {
                size_t length = static_cast<size_t>(end - begin);
                char_t* scratch = buffer;

                if (length >= sizeof(buffer) / sizeof(buffer[0]))
                {
                        // need to make dummy on-heap copy
                        scratch = static_cast<char_t*>(xml_memory::allocate((length + 1) * sizeof(char_t)));
                        if (!scratch) return false;
                }

                // copy string to zero-terminated buffer and perform conversion
                memcpy(scratch, begin, length * sizeof(char_t));
                scratch[length] = 0;

                *out_result = convert_string_to_number(scratch);

                // free dummy buffer
                if (scratch != buffer) xml_memory::deallocate(scratch);

                return true;
        }
template<typename T >
PUGI__FN void convert_utf_endian_swap ( T *  result,
const T *  data,
size_t  length 
)

Definition at line 1111 of file pugixml.cpp.

References endian_swap().

Referenced by convert_buffer_output().

        {
                for (size_t i = 0; i < length; ++i) result[i] = endian_swap(data[i]);
        }
template<typename I >
void copy_backwards ( begin,
end,
target 
)

Definition at line 6037 of file pugixml.cpp.

Referenced by insertion_sort().

        {
                while (begin != end) *--target = *--end;
        }
PUGI__NS_BEGIN PUGI__FN void* default_allocate ( size_t  size)

Definition at line 150 of file pugixml.cpp.

        {
                return malloc(size);
        }
PUGI__FN void default_deallocate ( void *  ptr)

Definition at line 155 of file pugixml.cpp.

        {
                free(ptr);
        }
template<typename T >
PUGI__FN void delete_xpath_variable ( T *  var)

Definition at line 7244 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::deallocate.

Referenced by delete_xpath_variable().

        {
                var->~T();
                xml_memory::deallocate(var);
        }
PUGI__FN void delete_xpath_variable ( xpath_value_type  type,
xpath_variable *  var 
)

Definition at line 7250 of file pugixml.cpp.

References delete_xpath_variable().

        {
                switch (type)
                {
                case xpath_type_node_set:
                        delete_xpath_variable(static_cast<xpath_variable_node_set*>(var));
                        break;

                case xpath_type_number:
                        delete_xpath_variable(static_cast<xpath_variable_number*>(var));
                        break;

                case xpath_type_string:
                        delete_xpath_variable(static_cast<xpath_variable_string*>(var));
                        break;

                case xpath_type_boolean:
                        delete_xpath_variable(static_cast<xpath_variable_boolean*>(var));
                        break;

                default:
                        assert(!"Invalid variable type");
                }
        }
void destroy_attribute ( xml_attribute_struct *  a,
xml_allocator alloc 
) [inline]

Definition at line 574 of file pugixml.cpp.

References xml_allocator::deallocate_memory(), xml_allocator::deallocate_string(), xml_memory_page_name_allocated_mask, and xml_memory_page_value_allocated_mask.

Referenced by destroy_node().

        {
                uintptr_t header = a->header;

                if (header & impl::xml_memory_page_name_allocated_mask) alloc.deallocate_string(a->name);
                if (header & impl::xml_memory_page_value_allocated_mask) alloc.deallocate_string(a->value);

                alloc.deallocate_memory(a, sizeof(xml_attribute_struct), reinterpret_cast<xml_memory_page*>(header & xml_memory_page_pointer_mask));
        }
void destroy_node ( xml_node_struct *  n,
xml_allocator alloc 
) [inline]

Definition at line 584 of file pugixml.cpp.

References xml_allocator::deallocate_memory(), xml_allocator::deallocate_string(), destroy_attribute(), xml_memory_page_name_allocated_mask, and xml_memory_page_value_allocated_mask.

        {
                uintptr_t header = n->header;

                if (header & impl::xml_memory_page_name_allocated_mask) alloc.deallocate_string(n->name);
                if (header & impl::xml_memory_page_value_allocated_mask) alloc.deallocate_string(n->value);

                for (xml_attribute_struct* attr = n->first_attribute; attr; )
                {
                        xml_attribute_struct* next = attr->next_attribute;

                        destroy_attribute(attr, alloc);

                        attr = next;
                }

                for (xml_node_struct* child = n->first_child; child; )
                {
                        xml_node_struct* next = child->next_sibling;

                        destroy_node(child, alloc);

                        child = next;
                }

                alloc.deallocate_memory(n, sizeof(xml_node_struct), reinterpret_cast<xml_memory_page*>(header & xml_memory_page_pointer_mask));
        }
PUGI__FN const void* document_order ( const xpath_node &  xnode)

Definition at line 6667 of file pugixml.cpp.

Referenced by document_order_comparator::operator()().

        {
                xml_node_struct* node = xnode.node().internal_object();

                if (node)
                {
                        if (node->name && (node->header & xml_memory_page_name_allocated_mask) == 0) return node->name;
                        if (node->value && (node->header & xml_memory_page_value_allocated_mask) == 0) return node->value;
                        return 0;
                }

                xml_attribute_struct* attr = xnode.attribute().internal_object();

                if (attr)
                {
                        if ((attr->header & xml_memory_page_name_allocated_mask) == 0) return attr->name;
                        if ((attr->header & xml_memory_page_value_allocated_mask) == 0) return attr->value;
                        return 0;
                }

                return 0;
        }
PUGI__NS_END PUGI__NS_BEGIN uint16_t endian_swap ( uint16_t  value) [inline]

Definition at line 752 of file pugixml.cpp.

Referenced by convert_utf_endian_swap(), utf_decoder< Traits, opt_swap >::decode_utf16_block(), and utf_decoder< Traits, opt_swap >::decode_utf32_block().

        {
                return static_cast<uint16_t>(((value & 0xff) << 8) | (value >> 8));
        }
uint32_t endian_swap ( uint32_t  value) [inline]

Definition at line 757 of file pugixml.cpp.

        {
                return ((value & 0xff) << 24) | ((value & 0xff00) << 8) | ((value & 0xff0000) >> 8) | (value >> 24);
        }
PUGI__FN xpath_string evaluate_string_impl ( xpath_query_impl impl,
const xpath_node &  n,
xpath_stack_data sd 
)

Definition at line 10123 of file pugixml.cpp.

References xpath_ast_node::eval_string(), xpath_query_impl::root, and xpath_stack_data::stack.

        {
                if (!impl) return xpath_string();

        #ifdef PUGIXML_NO_EXCEPTIONS
                if (setjmp(sd.error_handler)) return xpath_string();
        #endif

                xpath_context c(n, 1, 1);

                return impl->root->eval_string(c, sd.stack);
        }
PUGI__FN const char_t* find_char ( const char_t *  s,
char_t  c 
)

Definition at line 6545 of file pugixml.cpp.

Referenced by local_name(), namespace_uri_predicate::namespace_uri_predicate(), and translate().

        {
        #ifdef PUGIXML_WCHAR_MODE
                return wcschr(s, c);
        #else
                return strchr(s, c);
        #endif
        }
PUGI__FN const char_t* find_substring ( const char_t *  s,
const char_t *  p 
)

Definition at line 6554 of file pugixml.cpp.

Referenced by xpath_ast_node::eval_boolean(), and xpath_ast_node::eval_string().

        {
        #ifdef PUGIXML_WCHAR_MODE
                // MSVC6 wcsstr bug workaround (if s is empty it always returns 0)
                return (*p == 0) ? s : wcsstr(s, p);
        #else
                return strstr(s, p);
        #endif
        }
PUGI__FN double gen_nan ( )

Definition at line 6754 of file pugixml.cpp.

Referenced by convert_string_to_number().

        {
        #if defined(__STDC_IEC_559__) || ((FLT_RADIX - 0 == 2) && (FLT_MAX_EXP - 0 == 128) && (FLT_MANT_DIG - 0 == 24))
                union { float f; uint32_t i; } u[sizeof(float) == sizeof(uint32_t) ? 1 : -1];
                u[0].i = 0x7fc00000;
                return u[0].f;
        #else
                // fallback
                const volatile double zero = 0.0;
                return zero / zero;
        #endif
        }
xml_allocator& get_allocator ( const xml_node_struct *  node) [inline]

Definition at line 548 of file pugixml.cpp.

References xml_memory_page_pointer_mask.

        {
                assert(node);

                return *reinterpret_cast<xml_memory_page*>(node->header & xml_memory_page_pointer_mask)->allocator;
        }
PUGI__FN xml_encoding get_buffer_encoding ( xml_encoding  encoding,
const void *  contents,
size_t  size 
)

Definition at line 1239 of file pugixml.cpp.

References get_wchar_encoding(), guess_buffer_encoding(), is_little_endian(), and PUGI__DMC_VOLATILE.

Referenced by load_buffer_impl(), load_file_impl(), and load_stream_impl().

        {
                // replace wchar encoding with utf implementation
                if (encoding == encoding_wchar) return get_wchar_encoding();

                // replace utf16 encoding with utf16 with specific endianness
                if (encoding == encoding_utf16) return is_little_endian() ? encoding_utf16_le : encoding_utf16_be;

                // replace utf32 encoding with utf32 with specific endianness
                if (encoding == encoding_utf32) return is_little_endian() ? encoding_utf32_le : encoding_utf32_be;

                // only do autodetection if no explicit encoding is requested
                if (encoding != encoding_auto) return encoding;

                // skip encoding autodetection if input buffer is too small
                if (size < 4) return encoding_utf8;

                // try to guess encoding (based on XML specification, Appendix F.1)
                const uint8_t* data = static_cast<const uint8_t*>(contents);

                PUGI__DMC_VOLATILE uint8_t d0 = data[0], d1 = data[1], d2 = data[2], d3 = data[3];

                return guess_buffer_encoding(d0, d1, d2, d3);
        }
PUGI__FN xml_parse_status get_file_size ( FILE *  file,
size_t &  out_result 
)

Definition at line 3701 of file pugixml.cpp.

Referenced by load_file_impl().

        {
        #if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE)
                // there are 64-bit versions of fseek/ftell, let's use them
                typedef __int64 length_type;

                _fseeki64(file, 0, SEEK_END);
                length_type length = _ftelli64(file);
                _fseeki64(file, 0, SEEK_SET);
        #elif defined(__MINGW32__) && !defined(__NO_MINGW_LFS) && !defined(__STRICT_ANSI__)
                // there are 64-bit versions of fseek/ftell, let's use them
                typedef off64_t length_type;

                fseeko64(file, 0, SEEK_END);
                length_type length = ftello64(file);
                fseeko64(file, 0, SEEK_SET);
        #else
                // if this is a 32-bit OS, long is enough; if this is a unix system, long is 64-bit, which is enough; otherwise we can't do anything anyway.
                typedef long length_type;

                fseek(file, 0, SEEK_END);
                length_type length = ftell(file);
                fseek(file, 0, SEEK_SET);
        #endif

                // check for I/O errors
                if (length < 0) return status_io_error;
                
                // check for overflow
                size_t result = static_cast<size_t>(length);

                if (static_cast<length_type>(result) != length) return status_out_of_memory;

                // finalize
                out_result = result;

                return status_ok;
        }
PUGI__FN int get_integer_base ( const char_t *  value)

Definition at line 3524 of file pugixml.cpp.

References ct_space, and PUGI__IS_CHARTYPE.

Referenced by get_value_int(), and get_value_uint().

        {
                const char_t* s = value;

                while (PUGI__IS_CHARTYPE(*s, ct_space))
                        s++;

                if (*s == '-')
                        s++;

                return (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? 16 : 10;
        }
PUGI__FN size_t get_latin1_7bit_prefix_length ( const uint8_t *  data,
size_t  size 
)

Definition at line 1515 of file pugixml.cpp.

Referenced by convert_buffer_latin1().

        {
                for (size_t i = 0; i < size; ++i)
                        if (data[i] > 127)
                                return i;

                return size;
        }
PUGI__FN bool get_mutable_buffer ( char_t *&  out_buffer,
size_t &  out_length,
const void *  contents,
size_t  size,
bool  is_mutable 
)

Definition at line 1264 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate.

Referenced by convert_buffer(), and convert_buffer_latin1().

        {
                size_t length = size / sizeof(char_t);

                if (is_mutable)
                {
                        out_buffer = static_cast<char_t*>(const_cast<void*>(contents));
                        out_length = length;
                }
                else
                {
                        char_t* buffer = static_cast<char_t*>(xml_memory::allocate((length + 1) * sizeof(char_t)));
                        if (!buffer) return false;

                        memcpy(buffer, contents, length * sizeof(char_t));
                        buffer[length] = 0;

                        out_buffer = buffer;
                        out_length = length + 1;
                }

                return true;
        }

Definition at line 2189 of file pugixml.cpp.

References PUGI__STATIC_ASSERT.

Referenced by xml_parser::parse_tree().

        {
                PUGI__STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20 && parse_wconv_attribute == 0x40 && parse_wnorm_attribute == 0x80);
                
                switch ((optmask >> 4) & 15) // get bitmask for flags (wconv wnorm eol escapes)
                {
                case 0:  return strconv_attribute_impl<opt_false>::parse_simple;
                case 1:  return strconv_attribute_impl<opt_true>::parse_simple;
                case 2:  return strconv_attribute_impl<opt_false>::parse_eol;
                case 3:  return strconv_attribute_impl<opt_true>::parse_eol;
                case 4:  return strconv_attribute_impl<opt_false>::parse_wconv;
                case 5:  return strconv_attribute_impl<opt_true>::parse_wconv;
                case 6:  return strconv_attribute_impl<opt_false>::parse_wconv;
                case 7:  return strconv_attribute_impl<opt_true>::parse_wconv;
                case 8:  return strconv_attribute_impl<opt_false>::parse_wnorm;
                case 9:  return strconv_attribute_impl<opt_true>::parse_wnorm;
                case 10: return strconv_attribute_impl<opt_false>::parse_wnorm;
                case 11: return strconv_attribute_impl<opt_true>::parse_wnorm;
                case 12: return strconv_attribute_impl<opt_false>::parse_wnorm;
                case 13: return strconv_attribute_impl<opt_true>::parse_wnorm;
                case 14: return strconv_attribute_impl<opt_false>::parse_wnorm;
                case 15: return strconv_attribute_impl<opt_true>::parse_wnorm;
                default: assert(false); return 0; // should not get here
                }
        }
PUGI__FN strconv_pcdata_t get_strconv_pcdata ( unsigned int  optmask)

Definition at line 2020 of file pugixml.cpp.

References PUGI__STATIC_ASSERT.

Referenced by xml_parser::parse_tree().

        {
                PUGI__STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20 && parse_trim_pcdata == 0x0800);

                switch (((optmask >> 4) & 3) | ((optmask >> 9) & 4)) // get bitmask for flags (eol escapes trim)
                {
                case 0: return strconv_pcdata_impl<opt_false, opt_false, opt_false>::parse;
                case 1: return strconv_pcdata_impl<opt_false, opt_false, opt_true>::parse;
                case 2: return strconv_pcdata_impl<opt_false, opt_true, opt_false>::parse;
                case 3: return strconv_pcdata_impl<opt_false, opt_true, opt_true>::parse;
                case 4: return strconv_pcdata_impl<opt_true, opt_false, opt_false>::parse;
                case 5: return strconv_pcdata_impl<opt_true, opt_false, opt_true>::parse;
                case 6: return strconv_pcdata_impl<opt_true, opt_true, opt_false>::parse;
                case 7: return strconv_pcdata_impl<opt_true, opt_true, opt_true>::parse;
                default: assert(false); return 0; // should not get here
                }
        }
PUGI__FN size_t get_valid_length ( const char_t *  data,
size_t  length 
)

Definition at line 2961 of file pugixml.cpp.

Referenced by xml_buffered_writer::write().

        {
                assert(length > 4);

                for (size_t i = 1; i <= 4; ++i)
                {
                        uint8_t ch = static_cast<uint8_t>(data[length - i]);

                        // either a standalone character or a leading one
                        if ((ch & 0xc0) != 0x80) return length - i;
                }

                // there are four non-leading characters at the end, sequence tail is broken so might as well process the whole chunk
                return length;
        }
PUGI__FN bool get_value_bool ( const char_t *  value,
bool  def 
)

Definition at line 3585 of file pugixml.cpp.

        {
                if (!value) return def;

                // only look at first char
                char_t first = *value;

                // 1*, t* (true), T* (True), y* (yes), Y* (YES)
                return (first == '1' || first == 't' || first == 'T' || first == 'y' || first == 'Y');
        }
PUGI__FN double get_value_double ( const char_t *  value,
double  def 
)

Definition at line 3563 of file pugixml.cpp.

        {
                if (!value) return def;

        #ifdef PUGIXML_WCHAR_MODE
                return wcstod(value, 0);
        #else
                return strtod(value, 0);
        #endif
        }
PUGI__FN float get_value_float ( const char_t *  value,
float  def 
)

Definition at line 3574 of file pugixml.cpp.

        {
                if (!value) return def;

        #ifdef PUGIXML_WCHAR_MODE
                return static_cast<float>(wcstod(value, 0));
        #else
                return static_cast<float>(strtod(value, 0));
        #endif
        }
PUGI__FN int get_value_int ( const char_t *  value,
int  def 
)

Definition at line 3537 of file pugixml.cpp.

References get_integer_base().

        {
                if (!value) return def;

                int base = get_integer_base(value);

        #ifdef PUGIXML_WCHAR_MODE
                return static_cast<int>(wcstol(value, 0, base));
        #else
                return static_cast<int>(strtol(value, 0, base));
        #endif
        }
PUGI__FN unsigned int get_value_uint ( const char_t *  value,
unsigned int  def 
)

Definition at line 3550 of file pugixml.cpp.

References get_integer_base().

        {
                if (!value) return def;

                int base = get_integer_base(value);

        #ifdef PUGIXML_WCHAR_MODE
                return static_cast<unsigned int>(wcstoul(value, 0, base));
        #else
                return static_cast<unsigned int>(strtoul(value, 0, base));
        #endif
        }
PUGI__FN xpath_variable* get_variable_scratch ( char_t(&)  buffer[32],
xpath_variable_set *  set,
const char_t *  begin,
const char_t *  end 
)

Definition at line 7275 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, and xml_memory_management_function_storage< T >::deallocate.

Referenced by xpath_parser::parse_primary_expression().

        {
                size_t length = static_cast<size_t>(end - begin);
                char_t* scratch = buffer;

                if (length >= sizeof(buffer) / sizeof(buffer[0]))
                {
                        // need to make dummy on-heap copy
                        scratch = static_cast<char_t*>(xml_memory::allocate((length + 1) * sizeof(char_t)));
                        if (!scratch) return 0;
                }

                // copy string to zero-terminated buffer and perform lookup
                memcpy(scratch, begin, length * sizeof(char_t));
                scratch[length] = 0;

                xpath_variable* result = set->get(scratch);

                // free dummy buffer
                if (scratch != buffer) xml_memory::deallocate(scratch);

                return result;
        }
PUGI__FN xml_encoding get_wchar_encoding ( )

Definition at line 1205 of file pugixml.cpp.

References is_little_endian(), and PUGI__STATIC_ASSERT.

Referenced by get_buffer_encoding(), get_write_encoding(), get_write_native_encoding(), and zero_terminate_buffer().

        {
                PUGI__STATIC_ASSERT(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4);

                if (sizeof(wchar_t) == 2)
                        return is_little_endian() ? encoding_utf16_le : encoding_utf16_be;
                else 
                        return is_little_endian() ? encoding_utf32_le : encoding_utf32_be;
        }
PUGI__FN xml_encoding get_write_encoding ( xml_encoding  encoding)

Definition at line 2870 of file pugixml.cpp.

References get_wchar_encoding(), and is_little_endian().

        {
                // replace wchar encoding with utf implementation
                if (encoding == encoding_wchar) return get_wchar_encoding();

                // replace utf16 encoding with utf16 with specific endianness
                if (encoding == encoding_utf16) return is_little_endian() ? encoding_utf16_le : encoding_utf16_be;

                // replace utf32 encoding with utf32 with specific endianness
                if (encoding == encoding_utf32) return is_little_endian() ? encoding_utf32_le : encoding_utf32_be;

                // only do autodetection if no explicit encoding is requested
                if (encoding != encoding_auto) return encoding;

                // assume utf8 encoding
                return encoding_utf8;
        }

Definition at line 2861 of file pugixml.cpp.

References get_wchar_encoding().

Referenced by xml_buffered_writer::flush(), and xml_buffered_writer::write().

        {
        #ifdef PUGIXML_WCHAR_MODE
                return get_wchar_encoding();
        #else
                return encoding_utf8;
        #endif
        }
PUGI__FN xml_encoding guess_buffer_encoding ( uint8_t  d0,
uint8_t  d1,
uint8_t  d2,
uint8_t  d3 
)

Definition at line 1215 of file pugixml.cpp.

Referenced by get_buffer_encoding().

        {
                // look for BOM in first few bytes
                if (d0 == 0 && d1 == 0 && d2 == 0xfe && d3 == 0xff) return encoding_utf32_be;
                if (d0 == 0xff && d1 == 0xfe && d2 == 0 && d3 == 0) return encoding_utf32_le;
                if (d0 == 0xfe && d1 == 0xff) return encoding_utf16_be;
                if (d0 == 0xff && d1 == 0xfe) return encoding_utf16_le;
                if (d0 == 0xef && d1 == 0xbb && d2 == 0xbf) return encoding_utf8;

                // look for <, <? or <?xm in various encodings
                if (d0 == 0 && d1 == 0 && d2 == 0 && d3 == 0x3c) return encoding_utf32_be;
                if (d0 == 0x3c && d1 == 0 && d2 == 0 && d3 == 0) return encoding_utf32_le;
                if (d0 == 0 && d1 == 0x3c && d2 == 0 && d3 == 0x3f) return encoding_utf16_be;
                if (d0 == 0x3c && d1 == 0 && d2 == 0x3f && d3 == 0) return encoding_utf16_le;
                if (d0 == 0x3c && d1 == 0x3f && d2 == 0x78 && d3 == 0x6d) return encoding_utf8;

                // look for utf16 < followed by node name (this may fail, but is better than utf8 since it's zero terminated so early)
                if (d0 == 0 && d1 == 0x3c) return encoding_utf16_be;
                if (d0 == 0x3c && d1 == 0) return encoding_utf16_le;

                // no known BOM detected, assume utf8
                return encoding_utf8;
        }
bool has_declaration ( const xml_node &  node) [inline]

Definition at line 3417 of file pugixml.cpp.

        {
                for (xml_node child = node.first_child(); child; child = child.next_sibling())
                {
                        xml_node_type type = child.type();

                        if (type == node_declaration) return true;
                        if (type == node_element) return false;
                }

                return false;
        }
PUGI__FN unsigned int hash_string ( const char_t *  str)

Definition at line 7188 of file pugixml.cpp.

        {
                // Jenkins one-at-a-time hash (http://en.wikipedia.org/wiki/Jenkins_hash_function#one-at-a-time)
                unsigned int result = 0;

                while (*str)
                {
                        result += static_cast<unsigned int>(*str++);
                        result += result << 10;
                        result ^= result >> 6;
                }
        
                result += result << 3;
                result ^= result >> 11;
                result += result << 15;
        
                return result;
        }
void insert_node_after ( xml_node_struct *  child,
xml_node_struct *  node 
) [inline]

Definition at line 653 of file pugixml.cpp.

        {
                xml_node_struct* parent = node->parent;

                child->parent = parent;

                if (node->next_sibling)
                        node->next_sibling->prev_sibling_c = child;
                else
                        parent->first_child->prev_sibling_c = child;

                child->next_sibling = node->next_sibling;
                child->prev_sibling_c = node;

                node->next_sibling = child;
        }
void insert_node_before ( xml_node_struct *  child,
xml_node_struct *  node 
) [inline]

Definition at line 670 of file pugixml.cpp.

        {
                xml_node_struct* parent = node->parent;

                child->parent = parent;

                if (node->prev_sibling_c->next_sibling)
                        node->prev_sibling_c->next_sibling = child;
                else
                        parent->first_child = child;

                child->prev_sibling_c = node->prev_sibling_c;
                child->next_sibling = node;

                node->prev_sibling_c = child;
        }
template<typename I , typename Pred , typename T >
void insertion_sort ( begin,
end,
const Pred &  pred,
T *   
)

Definition at line 6042 of file pugixml.cpp.

References copy_backwards().

Referenced by sort().

        {
                assert(begin != end);

                for (I it = begin + 1; it != end; ++it)
                {
                        T val = *it;

                        if (pred(val, *begin))
                        {
                                // move to front
                                copy_backwards(begin, it, it + 1);
                                *begin = val;
                        }
                        else
                        {
                                I hole = it;

                                // move hole backwards
                                while (pred(val, *(hole - 1)))
                                {
                                        *hole = *(hole - 1);
                                        hole--;
                                }

                                // fill hole with element
                                *hole = val;
                        }
                }
        }

Definition at line 1198 of file pugixml.cpp.

Referenced by convert_buffer(), convert_buffer_output(), get_buffer_encoding(), get_wchar_encoding(), and get_write_encoding().

        {
                unsigned int ui = 1;

                return *reinterpret_cast<unsigned char*>(&ui) == 1;
        }
PUGI__FN bool is_nan ( double  value)

Definition at line 6767 of file pugixml.cpp.

Referenced by convert_number_to_boolean(), and xpath_ast_node::eval_string().

        {
        #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__)
                return !!_isnan(value);
        #elif defined(fpclassify) && defined(FP_NAN)
                return fpclassify(value) == FP_NAN;
        #else
                // fallback
                const volatile double v = value;
                return v != v;
        #endif
        }
bool is_text_node ( xml_node_struct *  node) [inline]

Definition at line 3516 of file pugixml.cpp.

References xml_memory_page_type_mask.

        {
                xml_node_type type = static_cast<xml_node_type>((node->header & impl::xml_memory_page_type_mask) + 1);

                return type == node_pcdata || type == node_cdata;
        }
PUGI__FN xml_parse_result load_buffer_impl ( xml_document_struct doc,
xml_node_struct *  root,
void *  contents,
size_t  size,
unsigned int  options,
xml_encoding  encoding,
bool  is_mutable,
bool  own,
char_t **  out_buffer 
)

Definition at line 4011 of file pugixml.cpp.

References xml_document_struct::buffer, convert_buffer(), get_buffer_encoding(), and make_parse_result().

        {
                // check input buffer
                assert(contents || size == 0);

                // get actual encoding
                xml_encoding buffer_encoding = impl::get_buffer_encoding(encoding, contents, size);

                // get private buffer
                char_t* buffer = 0;
                size_t length = 0;

                if (!impl::convert_buffer(buffer, length, buffer_encoding, contents, size, is_mutable)) return impl::make_parse_result(status_out_of_memory);
                
                // delete original buffer if we performed a conversion
                if (own && buffer != contents && contents) impl::xml_memory::deallocate(contents);

                // store buffer for offset_debug
                doc->buffer = buffer;

                // parse
                xml_parse_result res = impl::xml_parser::parse(buffer, length, doc, root, options);

                // remember encoding
                res.encoding = buffer_encoding;

                // grab onto buffer if it's our buffer, user is responsible for deallocating contents himself
                if (own || buffer != contents) *out_buffer = buffer;

                return res;
        }
PUGI__FN xml_parse_result load_file_impl ( xml_document &  doc,
FILE *  file,
unsigned int  options,
xml_encoding  encoding 
)

Definition at line 3764 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, xml_memory_management_function_storage< T >::deallocate, get_buffer_encoding(), get_file_size(), make_parse_result(), and zero_terminate_buffer().

        {
                if (!file) return make_parse_result(status_file_not_found);

                // get file size (can result in I/O errors)
                size_t size = 0;
                xml_parse_status size_status = get_file_size(file, size);

                if (size_status != status_ok)
                {
                        fclose(file);
                        return make_parse_result(size_status);
                }
                
                size_t max_suffix_size = sizeof(char_t);

                // allocate buffer for the whole file
                char* contents = static_cast<char*>(xml_memory::allocate(size + max_suffix_size));

                if (!contents)
                {
                        fclose(file);
                        return make_parse_result(status_out_of_memory);
                }

                // read file in memory
                size_t read_size = fread(contents, 1, size, file);
                fclose(file);

                if (read_size != size)
                {
                        xml_memory::deallocate(contents);
                        return make_parse_result(status_io_error);
                }

                xml_encoding real_encoding = get_buffer_encoding(encoding, contents, size);
                
                return doc.load_buffer_inplace_own(contents, zero_terminate_buffer(contents, size, real_encoding), options, real_encoding);
        }
template<typename T >
PUGI__FN xml_parse_status load_stream_data_noseek ( std::basic_istream< T > &  stream,
void **  out_buffer,
size_t *  out_size 
)

Definition at line 3837 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, xml_stream_chunk< T >::create(), buffer_holder::data, xml_stream_chunk< T >::data, xml_stream_chunk< T >::next, and xml_stream_chunk< T >::size.

Referenced by load_stream_impl().

        {
                buffer_holder chunks(0, xml_stream_chunk<T>::destroy);

                // read file to a chunk list
                size_t total = 0;
                xml_stream_chunk<T>* last = 0;

                while (!stream.eof())
                {
                        // allocate new chunk
                        xml_stream_chunk<T>* chunk = xml_stream_chunk<T>::create();
                        if (!chunk) return status_out_of_memory;

                        // append chunk to list
                        if (last) last = last->next = chunk;
                        else chunks.data = last = chunk;

                        // read data to chunk
                        stream.read(chunk->data, static_cast<std::streamsize>(sizeof(chunk->data) / sizeof(T)));
                        chunk->size = static_cast<size_t>(stream.gcount()) * sizeof(T);

                        // read may set failbit | eofbit in case gcount() is less than read length, so check for other I/O errors
                        if (stream.bad() || (!stream.eof() && stream.fail())) return status_io_error;

                        // guard against huge files (chunk size is small enough to make this overflow check work)
                        if (total + chunk->size < total) return status_out_of_memory;
                        total += chunk->size;
                }

                size_t max_suffix_size = sizeof(char_t);

                // copy chunk list to a contiguous buffer
                char* buffer = static_cast<char*>(xml_memory::allocate(total + max_suffix_size));
                if (!buffer) return status_out_of_memory;

                char* write = buffer;

                for (xml_stream_chunk<T>* chunk = static_cast<xml_stream_chunk<T>*>(chunks.data); chunk; chunk = chunk->next)
                {
                        assert(write + chunk->size <= buffer + total);
                        memcpy(write, chunk->data, chunk->size);
                        write += chunk->size;
                }

                assert(write == buffer + total);

                // return buffer
                *out_buffer = buffer;
                *out_size = total;

                return status_ok;
        }
template<typename T >
PUGI__FN xml_parse_status load_stream_data_seek ( std::basic_istream< T > &  stream,
void **  out_buffer,
size_t *  out_size 
)

Definition at line 3891 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, buffer_holder::data, xml_memory_management_function_storage< T >::deallocate, and buffer_holder::release().

Referenced by load_stream_impl().

        {
                // get length of remaining data in stream
                typename std::basic_istream<T>::pos_type pos = stream.tellg();
                stream.seekg(0, std::ios::end);
                std::streamoff length = stream.tellg() - pos;
                stream.seekg(pos);

                if (stream.fail() || pos < 0) return status_io_error;

                // guard against huge files
                size_t read_length = static_cast<size_t>(length);

                if (static_cast<std::streamsize>(read_length) != length || length < 0) return status_out_of_memory;

                size_t max_suffix_size = sizeof(char_t);

                // read stream data into memory (guard against stream exceptions with buffer holder)
                buffer_holder buffer(xml_memory::allocate(read_length * sizeof(T) + max_suffix_size), xml_memory::deallocate);
                if (!buffer.data) return status_out_of_memory;

                stream.read(static_cast<T*>(buffer.data), static_cast<std::streamsize>(read_length));

                // read may set failbit | eofbit in case gcount() is less than read_length (i.e. line ending conversion), so check for other I/O errors
                if (stream.bad() || (!stream.eof() && stream.fail())) return status_io_error;

                // return buffer
                size_t actual_length = static_cast<size_t>(stream.gcount());
                assert(actual_length <= read_length);
                
                *out_buffer = buffer.release();
                *out_size = actual_length * sizeof(T);

                return status_ok;
        }
template<typename T >
PUGI__FN xml_parse_result load_stream_impl ( xml_document &  doc,
std::basic_istream< T > &  stream,
unsigned int  options,
xml_encoding  encoding 
)

Definition at line 3927 of file pugixml.cpp.

References get_buffer_encoding(), load_stream_data_noseek(), load_stream_data_seek(), make_parse_result(), and zero_terminate_buffer().

        {
                void* buffer = 0;
                size_t size = 0;
                xml_parse_status status = status_ok;

                // if stream has an error bit set, bail out (otherwise tellg() can fail and we'll clear error bits)
                if (stream.fail()) return make_parse_result(status_io_error);

                // load stream to memory (using seek-based implementation if possible, since it's faster and takes less memory)
                if (stream.tellg() < 0)
                {
                        stream.clear(); // clear error flags that could be set by a failing tellg
                        status = load_stream_data_noseek(stream, &buffer, &size);
                }
                else
                        status = load_stream_data_seek(stream, &buffer, &size);

                if (status != status_ok) return make_parse_result(status);

                xml_encoding real_encoding = get_buffer_encoding(encoding, buffer, size);
                
                return doc.load_buffer_inplace_own(buffer, zero_terminate_buffer(buffer, size, real_encoding), options, real_encoding);
        }
PUGI__FN const char_t* local_name ( const xpath_node &  node)

Definition at line 7022 of file pugixml.cpp.

References find_char(), and qualified_name().

Referenced by xpath_ast_node::eval_string().

        {
                const char_t* name = qualified_name(node);
                const char_t* p = find_char(name, ':');
                
                return p ? p + 1 : name;
        }
xml_parse_result make_parse_result ( xml_parse_status  status,
ptrdiff_t  offset = 0 
) [inline]

Definition at line 2215 of file pugixml.cpp.

Referenced by load_buffer_impl(), load_file_impl(), load_stream_impl(), and xml_parser::parse().

        {
                xml_parse_result result;
                result.status = status;
                result.offset = offset;

                return result;
        }
template<typename I , typename Pred >
void median ( first,
middle,
last,
const Pred &  pred 
)

Definition at line 6134 of file pugixml.cpp.

References median3().

Referenced by sort().

        {
                if (last - first <= 40)
                {
                        // median of three for small chunks
                        median3(first, middle, last, pred);
                }
                else
                {
                        // median of nine
                        size_t step = (last - first + 1) / 8;

                        median3(first, first + step, first + 2 * step, pred);
                        median3(middle - step, middle, middle + step, pred);
                        median3(last - 2 * step, last - step, last, pred);
                        median3(first + step, middle, last - step, pred);
                }
        }
template<typename I , typename Pred >
void median3 ( first,
middle,
last,
const Pred &  pred 
)

Definition at line 6127 of file pugixml.cpp.

References swap().

Referenced by median().

        {
                if (pred(*middle, *first)) swap(*middle, *first);
                if (pred(*last, *middle)) swap(*last, *middle);
                if (pred(*middle, *first)) swap(*middle, *first);
        }
template<typename I , typename Pred >
I min_element ( begin,
end,
const Pred &  pred 
)

Definition at line 5998 of file pugixml.cpp.

Referenced by xpath_first().

        {
                I result = begin;

                for (I it = begin + 1; it != end; ++it)
                        if (pred(*it, *result))
                                result = it;

                return result;
        }
PUGI__FN const char_t* namespace_uri ( const xml_node &  node)

Definition at line 7053 of file pugixml.cpp.

Referenced by xpath_ast_node::eval_string(), and namespace_uri().

        {
                namespace_uri_predicate pred = node.name();
                
                xml_node p = node;
                
                while (p)
                {
                        xml_attribute a = p.find_attribute(pred);
                        
                        if (a) return a.value();
                        
                        p = p.parent();
                }
                
                return PUGIXML_TEXT("");
        }
PUGI__FN const char_t* namespace_uri ( const xml_attribute &  attr,
const xml_node &  parent 
)

Definition at line 7071 of file pugixml.cpp.

References namespace_uri_predicate::prefix.

        {
                namespace_uri_predicate pred = attr.name();
                
                // Default namespace does not apply to attributes
                if (!pred.prefix) return PUGIXML_TEXT("");
                
                xml_node p = parent;
                
                while (p)
                {
                        xml_attribute a = p.find_attribute(pred);
                        
                        if (a) return a.value();
                        
                        p = p.parent();
                }
                
                return PUGIXML_TEXT("");
        }
PUGI__FN const char_t* namespace_uri ( const xpath_node &  node)

Definition at line 7092 of file pugixml.cpp.

References namespace_uri().

        {
                return node.attribute() ? namespace_uri(node.attribute(), node.parent()) : namespace_uri(node.node());
        }
template<typename T >
PUGI__FN T* new_xpath_variable ( const char_t *  name)

Definition at line 7207 of file pugixml.cpp.

References xml_memory_management_function_storage< T >::allocate, and strlength().

        {
                size_t length = strlength(name);
                if (length == 0) return 0; // empty variable names are invalid

                // $$ we can't use offsetof(T, name) because T is non-POD, so we just allocate additional length characters
                void* memory = xml_memory::allocate(sizeof(T) + length * sizeof(char_t));
                if (!memory) return 0;

                T* result = new (memory) T();

                memcpy(result->name, name, (length + 1) * sizeof(char_t));

                return result;
        }
PUGI__FN xpath_variable* new_xpath_variable ( xpath_value_type  type,
const char_t *  name 
)

Definition at line 7223 of file pugixml.cpp.

        {
                switch (type)
                {
                case xpath_type_node_set:
                        return new_xpath_variable<xpath_variable_node_set>(name);

                case xpath_type_number:
                        return new_xpath_variable<xpath_variable_number>(name);

                case xpath_type_string:
                        return new_xpath_variable<xpath_variable_string>(name);

                case xpath_type_boolean:
                        return new_xpath_variable<xpath_variable_boolean>(name);

                default:
                        return 0;
                }
        }
PUGI__FN unsigned int node_height ( xml_node  n)

Definition at line 6620 of file pugixml.cpp.

Referenced by document_order_comparator::operator()().

        {
                unsigned int result = 0;
                
                while (n)
                {
                        ++result;
                        n = n.parent();
                }
                
                return result;
        }
PUGI__FN bool node_is_ancestor ( xml_node  parent,
xml_node  node 
)

Definition at line 6660 of file pugixml.cpp.

Referenced by xpath_ast_node::step_fill().

        {
                while (node && node != parent) node = node.parent();

                return parent && node == parent;
        }
PUGI__FN bool node_is_before ( xml_node  ln,
unsigned int  lh,
xml_node  rn,
unsigned int  rh 
)

Definition at line 6633 of file pugixml.cpp.

Referenced by document_order_comparator::operator()().

        {
                // normalize heights
                for (unsigned int i = rh; i < lh; i++) ln = ln.parent();
                for (unsigned int j = lh; j < rh; j++) rn = rn.parent();
                
                // one node is the ancestor of the other
                if (ln == rn) return lh < rh;
                
                // find common ancestor
                while (ln.parent() != rn.parent())
                {
                        ln = ln.parent();
                        rn = rn.parent();
                }

                // there is no common ancestor (the shared parent is null), nodes are from different documents
                if (!ln.parent()) return ln < rn;

                // determine sibling order
                for (; ln; ln = ln.next_sibling())
                        if (ln == rn)
                                return true;
                                
                return false;
        }
PUGI__FN void node_output ( xml_buffered_writer writer,
const xml_node &  node,
const char_t *  indent,
unsigned int  flags,
unsigned int  depth 
)

Definition at line 3288 of file pugixml.cpp.

References ctx_special_pcdata, node_output_attributes(), text_output(), text_output_cdata(), and xml_buffered_writer::write().

        {
                const char_t* default_name = PUGIXML_TEXT(":anonymous");

                if ((flags & format_indent) != 0 && (flags & format_raw) == 0)
                        for (unsigned int i = 0; i < depth; ++i) writer.write(indent);

                switch (node.type())
                {
                case node_document:
                {
                        for (xml_node n = node.first_child(); n; n = n.next_sibling())
                                node_output(writer, n, indent, flags, depth);
                        break;
                }
                        
                case node_element:
                {
                        const char_t* name = node.name()[0] ? node.name() : default_name;

                        writer.write('<');
                        writer.write(name);

                        node_output_attributes(writer, node, flags);

                        if (flags & format_raw)
                        {
                                if (!node.first_child())
                                        writer.write(' ', '/', '>');
                                else
                                {
                                        writer.write('>');

                                        for (xml_node n = node.first_child(); n; n = n.next_sibling())
                                                node_output(writer, n, indent, flags, depth + 1);

                                        writer.write('<', '/');
                                        writer.write(name);
                                        writer.write('>');
                                }
                        }
                        else if (!node.first_child())
                                writer.write(' ', '/', '>', '\n');
                        else if (node.first_child() == node.last_child() && (node.first_child().type() == node_pcdata || node.first_child().type() == node_cdata))
                        {
                                writer.write('>');

                                if (node.first_child().type() == node_pcdata)
                                        text_output(writer, node.first_child().value(), ctx_special_pcdata, flags);
                                else
                                        text_output_cdata(writer, node.first_child().value());

                                writer.write('<', '/');
                                writer.write(name);
                                writer.write('>', '\n');
                        }
                        else
                        {
                                writer.write('>', '\n');
                                
                                for (xml_node n = node.first_child(); n; n = n.next_sibling())
                                        node_output(writer, n, indent, flags, depth + 1);

                                if ((flags & format_indent) != 0 && (flags & format_raw) == 0)
                                        for (unsigned int i = 0; i < depth; ++i) writer.write(indent);
                                
                                writer.write('<', '/');
                                writer.write(name);
                                writer.write('>', '\n');
                        }

                        break;
                }
                
                case node_pcdata:
                        text_output(writer, node.value(), ctx_special_pcdata, flags);
                        if ((flags & format_raw) == 0) writer.write('\n');
                        break;

                case node_cdata:
                        text_output_cdata(writer, node.value());
                        if ((flags & format_raw) == 0) writer.write('\n');
                        break;

                case node_comment:
                        writer.write('<', '!', '-', '-');
                        writer.write(node.value());
                        writer.write('-', '-', '>');
                        if ((flags & format_raw) == 0) writer.write('\n');
                        break;

                case node_pi:
                case node_declaration:
                        writer.write('<', '?');
                        writer.write(node.name()[0] ? node.name() : default_name);

                        if (node.type() == node_declaration)
                        {
                                node_output_attributes(writer, node, flags);
                        }
                        else if (node.value()[0])
                        {
                                writer.write(' ');
                                writer.write(node.value());
                        }

                        writer.write('?', '>');
                        if ((flags & format_raw) == 0) writer.write('\n');
                        break;

                case node_doctype:
                        writer.write('<', '!', 'D', 'O', 'C');
                        writer.write('T', 'Y', 'P', 'E');

                        if (node.value()[0])
                        {
                                writer.write(' ');
                                writer.write(node.value());
                        }

                        writer.write('>');
                        if ((flags & format_raw) == 0) writer.write('\n');
                        break;

                default:
                        assert(!"Invalid node type");
                }
        }
PUGI__FN void node_output_attributes ( xml_buffered_writer writer,
const xml_node &  node,
unsigned int  flags 
)

Definition at line 3272 of file pugixml.cpp.

References ctx_special_attr, text_output(), and xml_buffered_writer::write().

Referenced by node_output().

        {
                const char_t* default_name = PUGIXML_TEXT(":anonymous");

                for (xml_attribute a = node.first_attribute(); a; a = a.next_attribute())
                {
                        writer.write(' ');
                        writer.write(a.name()[0] ? a.name() : default_name);
                        writer.write('=', '"');

                        text_output(writer, a.value(), ctx_special_attr, flags);

                        writer.write('"');
                }
        }
PUGI__FN void normalize_space ( char_t *  buffer)

Definition at line 7097 of file pugixml.cpp.

References ct_space, and PUGI__IS_CHARTYPE.

Referenced by xpath_ast_node::eval_string().

        {
                char_t* write = buffer;

                for (char_t* it = buffer; *it; )
                {
                        char_t ch = *it++;

                        if (PUGI__IS_CHARTYPE(ch, ct_space))
                        {
                                // replace whitespace sequence with single space
                                while (PUGI__IS_CHARTYPE(*it, ct_space)) it++;

                                // avoid leading spaces
                                if (write != buffer) *write++ = ' ';
                        }
                        else *write++ = ch;
                }

                // remove trailing space
                if (write != buffer && PUGI__IS_CHARTYPE(write[-1], ct_space)) write--;

                // zero-terminate
                *write = 0;
        }
PUGI__FN FILE* open_file_wide ( const wchar_t *  path,
const wchar_t *  mode 
)

Definition at line 3977 of file pugixml.cpp.

References convert_path_heap(), and xml_memory_management_function_storage< T >::deallocate.

        {
                // there is no standard function to open wide paths, so our best bet is to try utf8 path
                char* path_utf8 = convert_path_heap(path);
                if (!path_utf8) return 0;

                // convert mode to ASCII (we mirror _wfopen interface)
                char mode_ascii[4] = {0};
                for (size_t i = 0; mode[i]; ++i) mode_ascii[i] = static_cast<char>(mode[i]);

                // try to open the utf8 path
                FILE* result = fopen(path_utf8, mode_ascii);

                // free dummy buffer
                xml_memory::deallocate(path_utf8);

                return result;
        }
template<typename I , typename Pred >
void partition ( begin,
middle,
end,
const Pred &  pred,
I *  out_eqbeg,
I *  out_eqend 
)

Definition at line 6074 of file pugixml.cpp.

References swap().

Referenced by sort().

        {
                I eqbeg = middle, eqend = middle + 1;

                // expand equal range
                while (eqbeg != begin && *(eqbeg - 1) == *eqbeg) --eqbeg;
                while (eqend != end && *eqend == *eqbeg) ++eqend;

                // process outer elements
                I ltend = eqbeg, gtbeg = eqend;

                for (;;)
                {
                        // find the element from the right side that belongs to the left one
                        for (; gtbeg != end; ++gtbeg)
                                if (!pred(*eqbeg, *gtbeg))
                                {
                                        if (*gtbeg == *eqbeg) swap(*gtbeg, *eqend++);
                                        else break;
                                }

                        // find the element from the left side that belongs to the right one
                        for (; ltend != begin; --ltend)
                                if (!pred(*(ltend - 1), *eqbeg))
                                {
                                        if (*eqbeg == *(ltend - 1)) swap(*(ltend - 1), *--eqbeg);
                                        else break;
                                }

                        // scanned all elements
                        if (gtbeg == end && ltend == begin)
                        {
                                *out_eqbeg = eqbeg;
                                *out_eqend = eqend;
                                return;
                        }

                        // make room for elements by moving equal area
                        if (gtbeg == end)
                        {
                                if (--ltend != --eqbeg) swap(*ltend, *eqbeg);
                                swap(*eqbeg, *--eqend);
                        }
                        else if (ltend == begin)
                        {
                                if (eqend != gtbeg) swap(*eqbeg, *eqend);
                                ++eqend;
                                swap(*gtbeg++, *eqbeg++);
                        }
                        else swap(*gtbeg++, *--ltend);
                }
        }
void prepend_node ( xml_node_struct *  child,
xml_node_struct *  node 
) [inline]

Definition at line 635 of file pugixml.cpp.

        {
                child->parent = node;

                xml_node_struct* head = node->first_child;

                if (head)
                {
                        child->prev_sibling_c = head->prev_sibling_c;
                        head->prev_sibling_c = child;
                }
                else
                        child->prev_sibling_c = child;

                child->next_sibling = head;
                node->first_child = child;
        }
PUGI__FN const char_t* qualified_name ( const xpath_node &  node)

Definition at line 7017 of file pugixml.cpp.

Referenced by xpath_ast_node::eval_string(), and local_name().

        {
                return node.attribute() ? node.attribute().name() : node.node().name();
        }
PUGI__FN void recursive_copy_skip ( xml_node &  dest,
const xml_node &  source,
const xml_node &  skip 
)

Definition at line 3463 of file pugixml.cpp.

        {
                assert(dest.type() == source.type());

                switch (source.type())
                {
                case node_element:
                {
                        dest.set_name(source.name());

                        for (xml_attribute a = source.first_attribute(); a; a = a.next_attribute())
                                dest.append_attribute(a.name()).set_value(a.value());

                        for (xml_node c = source.first_child(); c; c = c.next_sibling())
                        {
                                if (c == skip) continue;

                                xml_node cc = dest.append_child(c.type());
                                assert(cc);

                                recursive_copy_skip(cc, c, skip);
                        }

                        break;
                }

                case node_pcdata:
                case node_cdata:
                case node_comment:
                case node_doctype:
                        dest.set_value(source.value());
                        break;

                case node_pi:
                        dest.set_name(source.name());
                        dest.set_value(source.value());
                        break;

                case node_declaration:
                {
                        dest.set_name(source.name());

                        for (xml_attribute a = source.first_attribute(); a; a = a.next_attribute())
                                dest.append_attribute(a.name()).set_value(a.value());

                        break;
                }

                default:
                        assert(!"Invalid node type");
                }
        }
void remove_node ( xml_node_struct *  node) [inline]

Definition at line 687 of file pugixml.cpp.

        {
                xml_node_struct* parent = node->parent;

                if (node->next_sibling)
                        node->next_sibling->prev_sibling_c = node->prev_sibling_c;
                else if (parent->first_child)
                        parent->first_child->prev_sibling_c = node->prev_sibling_c;

                if (node->prev_sibling_c->next_sibling)
                        node->prev_sibling_c->next_sibling = node->next_sibling;
                else
                        parent->first_child = node->next_sibling;
        }
template<typename I >
void reverse ( begin,
end 
)

Definition at line 6009 of file pugixml.cpp.

References swap().

Referenced by xpath_sort().

        {
                while (end - begin > 1) swap(*begin++, *--end);
        }
PUGI__FN double round_nearest ( double  value)

Definition at line 7005 of file pugixml.cpp.

Referenced by xpath_ast_node::eval_string().

        {
                return floor(value + 0.5);
        }
PUGI__FN double round_nearest_nzero ( double  value)

Definition at line 7010 of file pugixml.cpp.

Referenced by xpath_ast_node::eval_number().

        {
                // same as round_nearest, but returns -0 for [-0.5, -0]
                // ceil is used to differentiate between +0 and -0 (we return -0 for [-0.5, -0] and +0 for +0)
                return (value >= -0.5 && value <= 0) ? ceil(value) : floor(value + 0.5);
        }
PUGI__FN bool save_file_impl ( const xml_document &  doc,
FILE *  file,
const char_t *  indent,
unsigned int  flags,
xml_encoding  encoding 
)

Definition at line 3997 of file pugixml.cpp.

        {
                if (!file) return false;

                xml_writer_file writer(file);
                doc.save(writer, indent, flags, encoding);

                int result = ferror(file);

                fclose(file);

                return result == 0;
        }
PUGI__FN bool set_value_buffer ( char_t *&  dest,
uintptr_t &  header,
uintptr_t  header_mask,
char(&)  buf[128] 
)

Definition at line 3641 of file pugixml.cpp.

References strcpy_insitu().

Referenced by set_value_convert().

        {
        #ifdef PUGIXML_WCHAR_MODE
                char_t wbuf[128];
                impl::widen_ascii(wbuf, buf);

                return strcpy_insitu(dest, header, header_mask, wbuf);
        #else
                return strcpy_insitu(dest, header, header_mask, buf);
        #endif
        }
PUGI__FN bool set_value_convert ( char_t *&  dest,
uintptr_t &  header,
uintptr_t  header_mask,
int  value 
)

Definition at line 3653 of file pugixml.cpp.

References set_value_buffer().

        {
                char buf[128];
                sprintf(buf, "%d", value);
        
                return set_value_buffer(dest, header, header_mask, buf);
        }
PUGI__FN bool set_value_convert ( char_t *&  dest,
uintptr_t &  header,
uintptr_t  header_mask,
unsigned int  value 
)

Definition at line 3661 of file pugixml.cpp.

References set_value_buffer().

        {
                char buf[128];
                sprintf(buf, "%u", value);

                return set_value_buffer(dest, header, header_mask, buf);
        }
PUGI__FN bool set_value_convert ( char_t *&  dest,
uintptr_t &  header,
uintptr_t  header_mask,
double  value 
)

Definition at line 3669 of file pugixml.cpp.

References set_value_buffer().

        {
                char buf[128];
                sprintf(buf, "%g", value);

                return set_value_buffer(dest, header, header_mask, buf);
        }
PUGI__FN bool set_value_convert ( char_t *&  dest,
uintptr_t &  header,
uintptr_t  header_mask,
bool  value 
)

Definition at line 3677 of file pugixml.cpp.

References strcpy_insitu().

        {
                return strcpy_insitu(dest, header, header_mask, value ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false"));
        }
template<typename I , typename Pred >
void sort ( begin,
end,
const Pred &  pred 
)

Definition at line 6153 of file pugixml.cpp.

References insertion_sort(), median(), and partition().

Referenced by xpath_node_set_raw::remove_duplicates(), and xpath_sort().

        {
                // sort large chunks
                while (end - begin > 32)
                {
                        // find median element
                        I middle = begin + (end - begin) / 2;
                        median(begin, middle, end - 1, pred);

                        // partition in three chunks (< = >)
                        I eqbeg, eqend;
                        partition(begin, middle, end, pred, &eqbeg, &eqend);

                        // loop on larger half
                        if (eqbeg - begin > end - eqend)
                        {
                                sort(eqend, end, pred);
                                end = eqbeg;
                        }
                        else
                        {
                                sort(begin, eqbeg, pred);
                                begin = eqend;
                        }
                }

                // insertion sort small chunk
                if (begin != end) insertion_sort(begin, end, pred, &*begin);
        }
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN bool starts_with ( const char_t *  string,
const char_t *  pattern 
)

Definition at line 6534 of file pugixml.cpp.

Referenced by xpath_ast_node::eval_boolean(), namespace_uri_predicate::operator()(), and xpath_ast_node::step_push().

        {
                while (*pattern && *string == *pattern)
                {
                        string++;
                        pattern++;
                }

                return *pattern == 0;
        }
PUGI__FN char_t* strconv_cdata ( char_t *  s,
char_t  endch 
)

Definition at line 1939 of file pugixml.cpp.

References ct_parse_cdata, gap::flush(), PUGI__ENDSWITH, PUGI__IS_CHARTYPE, PUGI__SCANWHILE_UNROLL, and gap::push().

Referenced by xml_parser::parse_exclamation().

        {
                gap g;
                        
                while (true)
                {
                        PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPE(*s, ct_parse_cdata));
                        
                        if (*s == '\r') // Either a single 0x0d or 0x0d 0x0a pair
                        {
                                *s++ = '\n'; // replace first one with 0x0a
                                
                                if (*s == '\n') g.push(s, 1);
                        }
                        else if (s[0] == ']' && s[1] == ']' && PUGI__ENDSWITH(s[2], '>')) // CDATA ends here
                        {
                                *g.flush(s) = 0;
                                
                                return s + 1;
                        }
                        else if (*s == 0)
                        {
                                return 0;
                        }
                        else ++s;
                }
        }
PUGI__FN char_t* strconv_comment ( char_t *  s,
char_t  endch 
)

Definition at line 1911 of file pugixml.cpp.

References ct_parse_comment, gap::flush(), PUGI__ENDSWITH, PUGI__IS_CHARTYPE, PUGI__SCANWHILE_UNROLL, and gap::push().

Referenced by xml_parser::parse_exclamation().

        {
                gap g;
                
                while (true)
                {
                        PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPE(*s, ct_parse_comment));
                
                        if (*s == '\r') // Either a single 0x0d or 0x0d 0x0a pair
                        {
                                *s++ = '\n'; // replace first one with 0x0a
                                
                                if (*s == '\n') g.push(s, 1);
                        }
                        else if (s[0] == '-' && s[1] == '-' && PUGI__ENDSWITH(s[2], '>')) // comment ends here
                        {
                                *g.flush(s) = 0;
                                
                                return s + (s[2] == '>' ? 3 : 2);
                        }
                        else if (*s == 0)
                        {
                                return 0;
                        }
                        else ++s;
                }
        }
PUGI__FN char_t* strconv_escape ( char_t *  s,
gap g 
)

Definition at line 1758 of file pugixml.cpp.

References utf8_writer::any(), and gap::push().

Referenced by strconv_pcdata_impl< opt_trim, opt_eol, opt_escape >::parse(), strconv_attribute_impl< opt_escape >::parse_eol(), strconv_attribute_impl< opt_escape >::parse_simple(), strconv_attribute_impl< opt_escape >::parse_wconv(), and strconv_attribute_impl< opt_escape >::parse_wnorm().

        {
                char_t* stre = s + 1;

                switch (*stre)
                {
                        case '#':       // &#...
                        {
                                unsigned int ucsc = 0;

                                if (stre[1] == 'x') // &#x... (hex code)
                                {
                                        stre += 2;

                                        char_t ch = *stre;

                                        if (ch == ';') return stre;

                                        for (;;)
                                        {
                                                if (static_cast<unsigned int>(ch - '0') <= 9)
                                                        ucsc = 16 * ucsc + (ch - '0');
                                                else if (static_cast<unsigned int>((ch | ' ') - 'a') <= 5)
                                                        ucsc = 16 * ucsc + ((ch | ' ') - 'a' + 10);
                                                else if (ch == ';')
                                                        break;
                                                else // cancel
                                                        return stre;

                                                ch = *++stre;
                                        }
                                        
                                        ++stre;
                                }
                                else    // &#... (dec code)
                                {
                                        char_t ch = *++stre;

                                        if (ch == ';') return stre;

                                        for (;;)
                                        {
                                                if (static_cast<unsigned int>(static_cast<unsigned int>(ch) - '0') <= 9)
                                                        ucsc = 10 * ucsc + (ch - '0');
                                                else if (ch == ';')
                                                        break;
                                                else // cancel
                                                        return stre;

                                                ch = *++stre;
                                        }
                                        
                                        ++stre;
                                }

                        #ifdef PUGIXML_WCHAR_MODE
                                s = reinterpret_cast<char_t*>(wchar_writer::any(reinterpret_cast<wchar_writer::value_type>(s), ucsc));
                        #else
                                s = reinterpret_cast<char_t*>(utf8_writer::any(reinterpret_cast<uint8_t*>(s), ucsc));
                        #endif
                                        
                                g.push(s, stre - s);
                                return stre;
                        }

                        case 'a':       // &a
                        {
                                ++stre;

                                if (*stre == 'm') // &am
                                {
                                        if (*++stre == 'p' && *++stre == ';') // &amp;
                                        {
                                                *s++ = '&';
                                                ++stre;
                                                        
                                                g.push(s, stre - s);
                                                return stre;
                                        }
                                }
                                else if (*stre == 'p') // &ap
                                {
                                        if (*++stre == 'o' && *++stre == 's' && *++stre == ';') // &apos;
                                        {
                                                *s++ = '\'';
                                                ++stre;

                                                g.push(s, stre - s);
                                                return stre;
                                        }
                                }
                                break;
                        }

                        case 'g': // &g
                        {
                                if (*++stre == 't' && *++stre == ';') // &gt;
                                {
                                        *s++ = '>';
                                        ++stre;
                                        
                                        g.push(s, stre - s);
                                        return stre;
                                }
                                break;
                        }

                        case 'l': // &l
                        {
                                if (*++stre == 't' && *++stre == ';') // &lt;
                                {
                                        *s++ = '<';
                                        ++stre;
                                                
                                        g.push(s, stre - s);
                                        return stre;
                                }
                                break;
                        }

                        case 'q': // &q
                        {
                                if (*++stre == 'u' && *++stre == 'o' && *++stre == 't' && *++stre == ';') // &quot;
                                {
                                        *s++ = '"';
                                        ++stre;
                                        
                                        g.push(s, stre - s);
                                        return stre;
                                }
                                break;
                        }

                        default:
                                break;
                }
                
                return stre;
        }
PUGI__FN bool strcpy_insitu ( char_t *&  dest,
uintptr_t &  header,
uintptr_t  header_mask,
const char_t *  source 
)

Definition at line 1668 of file pugixml.cpp.

References xml_allocator::allocate_string(), xml_allocator::deallocate_string(), strcpy_insitu_allow(), strlength(), and xml_memory_page_pointer_mask.

Referenced by set_value_buffer(), and set_value_convert().

        {
                assert(header);

                size_t source_length = strlength(source);

                if (source_length == 0)
                {
                        // empty string and null pointer are equivalent, so just deallocate old memory
                        xml_allocator* alloc = reinterpret_cast<xml_memory_page*>(header & xml_memory_page_pointer_mask)->allocator;

                        if (header & header_mask) alloc->deallocate_string(dest);
                        
                        // mark the string as not allocated
                        dest = 0;
                        header &= ~header_mask;

                        return true;
                }
                else if (dest && strcpy_insitu_allow(source_length, header & header_mask, dest))
                {
                        // we can reuse old buffer, so just copy the new data (including zero terminator)
                        memcpy(dest, source, (source_length + 1) * sizeof(char_t));
                        
                        return true;
                }
                else
                {
                        xml_allocator* alloc = reinterpret_cast<xml_memory_page*>(header & xml_memory_page_pointer_mask)->allocator;

                        // allocate new buffer
                        char_t* buf = alloc->allocate_string(source_length + 1);
                        if (!buf) return false;

                        // copy the string (including zero terminator)
                        memcpy(buf, source, (source_length + 1) * sizeof(char_t));

                        // deallocate old buffer (*after* the above to protect against overlapping memory and/or allocation failures)
                        if (header & header_mask) alloc->deallocate_string(dest);
                        
                        // the string is now allocated, so set the flag
                        dest = buf;
                        header |= header_mask;

                        return true;
                }
        }
bool strcpy_insitu_allow ( size_t  length,
uintptr_t  allocated,
char_t *  target 
) [inline]

Definition at line 1654 of file pugixml.cpp.

References strlength().

Referenced by strcpy_insitu().

        {
                assert(target);
                size_t target_length = strlength(target);

                // always reuse document buffer memory if possible
                if (!allocated) return target_length >= length;

                // reuse heap memory if waste is not too great
                const size_t reuse_threshold = 32;

                return target_length >= length && (target_length < reuse_threshold || target_length - length < target_length / 2);
        }
PUGI__FN bool strequal ( const char_t *  src,
const char_t *  dst 
)

Definition at line 188 of file pugixml.cpp.

Referenced by xpath_string::operator!=(), xpath_string::operator==(), and xpath_ast_node::step_push().

        {
                assert(src && dst);

        #ifdef PUGIXML_WCHAR_MODE
                return wcscmp(src, dst) == 0;
        #else
                return strcmp(src, dst) == 0;
        #endif
        }
PUGI__FN bool strequalrange ( const char_t *  lhs,
const char_t *  rhs,
size_t  count 
)

Definition at line 200 of file pugixml.cpp.

Referenced by namespace_uri_predicate::operator()(), and xpath_lexer_string::operator==().

        {
                for (size_t i = 0; i < count; ++i)
                        if (lhs[i] != rhs[i])
                                return false;
        
                return lhs[count] == 0;
        }
PUGI__FN xpath_string string_value ( const xpath_node &  na,
xpath_allocator alloc 
)

Definition at line 6570 of file pugixml.cpp.

References xpath_string::append(), and xpath_string_const().

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

        {
                if (na.attribute())
                        return xpath_string_const(na.attribute().value());
                else
                {
                        const xml_node& n = na.node();

                        switch (n.type())
                        {
                        case node_pcdata:
                        case node_cdata:
                        case node_comment:
                        case node_pi:
                                return xpath_string_const(n.value());
                        
                        case node_document:
                        case node_element:
                        {
                                xpath_string result;

                                xml_node cur = n.first_child();
                                
                                while (cur && cur != n)
                                {
                                        if (cur.type() == node_pcdata || cur.type() == node_cdata)
                                                result.append(xpath_string_const(cur.value()), alloc);

                                        if (cur.first_child())
                                                cur = cur.first_child();
                                        else if (cur.next_sibling())
                                                cur = cur.next_sibling();
                                        else
                                        {
                                                while (!cur.next_sibling() && cur != n)
                                                        cur = cur.parent();

                                                if (cur != n) cur = cur.next_sibling();
                                        }
                                }
                                
                                return result;
                        }
                        
                        default:
                                return xpath_string();
                        }
                }
        }
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN size_t strlength ( const char_t *  s)

Definition at line 176 of file pugixml.cpp.

Referenced by xpath_string::append(), xpath_string::duplicate_string(), xpath_string::length(), new_xpath_variable(), strcpy_insitu(), strcpy_insitu_allow(), translate(), and xml_buffered_writer::write().

        {
                assert(s);

        #ifdef PUGIXML_WCHAR_MODE
                return wcslen(s);
        #else
                return strlen(s);
        #endif
        }
PUGI__FN size_t strlength_wide ( const wchar_t *  s)

Definition at line 210 of file pugixml.cpp.

Referenced by pugi::as_utf8(), and convert_path_heap().

        {
                assert(s);

        #ifdef PUGIXML_WCHAR_MODE
                return wcslen(s);
        #else
                const wchar_t* end = s;
                while (*end) end++;
                return static_cast<size_t>(end - s);
        #endif
        }
template<typename T >
void swap ( T &  lhs,
T &  rhs 
)

Definition at line 5991 of file pugixml.cpp.

Referenced by xpath_ast_node::compare_eq(), median3(), partition(), and reverse().

        {
                T temp = lhs;
                lhs = rhs;
                rhs = temp;
        }
PUGI__FN void text_output ( xml_buffered_writer writer,
const char_t *  s,
chartypex_t  type,
unsigned int  flags 
)

Definition at line 3242 of file pugixml.cpp.

References text_output_escaped(), and xml_buffered_writer::write().

Referenced by node_output(), and node_output_attributes().

        {
                if (flags & format_no_escapes)
                        writer.write(s);
                else
                        text_output_escaped(writer, s, type);
        }
PUGI__FN void text_output_cdata ( xml_buffered_writer writer,
const char_t *  s 
)

Definition at line 3250 of file pugixml.cpp.

References xml_buffered_writer::write().

Referenced by node_output().

        {
                do
                {
                        writer.write('<', '!', '[', 'C', 'D');
                        writer.write('A', 'T', 'A', '[');

                        const char_t* prev = s;

                        // look for ]]> sequence - we can't output it as is since it terminates CDATA
                        while (*s && !(s[0] == ']' && s[1] == ']' && s[2] == '>')) ++s;

                        // skip ]] if we stopped at ]]>, > will go to the next CDATA section
                        if (*s) s += 2;

                        writer.write(prev, static_cast<size_t>(s - prev));

                        writer.write(']', ']', '>');
                }
                while (*s);
        }
PUGI__FN void text_output_escaped ( xml_buffered_writer writer,
const char_t *  s,
chartypex_t  type 
)

Definition at line 3201 of file pugixml.cpp.

References PUGI__IS_CHARTYPEX, and xml_buffered_writer::write().

Referenced by text_output().

        {
                while (*s)
                {
                        const char_t* prev = s;
                        
                        // While *s is a usual symbol
                        while (!PUGI__IS_CHARTYPEX(*s, type)) ++s;
                
                        writer.write(prev, static_cast<size_t>(s - prev));

                        switch (*s)
                        {
                                case 0: break;
                                case '&':
                                        writer.write('&', 'a', 'm', 'p', ';');
                                        ++s;
                                        break;
                                case '<':
                                        writer.write('&', 'l', 't', ';');
                                        ++s;
                                        break;
                                case '>':
                                        writer.write('&', 'g', 't', ';');
                                        ++s;
                                        break;
                                case '"':
                                        writer.write('&', 'q', 'u', 'o', 't', ';');
                                        ++s;
                                        break;
                                default: // s is not a usual symbol
                                {
                                        unsigned int ch = static_cast<unsigned int>(*s++);
                                        assert(ch < 32);

                                        writer.write('&', '#', static_cast<char_t>((ch / 10) + '0'), static_cast<char_t>((ch % 10) + '0'), ';');
                                }
                        }
                }
        }
PUGI__FN char_t tolower_ascii ( char_t  ch)

Definition at line 6565 of file pugixml.cpp.

Referenced by xpath_ast_node::eval_boolean().

        {
                return static_cast<unsigned int>(ch - 'A') < 26 ? static_cast<char_t>(ch | ' ') : ch;
        }
PUGI__FN void translate ( char_t *  buffer,
const char_t *  from,
const char_t *  to 
)

Definition at line 7123 of file pugixml.cpp.

References find_char(), PUGI__DMC_VOLATILE, and strlength().

Referenced by xpath_ast_node::eval_string().

        {
                size_t to_length = strlength(to);

                char_t* write = buffer;

                while (*buffer)
                {
                        PUGI__DMC_VOLATILE char_t ch = *buffer++;

                        const char_t* pos = find_char(from, ch);

                        if (!pos)
                                *write++ = ch; // do not process
                        else if (static_cast<size_t>(pos - from) < to_length)
                                *write++ = to[pos - from]; // replace
                }

                // zero-terminate
                *write = 0;
        }
PUGI__FN void truncate_zeros ( char *  begin,
char *  end 
)

Definition at line 6817 of file pugixml.cpp.

Referenced by convert_number_to_mantissa_exponent().

        {
                while (begin != end && end[-1] == '0') end--;

                *end = 0;
        }
template<typename I >
I unique ( begin,
end 
)

Definition at line 6014 of file pugixml.cpp.

Referenced by xpath_node_set_raw::remove_duplicates().

        {
                // fast skip head
                while (end - begin > 1 && *begin != *(begin + 1)) begin++;

                if (begin == end) return begin;

                // last written element
                I write = begin++; 

                // merge unique elements
                while (begin != end)
                {
                        if (*begin != *write)
                                *++write = *begin++;
                        else
                                begin++;
                }

                // past-the-end (write points to live element)
                return write + 1;
        }
PUGI__FN xpath_node xpath_first ( const xpath_node *  begin,
const xpath_node *  end,
xpath_node_set::type_t  type 
)

Definition at line 7318 of file pugixml.cpp.

References min_element().

Referenced by xpath_node_set_raw::first().

        {
                if (begin == end) return xpath_node();

                switch (type)
                {
                case xpath_node_set::type_sorted:
                        return *begin;

                case xpath_node_set::type_sorted_reverse:
                        return *(end - 1);

                case xpath_node_set::type_unsorted:
                        return *min_element(begin, end, document_order_comparator());

                default:
                        assert(!"Invalid node set type");
                        return xpath_node();
                }
        }
PUGI__NS_END PUGI__NS_BEGIN PUGI__FN xpath_node_set::type_t xpath_sort ( xpath_node *  begin,
xpath_node *  end,
xpath_node_set::type_t  type,
bool  rev 
)

Definition at line 7302 of file pugixml.cpp.

References reverse(), and sort().

Referenced by xpath_node_set_raw::sort_do().

        {
                xpath_node_set::type_t order = rev ? xpath_node_set::type_sorted_reverse : xpath_node_set::type_sorted;

                if (type == xpath_node_set::type_unsorted)
                {
                        sort(begin, end, document_order_comparator());

                        type = xpath_node_set::type_sorted;
                }
                
                if (type != order) reverse(begin, end);
                        
                return order;
        }
PUGI__FN xpath_string xpath_string_const ( const char_t *  str)

Definition at line 6527 of file pugixml.cpp.

Referenced by convert_number_to_string(), xpath_ast_node::eval_string(), and string_value().

        {
                return xpath_string(str, false);
        }
PUGI__FN size_t zero_terminate_buffer ( void *  buffer,
size_t  size,
xml_encoding  encoding 
)

Definition at line 3740 of file pugixml.cpp.

References get_wchar_encoding().

Referenced by load_file_impl(), and load_stream_impl().

        {
                // We only need to zero-terminate if encoding conversion does not do it for us
        #ifdef PUGIXML_WCHAR_MODE
                xml_encoding wchar_encoding = get_wchar_encoding();

                if (encoding == wchar_encoding || need_endian_swap_utf(encoding, wchar_encoding))
                {
                        size_t length = size / sizeof(char_t);

                        static_cast<char_t*>(buffer)[length] = 0;
                        return (length + 1) * sizeof(char_t);
                }
        #else
                if (encoding == encoding_utf8)
                {
                        static_cast<char*>(buffer)[size] = 0;
                        return size + 1;
                }
        #endif

                return size;
        }

Variable Documentation

const unsigned char chartype_table[256] [static]
Initial value:
        {
                55,  0,   0,   0,   0,   0,   0,   0,      0,   12,  12,  0,   0,   63,  0,   0,   
                0,   0,   0,   0,   0,   0,   0,   0,      0,   0,   0,   0,   0,   0,   0,   0,   
                8,   0,   6,   0,   0,   0,   7,   6,      0,   0,   0,   0,   0,   96,  64,  0,   
                64,  64,  64,  64,  64,  64,  64,  64,     64,  64,  192, 0,   1,   0,   48,  0,   
                0,   192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192, 
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 0,   0,   16,  0,   192, 
                0,   192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192, 
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 0, 0, 0, 0, 0,           

                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192, 
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192,
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192,
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192,
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192,
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192,
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192,
                192, 192, 192, 192, 192, 192, 192, 192,    192, 192, 192, 192, 192, 192, 192, 192
        }

Definition at line 1137 of file pugixml.cpp.

const unsigned char chartypex_table[256] [static]
Initial value:
        {
                3,  3,  3,  3,  3,  3,  3,  3,     3,  0,  2,  3,  3,  2,  3,  3,     
                3,  3,  3,  3,  3,  3,  3,  3,     3,  3,  3,  3,  3,  3,  3,  3,     
                0,  0,  2,  0,  0,  0,  3,  0,     0,  0,  0,  0,  0, 16, 16,  0,     
                24, 24, 24, 24, 24, 24, 24, 24,    24, 24, 0,  0,  3,  0,  3,  0,     

                0,  20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,    
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 0,  0,  0,  0,  20,    
                0,  20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,    
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 0,  0,  0,  0,  0,     

                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,    
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20,
                20, 20, 20, 20, 20, 20, 20, 20,    20, 20, 20, 20, 20, 20, 20, 20
        }

Definition at line 1167 of file pugixml.cpp.

const xpath_node_set dummy_node_set [static]

Definition at line 7186 of file pugixml.cpp.

const uintptr_t xml_memory_page_alignment = 32 [static]

Definition at line 269 of file pugixml.cpp.

const uintptr_t xml_memory_page_name_allocated_mask = 16 [static]

Definition at line 271 of file pugixml.cpp.

Referenced by destroy_attribute(), and destroy_node().

const uintptr_t xml_memory_page_pointer_mask = ~(xml_memory_page_alignment - 1) [static]

Definition at line 270 of file pugixml.cpp.

Referenced by get_allocator(), and strcpy_insitu().

PUGI__NS_END static PUGI__NS_BEGIN const size_t xml_memory_page_size [static]
Initial value:



                32768

Definition at line 261 of file pugixml.cpp.

const uintptr_t xml_memory_page_type_mask = 7 [static]

Definition at line 273 of file pugixml.cpp.

Referenced by xml_parser::has_element_node_siblings(), and is_text_node().

const uintptr_t xml_memory_page_value_allocated_mask = 8 [static]

Definition at line 272 of file pugixml.cpp.

Referenced by destroy_attribute(), and destroy_node().


Generated on Mon Sep 15 2014 01:23:55 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001