matrix_thing/src/raii/rjp_string.cpp
2019-09-01 20:14:02 -07:00

43 lines
1.3 KiB
C++

/**
This file is a part of r0nk, atlas_moon, and rexy's matrix client
Copyright (C) 2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "raii/rjp_string.hpp"
namespace raii{
namespace detail{
void rjp_allocator::free(void* data){
rjp_free(data);
}
void* rjp_allocator::allocate(size_t size){
return rjp_alloc(size);
}
void* rjp_allocator::copy(const void* data, size_t len){
char* tmp = reinterpret_cast<char*>(allocate(len));
memcpy(tmp, data, len-1);
tmp[len-1] = 0;
return tmp;
}
}
rjp_string rjp_string_from_key(RJP_value* val){
char* key = rjp_member_name(val);
size_t len = rjp_member_name_length(val);
rjp_set_key(val, nullptr, 0);
return rjp_string(key, len);
}
}