| 6668 | } |
| 6669 | |
| 6670 | template <typename T> PUGI__FN T* new_xpath_variable(const char_t* name) |
| 6671 | { |
| 6672 | size_t length = strlength(name); |
| 6673 | if (length == 0) return 0; // empty variable names are invalid |
| 6674 | |
| 6675 | // $$ we can't use offsetof(T, name) because T is non-POD, so we just allocate additional length characters |
| 6676 | void* memory = xml_memory::allocate(sizeof(T) + length * sizeof(char_t)); |
| 6677 | if (!memory) return 0; |
| 6678 | |
| 6679 | T* result = new (memory) T(); |
| 6680 | |
| 6681 | memcpy(result->name, name, (length + 1) * sizeof(char_t)); |
| 6682 | |
| 6683 | return result; |
| 6684 | } |
| 6685 | |
| 6686 | PUGI__FN xpath_variable* new_xpath_variable(xpath_value_type type, const char_t* name) |
| 6687 | { |