| 7396 | |
| 7397 | template<typename T> |
| 7398 | PUGI__FN T* new_xpath_variable(const char_t* name) |
| 7399 | { |
| 7400 | size_t length = strlength(name); |
| 7401 | if (length == 0) |
| 7402 | return 0; // empty variable names are invalid |
| 7403 | |
| 7404 | // $$ we can't use offsetof(T, name) because T is non-POD, so we just allocate additional length characters |
| 7405 | void* memory = xml_memory::allocate(sizeof(T) + length * sizeof(char_t)); |
| 7406 | if (!memory) |
| 7407 | return 0; |
| 7408 | |
| 7409 | T* result = new (memory) T(); |
| 7410 | |
| 7411 | memcpy(result->name, name, (length + 1) * sizeof(char_t)); |
| 7412 | |
| 7413 | return result; |
| 7414 | } |
| 7415 | |
| 7416 | PUGI__FN xpath_variable* new_xpath_variable(xpath_value_type type, const char_t* name) |
| 7417 | { |