diff --git a/doc/TODO b/doc/TODO
index 2b6ea3e..41c60a5 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -4,7 +4,6 @@ general/other:
1:cross platform matrix-send
matrix:
- 8:fix fat_strings.cpp; use C style string allocation/catenation
4:string constant lookup tables
session:
7:server level queries in matrix::session
diff --git a/include/matrix/events.hpp b/include/matrix/events.hpp
index d9a33e9..e4f3f35 100644
--- a/include/matrix/events.hpp
+++ b/include/matrix/events.hpp
@@ -20,7 +20,7 @@
#define MATRIX_EVENT_HPP
#include "raii/rjp_ptr.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include "raii/rjp_string.hpp"
namespace matrix::sync{
diff --git a/include/matrix/iterable.hpp b/include/matrix/iterable.hpp
index 14bb2e0..658d54f 100644
--- a/include/matrix/iterable.hpp
+++ b/include/matrix/iterable.hpp
@@ -20,8 +20,8 @@
#define MATRIX_ITERABLE_HPP
#include "matrix/events.hpp"
+#include "raii/string_base.hpp"
#include "raii/rjp_string.hpp"
-#include "raii/static_string.hpp"
#include "raii/rjp_iterator.hpp"
namespace matrix::sync{
diff --git a/include/matrix/json_targets.hpp b/include/matrix/json_targets.hpp
index 78ae827..30fbaff 100644
--- a/include/matrix/json_targets.hpp
+++ b/include/matrix/json_targets.hpp
@@ -1,7 +1,7 @@
#ifndef MATRIX_JSON_TARGETS_HPP
#define MATRIX_JSON_TARGETS_HPP
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
namespace matrix::json{
diff --git a/include/matrix/sync_response.hpp b/include/matrix/sync_response.hpp
index ec5ca70..181b743 100644
--- a/include/matrix/sync_response.hpp
+++ b/include/matrix/sync_response.hpp
@@ -19,8 +19,8 @@
#ifndef SYNC_RESPONSE_HPP
#define SYNC_RESPONSE_HPP
+#include "raii/string_base.hpp"
#include "raii/rjp_string.hpp"
-#include "raii/static_string.hpp"
#include "raii/rjp_iterator.hpp"
#include "raii/rjp_ptr.hpp"
#include "matrix/events.hpp"
diff --git a/include/raii/static_string.hpp b/include/raii/static_string.hpp
deleted file mode 100644
index 06d1536..0000000
--- a/include/raii/static_string.hpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- This file is a part of 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 .
-*/
-
-#ifndef RAII_STATIC_STRING_HPP
-#define RAII_STATIC_STRING_HPP
-
-#include "raii/string_base.hpp"
-
-namespace raii{
-
- class static_string : public string_base
- {
- public:
- constexpr static_string(void) = default;
- template
- constexpr static_string(const char(&str)[N]):
- string_base(const_cast(str), N){}
- constexpr static_string(const char* str, size_t len):
- string_base(const_cast(str), len){}
- static_string(const char* c):
- string_base(const_cast(c), strlen(c)){}
- constexpr static_string(const static_string& s):
- string_base(s.m_data, s.m_length){}
- constexpr static_string(static_string&& s):
- string_base(s.m_data, s.m_length){}
- ~static_string(void) = default;
-
- static_string& operator=(const char* c){
- m_data = const_cast(c);
- m_length = strlen(c);
- return *this;
- }
- static_string& operator=(const static_string& s){
- m_data = s.m_data;
- m_length = s.m_length;
- return *this;
- }
- static_string& operator=(static_string&&) = delete;
- };
-}
-
-namespace{
- constexpr inline raii::static_string operator"" _ss(const char* str, size_t len){
- return raii::static_string(str, len);
- }
-}
-
-#endif
diff --git a/include/raii/string_base.hpp b/include/raii/string_base.hpp
index eaaaffd..e842dfa 100644
--- a/include/raii/string_base.hpp
+++ b/include/raii/string_base.hpp
@@ -19,12 +19,9 @@
#ifndef RAII_STRING_BASE_HPP
#define RAII_STRING_BASE_HPP
-#include //size_t
-#include //strlen, strcpy
-#include //memcpy
#include //is_same, integral_contant, enable_if, etc
#include //forward
-#include
+#include //size_t
namespace raii{
@@ -51,6 +48,20 @@ namespace raii{
struct is_tuple{
static constexpr bool value = std::is_same()))>::value;
};
+
+ //check for member function 'length'
+ template
+ struct has_len{
+ template
+ struct check;
+
+ template
+ static std::true_type test(check*);
+ template
+ static std::false_type test(...);
+
+ static constexpr bool value = std::is_same(0))>::value;
+ };
}
@@ -92,7 +103,6 @@ namespace raii{
};
-
//Supplies all functions that string_base can't implement
template
class string_intermediary : public string_base
@@ -102,183 +112,39 @@ namespace raii{
public:
string_intermediary(void) = default;
- string_intermediary(char* data, size_t len):
- string_base(data, len){}
- string_intermediary(const char* data, size_t len):
- string_base(reinterpret_cast(len ? Allocator::copy(data, len+1) : nullptr), len){}
- string_intermediary(const char* data):
- string_base(data ? strlen(data) : 0)
- {
- if(m_length)
- m_data = reinterpret_cast(Allocator::copy(data, m_length+1));
- }
- string_intermediary(size_t len):
- string_base(reinterpret_cast(len ? Allocator::allocate(len+1) : nullptr), len){}
+ string_intermediary(char* data, size_t len);
+ string_intermediary(const char* data, size_t len);
+ string_intermediary(const char* data);
+ string_intermediary(size_t len);
//normal copy and move ctors
- string_intermediary(const string_intermediary& b):
- string_base(reinterpret_cast(b.m_length ? Allocator::copy(b.m_data, b.m_length+1) : nullptr), b.m_length){}
- string_intermediary(string_intermediary&& s):
- string_base(std::exchange(s.m_data, nullptr), s.m_length){}
+ string_intermediary(const string_intermediary& b);
+ string_intermediary(string_intermediary&& s);
- string_intermediary(const string_base& b):
- string_base(reinterpret_cast(b.length() ? Allocator::copy(b.get(), b.length()+1) : nullptr), b.length()){}
-
- //copy from string expression
- template::value && !detail::is_concrete_string::value,void>::type* = nullptr>
- string_intermediary(T&& t){
- size_t len = t.length();
- if(!len){
- return;
- }
- char* tmp = reinterpret_cast(Allocator::allocate(len+1));
- _assign(tmp, t.get(), 0);
- m_data = tmp;
- m_data[len] = 0;
- m_length = len;
- }
+ string_intermediary(const string_base& b);
//dtor
- ~string_intermediary(void){
- Allocator::free(m_data);
- }
+ ~string_intermediary(void);
- string_intermediary& operator=(const string_intermediary& s){
- string_intermediary tmp(s);
- return (*this = std::move(tmp));
- }
- string_intermediary& operator=(string_intermediary&& s){
- std::swap(m_data, s.m_data);
- m_length = s.m_length;
- return *this;
- }
+ string_intermediary& operator=(const string_intermediary& s);
+ string_intermediary& operator=(string_intermediary&& s);
//Copy from c string
- string_intermediary& operator=(const char* c){
- return _copy_string(c, strlen(c));
- }
+ string_intermediary& operator=(const char* c);
//Copy from other string_base
- string_intermediary& operator=(const string_base& s){
- return _copy_string(s.get(), s.length());
- }
- //Move from other string base
- template::value && !detail::is_concrete_string::value,void>::type* = nullptr>
- string_base& operator=(T&& t){
- size_t len = t.length();
- char* tmp;
- if(len > m_length){
- tmp = reinterpret_cast(Allocator::allocate(len+1));
- _assign(tmp, t.get(), 0);
- Allocator::free(m_data);
- }else{
- tmp = m_data;
- _assign(tmp, t.get(), 0);
- }
- m_data = tmp;
- m_data[len] = 0;
- m_length = len;
- return *this;
- }
-
- string_intermediary operator+(const string_base& s)const{
- string_intermediary tmp(reinterpret_cast(Allocator::allocate(m_length + s.length() + 1)), m_length+s.length());
- memcpy(tmp.get(), m_data, m_length);
- strcpy(tmp.get()+m_length, s.get());
- return tmp;
- }
-
- string_intermediary operator+(const char* c)const{
- size_t len = strlen(c);
- string_intermediary tmp(reinterpret_cast(Allocator::allocate(m_length + len + 1)), m_length+len);
- memcpy(tmp.get(), m_data, m_length);
- strcpy(tmp.get()+m_length, c);
- return tmp;
- }
-
+ string_intermediary& operator=(const string_base& s);
//Replace managed pointer. Frees existing value
- void reset(char* val = nullptr){
- Allocator::free(m_data);
- m_data = val;
- m_length = val ? strlen(val) : 0;
- }
- void reset(char* val, size_t len){
- Allocator::free(m_data);
- m_data = val;
- m_length = len;
- }
- bool resize(size_t newsize){
- if(newsize < m_length)
- return false;
- string_intermediary tmp(newsize);
- memcpy(tmp.get(), m_data, m_length);
- tmp[m_length] = 0;
- *this = std::move(tmp);
- return true;
- }
- void append(const char* data, size_t len){
- string_intermediary tmp(m_length + len);
- memcpy(tmp.m_data, m_data, m_length);
- memcpy(tmp.m_data+m_length, data, len);
- tmp[m_length+len] = 0;
- *this = std::move(tmp);
- }
- void append(const char* data){
- *this += data;
- }
- void append(const string_expr& s){
- *this += s;
- }
+ void reset(char* val = nullptr);
+ void reset(char* val, size_t len);
+ bool resize(size_t newsize);
+ void append(const char* data, size_t len);
+ void append(const char* data);
+ void append(const string_base& s);
private:
- string_intermediary& _copy_string(const char* s, size_t len){
- if(!len){
- Allocator::free(m_data);
- m_length = 0;
- return *this;
- }
- if(len <= m_length){
- strcpy(m_data, s);
- }else{
- Allocator::free(m_data);
- m_data = reinterpret_cast(Allocator::copy(s, len+1));
- if(!m_data){
- m_length = 0;
- return *this;
- }
- }
- m_length = len;
- return *this;
- }
- template
- static void _assign(char* dest, Tup&& t, size_t offset){
- memcpy(dest+offset, std::get(t), std::get(t));
- if constexpr(I+2 < std::tuple_size::value){
- _assign(dest, std::forward(t), offset+std::get(t));
- }
- }
+ string_intermediary& _copy_string(const char* s, size_t len);
};
-
-
- //check for member function 'length'
- namespace detail{
- template
- struct has_len{
- template
- struct check;
-
- template
- static std::true_type test(check*);
- template
- static std::false_type test(...);
-
- static constexpr bool value = std::is_same(0))>::value;
- };
-
- }
-
-
-
//Like an expression template but not really
template
class string_cat_expr : public string_expr
@@ -289,66 +155,56 @@ namespace raii{
public:
template
- constexpr string_cat_expr(T&& l, U&& r):
- m_l(std::forward(l)),
- m_r(std::forward(r)){}
- constexpr string_cat_expr(const string_cat_expr& s):
- m_l(std::forward(s.m_l)),
- m_r(std::forward(s.m_r)){}
- constexpr string_cat_expr(string_cat_expr&& s):
- m_l(std::forward(s.m_l)),
- m_r(std::forward(s.m_r)){}
+ constexpr string_cat_expr(T&& l, U&& r);
+ constexpr string_cat_expr(const string_cat_expr& s);
+ constexpr string_cat_expr(string_cat_expr&& s);
- constexpr size_t length(void)const{
- return _llen() + _rlen();
- }
- constexpr auto get(void){
- return std::tuple_cat(_lget(), _rget());
- }
+ constexpr size_t length(void)const;
+ template
+ operator string_intermediary(void);
+ constexpr const Left& left(void)const;
+ constexpr const Right& right(void)const;
+ };
+
+ template
+ struct appender
+ {
private:
- constexpr auto _lget(void){
- if constexpr(detail::is_string::value){
- if constexpr(detail::is_tuple::value){
- //string_cat_expr
- return m_l.get();
- }else{
- //string_base
- return std::make_tuple(m_l.get(), m_l.length());
- }
- }else{
- //c string
- return std::make_tuple(m_l, strlen(m_l));
- }
- }
- constexpr auto _rget(void){
- if constexpr(detail::is_string::value){
- if constexpr(detail::is_tuple::value){
- return m_r.get();
- }else{
- return std::make_tuple(m_r.get(), m_r.length());
- }
- }else{
- return std::make_tuple(m_r, strlen(m_r));
- }
- }
- constexpr size_t _llen(void)const{
- if constexpr(detail::has_len::type>::value){
- return m_l.length();
- }else{
- return strlen(m_l);
- }
- }
- constexpr size_t _rlen(void)const{
- if constexpr(detail::has_len::type>::value){
- return m_r.length();
- }else{
- return strlen(m_r);
- }
- }
+ Targ& m_targ;
+ size_t m_pos = 0;
+ public:
+ appender(Targ& t);
+ template
+ void operator()(const string_cat_expr& str);
+ void operator()(const string_base& str);
+ };
+
+ class static_string : public string_base
+ {
+ public:
+ constexpr static_string(void) = default;
+ template
+ constexpr static_string(const char(&str)[N]);
+ constexpr static_string(const char* str, size_t len);
+ static_string(const char* c);
+ constexpr static_string(const static_string& s);
+ constexpr static_string(static_string&& s);
+ ~static_string(void) = default;
+
+ static_string& operator=(const char* c);
+ static_string& operator=(const static_string& s);
+ static_string& operator=(static_string&&) = delete;
};
}
+#include "raii/string_base.tpp"
+
+namespace{
+ constexpr inline raii::static_string operator"" _ss(const char* str, size_t len){
+ return raii::static_string(str, len);
+ }
+}
template::value&&raii::detail::is_concrete_string::value,void>::type* = nullptr>
bool operator==(Str1&& left, Str2&& right){
return left && right && left.length() == right.length() && !strcmp(left.get(), right.get());
@@ -360,20 +216,20 @@ bool operator!=(Str1&& left, Str2&& right){
template::value && std::is_rvalue_reference::value,void>::type* = nullptr>
constexpr auto operator+(const char* left, Right&& right){
- return raii::string_cat_expr::type>(left, std::move(right));
+ return raii::string_cat_expr::type>(raii::static_string(left), std::move(right));
}
template::value && !std::is_rvalue_reference::value,void>::type* = nullptr>
constexpr auto operator+(const char* left, Right&& right){
- return raii::string_cat_expr(right))>(left, std::forward(right));
+ return raii::string_cat_expr(right))>(raii::static_string(left), std::forward(right));
}
template::value && std::is_rvalue_reference::value,void>::type* = nullptr>
constexpr auto operator+(Left&& left, const char* right){
- return raii::string_cat_expr::type,const char*>(std::move(left), right);
+ return raii::string_cat_expr::type,raii::static_string>(std::move(left), raii::static_string(right));
}
template::value && !std::is_rvalue_reference::value,void>::type* = nullptr>
constexpr auto operator+(Left&& left, const char* right){
- return raii::string_cat_expr(left)),const char*>(std::forward(left), right);
+ return raii::string_cat_expr(left)),raii::static_string>(std::forward(left), raii::static_string(right));
}
template.
+*/
+
+#ifndef RAII_STRING_BASE_TPP
+#define RAII_STRING_BASE_TPP
+
+#include //forward, move, swap, etc
+#include //memcpy
+#include //strlen, strcpy
+
+namespace raii{
+ template
+ string_intermediary::string_intermediary(char* data, size_t len):
+ string_base(data, len){}
+ template
+ string_intermediary::string_intermediary(const char* data, size_t len):
+ string_base(reinterpret_cast(len ? Allocator::copy(data, len+1) : nullptr), len)
+ {
+ m_data[len] = 0;
+ }
+ template
+ string_intermediary::string_intermediary(const char* data):
+ string_base(data ? strlen(data) : 0)
+ {
+ if(m_length)
+ m_data = reinterpret_cast(Allocator::copy(data, m_length+1));
+ }
+ template
+ string_intermediary::string_intermediary(size_t len):
+ string_base(reinterpret_cast(len ? Allocator::allocate(len+1) : nullptr), len)
+ {
+ m_data[len] = 0;
+ }
+
+ //normal copy and move ctors
+ template
+ string_intermediary::string_intermediary(const string_intermediary& b):
+ string_base(reinterpret_cast(b.m_length ? Allocator::copy(b.m_data, b.m_length+1) : nullptr), b.m_length){}
+ template
+ string_intermediary::string_intermediary(string_intermediary&& s):
+ string_base(std::exchange(s.m_data, nullptr), s.m_length){}
+
+ template
+ string_intermediary::string_intermediary(const string_base& b):
+ string_base(reinterpret_cast(b.length() ? Allocator::copy(b.get(), b.length()+1) : nullptr), b.length()){}
+
+ //dtor
+ template
+ string_intermediary::~string_intermediary(void){
+ Allocator::free(m_data);
+ }
+
+ template
+ string_intermediary& string_intermediary::operator=(const string_intermediary& s){
+ string_intermediary tmp(s);
+ return (*this = std::move(tmp));
+ }
+ template
+ string_intermediary& string_intermediary::operator=(string_intermediary&& s){
+ std::swap(m_data, s.m_data);
+ m_length = s.m_length;
+ return *this;
+ }
+ //Copy from c string
+ template
+ string_intermediary& string_intermediary::operator=(const char* c){
+ return _copy_string(c, strlen(c));
+ }
+ //Copy from other string_base
+ template
+ string_intermediary& string_intermediary::operator=(const string_base& s){
+ return _copy_string(s.get(), s.length());
+ }
+
+ //Replace managed pointer. Frees existing value
+ template
+ void string_intermediary::reset(char* val){
+ Allocator::free(m_data);
+ m_data = val;
+ m_length = val ? strlen(val) : 0;
+ }
+ template
+ void string_intermediary::reset(char* val, size_t len){
+ Allocator::free(m_data);
+ m_data = val;
+ m_length = len;
+ }
+ template
+ bool string_intermediary::resize(size_t newsize){
+ if(newsize < m_length)
+ return false;
+ string_intermediary tmp(newsize);
+ memcpy(tmp.get(), m_data, m_length);
+ tmp[m_length] = 0;
+ *this = std::move(tmp);
+ return true;
+ }
+ template
+ void string_intermediary::append(const char* data, size_t len){
+ string_intermediary tmp(m_length + len);
+ memcpy(tmp.m_data, m_data, m_length);
+ memcpy(tmp.m_data+m_length, data, len);
+ tmp[m_length+len] = 0;
+ *this = std::move(tmp);
+ }
+ template
+ void string_intermediary::append(const char* data){
+ size_t len = strlen(data);
+ resize(m_length+len);
+ memcpy(m_data+m_length, data, len);
+ m_length += len;
+ m_data[m_length] = 0;
+ }
+ template
+ void string_intermediary::append(const string_base& s){
+ append(s.get());
+ }
+
+ template
+ string_intermediary& string_intermediary::_copy_string(const char* s, size_t len){
+ if(!len){
+ Allocator::free(m_data);
+ m_length = 0;
+ return *this;
+ }
+ if(len <= m_length){
+ strcpy(m_data, s);
+ }else{
+ Allocator::free(m_data);
+ m_data = reinterpret_cast(Allocator::copy(s, len+1));
+ if(!m_data){
+ m_length = 0;
+ return *this;
+ }
+ }
+ m_length = len;
+ return *this;
+ }
+
+
+ template
+ template
+ constexpr string_cat_expr::string_cat_expr(T&& l, U&& r):
+ m_l(std::forward(l)),
+ m_r(std::forward(r)){}
+ template
+ constexpr string_cat_expr::string_cat_expr(const string_cat_expr& s):
+ m_l(std::forward(s.m_l)),
+ m_r(std::forward(s.m_r)){}
+ template
+ constexpr string_cat_expr::string_cat_expr(string_cat_expr&& s):
+ m_l(std::forward(s.m_l)),
+ m_r(std::forward(s.m_r)){}
+
+ template
+ constexpr size_t string_cat_expr::length(void)const{
+ return m_l.length() + m_r.length();
+ }
+ template
+ template
+ string_cat_expr::operator string_intermediary(void){
+ string_intermediary ret(length());
+ for(size_t i = 0;i < length();++i)
+ ret[i] = 'n';
+ appender> append(ret);
+ append(*this);
+ return ret;
+ }
+ template
+ constexpr const Left& string_cat_expr::left(void)const{
+ return m_l;
+ }
+ template
+ constexpr const Right& string_cat_expr::right(void)const{
+ return m_r;
+ }
+
+
+ template
+ appender::appender(Targ& t): m_targ(t){}
+ template
+ template
+ void appender::operator()(const string_cat_expr& str){
+ (*this)(str.left());
+ (*this)(str.right());
+ }
+ template
+ void appender::operator()(const string_base& str){
+ memcpy(m_targ.get()+m_pos, str.get(), str.length());
+ m_pos += str.length();
+ }
+
+ template
+ constexpr static_string::static_string(const char(&str)[N]):
+ string_base(const_cast(str), N){}
+ constexpr static_string::static_string(const char* str, size_t len):
+ string_base(const_cast(str), len){}
+ constexpr static_string::static_string(const static_string& s):
+ string_base(s.m_data, s.m_length){}
+ constexpr static_string::static_string(static_string&& s):
+ string_base(s.m_data, s.m_length){}
+
+} //namespace raii
+
+#endif
diff --git a/makefile b/makefile
index 12e70cf..060fe95 100644
--- a/makefile
+++ b/makefile
@@ -60,13 +60,15 @@ else
endif
ifeq ($(RELEASE),1)
- CXXFLAGS+=-O2
+ #a lot of false strict aliasing warnings from gcc 9
+ CXXFLAGS+=-O2 -Wno-strict-aliasing
+else ifeq ($(MEMCHK),1)
+ LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
+ CXXFLAGS+=-O0 -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
else
CXXFLAGS+=-O0 -g
endif
-memchk: LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
-memchk: CXXFLAGS+=-O0 -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
ifeq ($(OS),Windows_NT)
mkdir=mkdir $(subst /,\,$(1)) > NUL 2>&1
@@ -115,10 +117,10 @@ memchk: all
.PHONY: utils
utils: matrix-send
tester: all $(OBJDIR)/src.test.cpp.o
- $(CXX) -L. -o "$@" $(OBJDIR)/src.test.cpp.o -l$(MAIN_LIBRARY) $(LDLIBS) -lpthread -Iinclude
+ $(CXX) -L. -o "$@" $(OBJDIR)/src.test.cpp.o -l$(MAIN_LIBRARY) $(LDFLAGS) $(LDLIBS) -lpthread -Iinclude
matrix-send: all $(OBJDIR)/util.matrix-send.cpp.o
- $(CXX) -L. -o "$@" $(OBJDIR)/util.matrix-send.cpp.o -l$(MAIN_LIBRARY) $(LDLIBS) -Iinclude
+ $(CXX) -L. -o "$@" $(OBJDIR)/util.matrix-send.cpp.o -l$(MAIN_LIBRARY) $(LDFLAGS) $(LDLIBS) -Iinclude
define GENERATE_OBJECTS
diff --git a/src/matrix/client.cpp b/src/matrix/client.cpp
index 17b2245..22c433b 100644
--- a/src/matrix/client.cpp
+++ b/src/matrix/client.cpp
@@ -20,7 +20,7 @@
#include "matrix/fat_strings.hpp"
#include "matrix/json_targets.hpp"
#include "raii/filerd.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include "raii/rjp_ptr.hpp"
#include "raii/util.hpp"
diff --git a/src/matrix/connection.cpp b/src/matrix/connection.cpp
index fa98dbc..765416c 100644
--- a/src/matrix/connection.cpp
+++ b/src/matrix/connection.cpp
@@ -18,7 +18,7 @@
#include "matrix/connection.hpp"
#include "raii/rjp_ptr.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include //size_t
#include //min, max
diff --git a/src/matrix/fat_strings.cpp b/src/matrix/fat_strings.cpp
index 0ba7004..1792b24 100644
--- a/src/matrix/fat_strings.cpp
+++ b/src/matrix/fat_strings.cpp
@@ -18,7 +18,7 @@
#include "matrix/fat_strings.hpp"
#include "matrix/upload_info.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include "matrix/json_targets.hpp"
#include "raii/util.hpp"
diff --git a/src/matrix/roomcxn.cpp b/src/matrix/roomcxn.cpp
index 2f6ccd0..49ba285 100644
--- a/src/matrix/roomcxn.cpp
+++ b/src/matrix/roomcxn.cpp
@@ -17,7 +17,7 @@
*/
#include "matrix/roomcxn.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include "matrix/fat_strings.hpp"
#include "matrix/json_targets.hpp"
#include "raii/util.hpp"
diff --git a/src/matrix/session.cpp b/src/matrix/session.cpp
index 3e66829..a950e0a 100644
--- a/src/matrix/session.cpp
+++ b/src/matrix/session.cpp
@@ -20,7 +20,7 @@
#include "raii/rjp_ptr.hpp"
#include "raii/curler.hpp"
#include "raii/util.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include "matrix/fat_strings.hpp"
#include "matrix/json_targets.hpp"
diff --git a/src/matrix/syncer.cpp b/src/matrix/syncer.cpp
index e2f645b..47485d6 100644
--- a/src/matrix/syncer.cpp
+++ b/src/matrix/syncer.cpp
@@ -17,7 +17,7 @@
*/
#include "matrix/syncer.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include "raii/rjp_ptr.hpp"
#include "raii/util.hpp"
diff --git a/src/raii/string_base.cpp b/src/raii/string_base.cpp
index 6ef3ed2..b2f2b63 100644
--- a/src/raii/string_base.cpp
+++ b/src/raii/string_base.cpp
@@ -17,7 +17,6 @@
*/
#include "raii/string_base.hpp"
-#include "raii/string.hpp"
#include //exchange, swap
#include //memcpy
@@ -34,4 +33,17 @@ namespace raii{
return m_data[i];
}
+ static_string::static_string(const char* c):
+ string_base(const_cast(c), strlen(c)){}
+ static_string& static_string::operator=(const char* c){
+ m_data = const_cast(c);
+ m_length = strlen(c);
+ return *this;
+ }
+ static_string& static_string::operator=(const static_string& s){
+ m_data = s.m_data;
+ m_length = s.m_length;
+ return *this;
+ }
+
}
diff --git a/src/test.cpp b/src/test.cpp
index 3745559..7589100 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -19,8 +19,9 @@
//example of a client which responds to commands
#include "matrix/matrix.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include "matrix/sync_response.hpp"
+#include "raii/util.hpp"
#include
#include
@@ -112,7 +113,7 @@ int main(){
auto room = client.spawn_room("!IaZlRZWhZiNMMsiZRl:rexy712.chickenkiller.com"_ss);
syn.sync(0);
- auto status = room.send_message("gay"_ss);
+ auto status = room.send_message("test"_ss);
if(!status.ok())
fprintf(stderr, "http error: %d\n", status.httpstatus());
if(status.mxerror())
diff --git a/util/matrix-send.cpp b/util/matrix-send.cpp
index b1e4219..47b000a 100644
--- a/util/matrix-send.cpp
+++ b/util/matrix-send.cpp
@@ -17,7 +17,7 @@
*/
#include "matrix/matrix.hpp"
-#include "raii/static_string.hpp"
+#include "raii/string_base.hpp"
#include //exit
#include