Did most of the remaining std::string and vector to String and Vector conversions.

This commit is contained in:
Relintai 2021-11-01 19:53:35 +01:00
parent 3f190e9a53
commit f7b5952d2a
20 changed files with 183 additions and 119 deletions

View File

@ -4,15 +4,15 @@
#include <iostream> #include <iostream>
void FileCache::wwwroot_register_file(const std::string &file_path) { void FileCache::wwwroot_register_file(const String &file_path) {
registered_files.insert(file_path); registered_files.insert(file_path);
} }
void FileCache::wwwroot_deregister_file(const std::string &file_path) { void FileCache::wwwroot_deregister_file(const String &file_path) {
registered_files.erase(file_path); registered_files.erase(file_path);
} }
bool FileCache::wwwroot_has_file(const std::string &file_path) { bool FileCache::wwwroot_has_file(const String &file_path) {
return registered_files.find(file_path) != registered_files.end(); return registered_files.find(file_path) != registered_files.end();
} }
@ -40,7 +40,7 @@ void FileCache::wwwroot_evaluate_dir(const char *path, const bool should_exist)
} }
if (!file.is_dir) { if (!file.is_dir) {
std::string np = file.path; String np = file.path;
np = np.substr(wwwroot.size(), np.size() - wwwroot.size()); np = np.substr(wwwroot.size(), np.size() - wwwroot.size());
registered_files.insert(np); registered_files.insert(np);
@ -59,7 +59,7 @@ void FileCache::wwwroot_evaluate_dir(const char *path, const bool should_exist)
tinydir_close(&dir); tinydir_close(&dir);
} }
bool FileCache::get_cached_body(const std::string &path, std::string *body) { bool FileCache::get_cached_body(const String &path, String *body) {
//TODO ERROR MACRO body == null //TODO ERROR MACRO body == null
//this shouldn't need mutexes //this shouldn't need mutexes
@ -78,12 +78,12 @@ bool FileCache::get_cached_body(const std::string &path, std::string *body) {
return false; return false;
} }
body->append(e->body); body->append_str(e->body);
return true; return true;
} }
void FileCache::set_cached_body(const std::string &path, const std::string &body) { void FileCache::set_cached_body(const String &path, const String &body) {
cache_mutex.lock(); cache_mutex.lock();
CacheEntry *e = cache_map[path]; CacheEntry *e = cache_map[path];

View File

@ -1,7 +1,8 @@
#ifndef FILE_CACHE_H #ifndef FILE_CACHE_H
#define FILE_CACHE_H #define FILE_CACHE_H
#include <string> #include "core/string.h"
#include <set> #include <set>
#include <map> #include <map>
#include <chrono> #include <chrono>
@ -9,32 +10,32 @@
class FileCache { class FileCache {
public: public:
std::string wwwroot; String wwwroot;
int cache_invalidation_time; int cache_invalidation_time;
//Note: file path should be the url you want to access the file with, inculding lead slash //Note: file path should be the url you want to access the file with, inculding lead slash
//e.g. http://127.0.0.1/a/b/d.jpg -> /a/b/d.jpg //e.g. http://127.0.0.1/a/b/d.jpg -> /a/b/d.jpg
void wwwroot_register_file(const std::string &file_path); void wwwroot_register_file(const String &file_path);
void wwwroot_deregister_file(const std::string &file_path); void wwwroot_deregister_file(const String &file_path);
bool wwwroot_has_file(const std::string &file_path); bool wwwroot_has_file(const String &file_path);
void wwwroot_refresh_cache(); void wwwroot_refresh_cache();
void wwwroot_evaluate_dir(const char *path, const bool should_exist = true); void wwwroot_evaluate_dir(const char *path, const bool should_exist = true);
bool get_cached_body(const std::string &path, std::string *body); bool get_cached_body(const String &path, String *body);
void set_cached_body(const std::string &path, const std::string &body); void set_cached_body(const String &path, const String &body);
FileCache(bool singleton = false); FileCache(bool singleton = false);
virtual ~FileCache(); virtual ~FileCache();
static FileCache *get_singleton(); static FileCache *get_singleton();
std::set<std::string> registered_files; std::set<String> registered_files;
protected: protected:
struct CacheEntry { struct CacheEntry {
int64_t timestamp; int64_t timestamp;
std::string body; String body;
CacheEntry() { CacheEntry() {
timestamp = 0; timestamp = 0;
@ -43,7 +44,7 @@ protected:
std::mutex cache_mutex; std::mutex cache_mutex;
std::map<std::string, CacheEntry *> cache_map; std::map<String, CacheEntry *> cache_map;
private: private:
static FileCache *_instance; static FileCache *_instance;

View File

@ -1,9 +1,9 @@
#include "resource.h" #include "resource.h"
std::string Resource::to_json(rapidjson::Document *into) { String Resource::to_json(rapidjson::Document *into) {
return ""; return "";
} }
void Resource::from_json(const std::string &data) { void Resource::from_json(const String &data) {
} }
Resource::Resource() : Resource::Resource() :

View File

@ -1,7 +1,7 @@
#ifndef RESOURCE_H #ifndef RESOURCE_H
#define RESOURCE_H #define RESOURCE_H
#include <string> #include "core/string.h"
#include "reference.h" #include "reference.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
@ -16,8 +16,8 @@ class Resource : public Reference {
public: public:
int id; int id;
virtual std::string to_json(rapidjson::Document *into = nullptr); virtual String to_json(rapidjson::Document *into = nullptr);
virtual void from_json(const std::string &data); virtual void from_json(const String &data);
Resource(); Resource();
~Resource(); ~Resource();

View File

@ -3,7 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
void Settings::parse_file(const std::string &path) { void Settings::parse_file(const String &path) {
FILE *f = fopen(path.c_str(), "r"); FILE *f = fopen(path.c_str(), "r");
if (!f) { if (!f) {
@ -15,10 +15,10 @@ void Settings::parse_file(const std::string &path) {
long fsize = ftell(f); long fsize = ftell(f);
fseek(f, 0, SEEK_SET); /* same as rewind(f); */ fseek(f, 0, SEEK_SET); /* same as rewind(f); */
std::string config_str; String config_str;
config_str.resize(fsize); config_str.resize(fsize);
fread(&config_str[0], 1, fsize, f); fread(config_str.dataw(), 1, fsize, f);
fclose(f); fclose(f);
settings.Parse(config_str.c_str()); settings.Parse(config_str.c_str());

View File

@ -1,7 +1,7 @@
#ifndef SETTINGS_H #ifndef SETTINGS_H
#define SETTINGS_H #define SETTINGS_H
#include <string> #include "core/string.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
@ -9,7 +9,7 @@ class Settings {
public: public:
rapidjson::Document settings; rapidjson::Document settings;
void parse_file(const std::string &path); void parse_file(const String &path);
static Settings *get_singleton(); static Settings *get_singleton();

View File

@ -115,8 +115,8 @@ void String::resize(const int s) {
_data[_size] = '\0'; _data[_size] = '\0';
} }
int String::find(const char val) const { int String::find(const char val, const int from) const {
for (int i = 0; i < _size; ++i) { for (int i = from; i < _size; ++i) {
if (_data[i] == val) { if (_data[i] == val) {
return i; return i;
} }
@ -125,6 +125,26 @@ int String::find(const char val) const {
return -1; return -1;
} }
int String::find(const String &val, const int from) const {
int ve = _size - val.size();
for (int i = from; i < ve; ++i) {
bool found = true;
for (int j = 0; j < val.size(); ++j) {
if (_data[i + j] != val[j]) {
found = false;
break;
}
}
if (found) {
return i;
}
}
return -1;
}
void String::get_substr(char *into_buf, const int start_index, const int len) { void String::get_substr(char *into_buf, const int start_index, const int len) {
ERR_FAIL_INDEX(start_index + len - 1, _size); ERR_FAIL_INDEX(start_index + len - 1, _size);
@ -150,7 +170,7 @@ String String::substr(const int start_index, const int len) {
int sil = start_index + len; int sil = start_index + len;
ERR_FAIL_INDEX_V(sil, _size, String()); ERR_FAIL_INDEX_V(sil, _size + 1, String());
String str; String str;
str.ensure_capacity(len + 1); str.ensure_capacity(len + 1);
@ -163,6 +183,54 @@ String String::substr(const int start_index, const int len) {
return str; return str;
} }
void String::replace_from(const int start_index, const int length, const String &with) {
ERR_FAIL_INDEX(start_index, _size);
int sil = start_index + length;
ERR_FAIL_INDEX(sil, _size + 1);
if (length < with.size()) {
int loffs = with.size() - length;
ensure_capacity(_size + loffs + 1);
_size += loffs;
_data[_size] = '\0';
for (int i = _size - 1; i > start_index + loffs; --i) {
_data[i] = _data[i - loffs];
}
} else if (length > with.size()) {
int loffs = length - with.size();
for (int i = start_index + with.size(); i < _size; ++i) {
_data[i] = _data[i + loffs];
}
_size -= loffs;
}
for (int i = 0; i < length; ++i) {
_data[i + start_index] = with._data[i];
}
}
void String::replace(const String &find_str, const String &with) {
if (empty()) {
return;
}
if (find_str.empty())
return;
int start_pos = 0;
while ((start_pos = find(find_str, start_pos)) != -1) {
replace_from(start_pos, find_str.size(), with);
start_pos += with.size();
}
}
int String::compare(const String &other) const { int String::compare(const String &other) const {
if (size() < other.size()) { if (size() < other.size()) {
return 1; return 1;

View File

@ -22,11 +22,15 @@ public:
int capacity() const; int capacity() const;
void ensure_capacity(const int capacity); void ensure_capacity(const int capacity);
void resize(const int s); void resize(const int s);
int find(const char val) const; int find(const char val, const int from = 0) const;
int find(const String &val, const int from = 0) const;
void get_substr(char *into_buf, const int start_index, const int len); void get_substr(char *into_buf, const int start_index, const int len);
void get_substr_nt(char *into_buf, const int start_index, const int len); void get_substr_nt(char *into_buf, const int start_index, const int len);
String substr(const int start_index, const int len); String substr(const int start_index, const int len);
void replace_from(const int start_index, const int length, const String &with);
void replace(const String &find_str, const String &with);
int compare(const String &other) const; int compare(const String &other) const;
uint8_t read_uint8_bytes_at(int &index, bool advance_index = true); uint8_t read_uint8_bytes_at(int &index, bool advance_index = true);

View File

@ -6,12 +6,12 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
void Utils::newline_to_br(std::string *str) { void Utils::newline_to_br(String *str) {
str_replace(str, "\r\n", "<br>"); str->replace("\r\n", "<br>");
str_replace(str, "\n", "<br>"); str->replace("\n", "<br>");
} }
void Utils::markdown_to_html(std::string *str) { void Utils::markdown_to_html(String *str) {
std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>(); std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>();
config->isEmphasizedParserEnabled = false; config->isEmphasizedParserEnabled = false;
config->isHTMLWrappedInParagraph = true; config->isHTMLWrappedInParagraph = true;
@ -20,13 +20,13 @@ void Utils::markdown_to_html(std::string *str) {
std::stringstream ss((*str)); std::stringstream ss((*str));
std::string htmlOutput = parser->Parse(ss); String htmlOutput = parser->Parse(ss);
(*str) = htmlOutput; (*str) = htmlOutput;
} }
std::string Utils::get_pagination(const std::string base_url, const uint32_t max, const uint32_t current_index, const uint32_t max_visible_links) { String Utils::get_pagination(const String base_url, const uint32_t max, const uint32_t current_index, const uint32_t max_visible_links) {
std::string s = base_url; String s = base_url;
if (s.size() > 0 && s[s.size() - 1] != '/') { if (s.size() > 0 && s[s.size() - 1] != '/') {
s += '/'; s += '/';
} }
@ -103,8 +103,8 @@ std::string Utils::get_pagination(const std::string base_url, const uint32_t max
return b.result; return b.result;
} }
std::string Utils::get_pagination_links(const std::string base_url, const std::vector<std::string> &links, const uint32_t current_index, const uint32_t max_visible_links) { String Utils::get_pagination_links(const String base_url, const Vector<String> &links, const uint32_t current_index, const uint32_t max_visible_links) {
std::string s = base_url; String s = base_url;
if (s.size() > 0 && s[s.size() - 1] != '/') { if (s.size() > 0 && s[s.size() - 1] != '/') {
s += '/'; s += '/';
} }
@ -183,13 +183,3 @@ std::string Utils::get_pagination_links(const std::string base_url, const std::v
return b.result; return b.result;
} }
void Utils::str_replace(std::string *str, const std::string &from, const std::string &to) {
if (from.empty())
return;
size_t start_pos = 0;
while ((start_pos = str->find(from, start_pos)) != std::string::npos) {
str->replace(start_pos, from.length(), to);
start_pos += to.length();
}
}

View File

@ -1,20 +1,18 @@
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
#include <string> #include "core/string.h"
#include <vector> #include "core/containers/vector.h"
class Utils { class Utils {
public: public:
static void newline_to_br(std::string *str); static void newline_to_br(String *str);
//htmlspecialchars //htmlspecialchars
static void markdown_to_html(std::string *str); static void markdown_to_html(String *str);
static std::string get_pagination(const std::string base_url, const uint32_t max, const uint32_t current_index, const uint32_t max_visible_links = 10); static String get_pagination(const String base_url, const uint32_t max, const uint32_t current_index, const uint32_t max_visible_links = 10);
static std::string get_pagination_links(const std::string base_url, const std::vector<std::string> &links, const uint32_t current_index, const uint32_t max_visible_links = 10); static String get_pagination_links(const String base_url, const Vector<String> &links, const uint32_t current_index, const uint32_t max_visible_links = 10);
static void str_replace(std::string *str, const std::string &from, const std::string &to);
protected: protected:
}; };

View File

@ -9,7 +9,7 @@
#include <iostream> #include <iostream>
void ListPage::index(Request *request) { void ListPage::index(Request *request) {
std::string r = ""; String r = "";
for (uint32_t i = 0; i < list_entries.size(); ++i) { for (uint32_t i = 0; i < list_entries.size(); ++i) {
r += "<div class=\"list_entry\">" + list_entries[i] + "</div>"; r += "<div class=\"list_entry\">" + list_entries[i] + "</div>";
@ -26,7 +26,7 @@ void ListPage::load() {
return; return;
} }
std::vector<std::string> files; std::vector<String> files;
tinydir_dir dir; tinydir_dir dir;
if (tinydir_open(&dir, folder.c_str()) == -1) { if (tinydir_open(&dir, folder.c_str()) == -1) {
@ -42,7 +42,7 @@ void ListPage::load() {
} }
if (!file.is_dir) { if (!file.is_dir) {
std::string np = file.path; String np = file.path;
files.push_back(np); files.push_back(np);
} }
@ -52,7 +52,8 @@ void ListPage::load() {
tinydir_close(&dir); tinydir_close(&dir);
std::sort(files.begin(), files.end()); //todo
//std::sort(files.begin(), files.end());
for (uint32_t i = 0; i < files.size(); ++i) { for (uint32_t i = 0; i < files.size(); ++i) {
FILE *f = fopen(files[i].c_str(), "r"); FILE *f = fopen(files[i].c_str(), "r");
@ -66,7 +67,7 @@ void ListPage::load() {
long fsize = ftell(f); long fsize = ftell(f);
fseek(f, 0, SEEK_SET); /* same as rewind(f); */ fseek(f, 0, SEEK_SET); /* same as rewind(f); */
std::string fd; String fd;
fd.resize(fsize); fd.resize(fsize);
fread(&fd[0], 1, fsize, f); fread(&fd[0], 1, fsize, f);

View File

@ -1,8 +1,8 @@
#ifndef LIST_PAGE_H #ifndef LIST_PAGE_H
#define LIST_PAGE_H #define LIST_PAGE_H
#include <vector> #include "core/containers/vector.h"
#include <string> #include "core/string.h"
#include "core/object.h" #include "core/object.h"
@ -20,8 +20,8 @@ public:
ListPage(); ListPage();
~ListPage(); ~ListPage();
std::vector<std::string> list_entries; Vector<String> list_entries;
std::string folder; String folder;
}; };
#endif #endif

View File

@ -13,13 +13,13 @@ void MessagePage::index(Request *request) {
Ref<QueryResult> res = db->query(b->query_result); Ref<QueryResult> res = db->query(b->query_result);
std::vector<std::string> msgs; Vector<String> msgs;
while (res->next_row()) { while (res->next_row()) {
msgs.push_back(res->get_cell(0)); msgs.push_back(res->get_cell(0));
} }
std::string r = "<html><body>"; String r = "<html><body>";
for (uint32_t i = 0; i < messages.size(); ++i) { for (uint32_t i = 0; i < messages.size(); ++i) {
r += "<p>" + messages[i] + "</p><br>"; r += "<p>" + messages[i] + "</p><br>";

View File

@ -1,8 +1,8 @@
#ifndef MESSAGE_PAGE_H #ifndef MESSAGE_PAGE_H
#define MESSAGE_PAGE_H #define MESSAGE_PAGE_H
#include <vector> #include "core/containers/vector.h"
#include <string> #include "core/string.h"
#include "core/object.h" #include "core/object.h"
@ -20,7 +20,7 @@ public:
MessagePage(); MessagePage();
~MessagePage(); ~MessagePage();
std::vector<std::string> messages; Vector<String> messages;
}; };
#endif #endif

View File

@ -11,7 +11,7 @@
#include "core/http/web_application.h" #include "core/http/web_application.h"
void PagedArticle::index(Request *request) { void PagedArticle::index(Request *request) {
const std::string r = request->get_current_path_segment(); const String r = request->get_current_path_segment();
Article *s = pages[r]; Article *s = pages[r];
@ -22,13 +22,13 @@ void PagedArticle::index(Request *request) {
request->push_path(); request->push_path();
const std::string rp = request->get_current_path_segment(); const String rp = request->get_current_path_segment();
if (request->get_remaining_segment_count() > 1 && rp == "files") { if (request->get_remaining_segment_count() > 1 && rp == "files") {
std::string file_name = "/" + request->get_path_segment(request->get_current_segment_index() + 1); String file_name = "/" + request->get_path_segment(request->get_current_segment_index() + 1);
if (s->file_cache->wwwroot_has_file(file_name)) { if (s->file_cache->wwwroot_has_file(file_name)) {
std::string fp = s->file_cache->wwwroot + file_name; String fp = s->file_cache->wwwroot + file_name;
request->send_file(fp); request->send_file(fp);
return; return;
@ -44,7 +44,7 @@ void PagedArticle::index(Request *request) {
return; return;
} }
const std::string *page = s->pages[rp]; const String *page = s->pages[rp];
if (page == nullptr) { if (page == nullptr) {
//bad url //bad url
@ -90,17 +90,17 @@ void PagedArticle::load() {
continue; continue;
} }
std::string np = file.path; String np = file.path;
std::string fn = file.name; String fn = file.name;
std::string ff = folder + "/" + fn; String ff = folder + "/" + fn;
std::string wp = base_path + "/" + fn; String wp = base_path + "/" + fn;
Article *a = load_folder(np, wp); Article *a = load_folder(np, wp);
if (a) { if (a) {
std::string p = file.name; String p = file.name;
a->url = p; a->url = p;
pages[p] = a; pages[p] = a;
@ -118,10 +118,10 @@ void PagedArticle::load() {
generate_summaries(); generate_summaries();
} }
Article *PagedArticle::load_folder(const std::string &folder, const std::string &path) { Article *PagedArticle::load_folder(const String &folder, const String &path) {
printf("PagedArticle: loading: %s\n", folder.c_str()); printf("PagedArticle: loading: %s\n", folder.c_str());
std::vector<std::string> files; Vector<String> files;
tinydir_dir dir; tinydir_dir dir;
if (tinydir_open(&dir, folder.c_str()) == -1) { if (tinydir_open(&dir, folder.c_str()) == -1) {
@ -137,7 +137,7 @@ Article *PagedArticle::load_folder(const std::string &folder, const std::string
} }
if (!file.is_dir) { if (!file.is_dir) {
std::string np = file.name; String np = file.name;
files.push_back(np); files.push_back(np);
} }
@ -151,12 +151,13 @@ Article *PagedArticle::load_folder(const std::string &folder, const std::string
return nullptr; return nullptr;
} }
std::sort(files.begin(), files.end()); //todo
//std::sort(files.begin(), files.end());
Article *article = new Article(); Article *article = new Article();
for (uint32_t i = 0; i < files.size(); ++i) { for (uint32_t i = 0; i < files.size(); ++i) {
std::string file_path = folder; String file_path = folder;
if (file_path.size() > 0 && file_path[file_path.size() - 1] != '/') if (file_path.size() > 0 && file_path[file_path.size() - 1] != '/')
file_path += "/"; file_path += "/";
@ -174,7 +175,7 @@ Article *PagedArticle::load_folder(const std::string &folder, const std::string
long fsize = ftell(f); long fsize = ftell(f);
fseek(f, 0, SEEK_SET); /* same as rewind(f); */ fseek(f, 0, SEEK_SET); /* same as rewind(f); */
std::string fd; String fd;
fd.resize(fsize); fd.resize(fsize);
fread(&fd[0], 1, fsize, f); fread(&fd[0], 1, fsize, f);
@ -182,11 +183,11 @@ Article *PagedArticle::load_folder(const std::string &folder, const std::string
Utils::markdown_to_html(&fd); Utils::markdown_to_html(&fd);
std::string pagination; String pagination;
pagination = Utils::get_pagination_links(path, files, i); pagination = Utils::get_pagination_links(path, files, i);
std::string *finals = new std::string(); String *finals = new String();
(*finals) += pagination; (*finals) += pagination;
(*finals) += fd; (*finals) += fd;
@ -203,7 +204,7 @@ Article *PagedArticle::load_folder(const std::string &folder, const std::string
} }
void PagedArticle::generate_summaries() { void PagedArticle::generate_summaries() {
for (std::map<std::string, Article *>::iterator it = pages.begin(); it != pages.end(); ++it) { for (std::map<String, Article *>::iterator it = pages.begin(); it != pages.end(); ++it) {
generate_summary((*it).second); generate_summary((*it).second);
} }
} }
@ -213,8 +214,8 @@ void PagedArticle::generate_summary(Article *article) {
return; return;
} }
for (std::map<std::string, std::string *>::iterator it = article->pages.begin(); it != article->pages.end(); ++it) { for (std::map<String, String *>::iterator it = article->pages.begin(); it != article->pages.end(); ++it) {
std::string *s = (*it).second; String *s = (*it).second;
if (s != nullptr) { if (s != nullptr) {
article->summary_page = (*s); article->summary_page = (*s);

View File

@ -2,8 +2,8 @@
#define PAGED_ARTICLE_H #define PAGED_ARTICLE_H
#include <map> #include <map>
#include <string> #include "core/containers/vector.h"
#include <vector> #include "core/string.h"
#include "core/file_cache.h" #include "core/file_cache.h"
#include "core/object.h" #include "core/object.h"
@ -11,16 +11,16 @@
#include "core/http/request.h" #include "core/http/request.h"
struct Article { struct Article {
std::string url; String url;
std::string summary_page; String summary_page;
std::map<std::string, std::string *> pages; std::map<String, String *> pages;
FileCache *file_cache; FileCache *file_cache;
Article() { Article() {
file_cache = new FileCache(); file_cache = new FileCache();
} }
~Article() { ~Article() {
for (std::map<std::string, std::string *>::iterator it = pages.begin(); it != pages.end(); ++it) { for (std::map<String, String *>::iterator it = pages.begin(); it != pages.end(); ++it) {
delete ((*it).second); delete ((*it).second);
} }
@ -37,16 +37,16 @@ public:
void index(Request *request); void index(Request *request);
void load(); void load();
Article *load_folder(const std::string &folder, const std::string &path); Article *load_folder(const String &folder, const String &path);
void generate_summaries(); void generate_summaries();
void generate_summary(Article *article); void generate_summary(Article *article);
PagedArticle(); PagedArticle();
~PagedArticle(); ~PagedArticle();
std::map<std::string, Article *> pages; std::map<String, Article *> pages;
std::string folder; String folder;
std::string base_path; String base_path;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
#include "core/html/html_builder.h" #include "core/html/html_builder.h"
void PagedList::index(Request *request) { void PagedList::index(Request *request) {
const std::string path = request->get_current_path_segment(); const String path = request->get_current_path_segment();
if (request->get_remaining_segment_count() == 0) { if (request->get_remaining_segment_count() == 0) {
main_page->index(request); main_page->index(request);

View File

@ -3,7 +3,7 @@
#include "core/object.h" #include "core/object.h"
#include <string> #include "core/string.h"
#include "modules/list_page/list_page.h" #include "modules/list_page/list_page.h"
#include "modules/paged_article/paged_article.h" #include "modules/paged_article/paged_article.h"
@ -19,8 +19,8 @@ public:
ListPage *main_page; ListPage *main_page;
PagedArticle *articles; PagedArticle *articles;
std::string folder; String folder;
std::string base_path; String base_path;
}; };
#endif #endif

View File

@ -22,7 +22,7 @@
#include "core/utils.h" #include "core/utils.h"
#include "user_model.h" #include "user_model.h"
std::string User::to_json(rapidjson::Document *into) { String User::to_json(rapidjson::Document *into) {
rapidjson::Document *document; rapidjson::Document *document;
if (into) { if (into) {
@ -53,14 +53,14 @@ std::string User::to_json(rapidjson::Document *into) {
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document->Accept(writer); document->Accept(writer);
std::string s = buffer.GetString(); String s = buffer.GetString();
delete document; delete document;
return s; return s;
} }
void User::from_json(const std::string &p_data) { void User::from_json(const String &p_data) {
rapidjson::Document data; rapidjson::Document data;
data.Parse(p_data.c_str()); data.Parse(p_data.c_str());

View File

@ -1,10 +1,11 @@
#ifndef USER_H #ifndef USER_H
#define USER_H #define USER_H
#include "core/string.h"
#include "core/resource.h" #include "core/resource.h"
#include <mutex> #include <mutex>
#include <string>
class Request; class Request;
class FormValidator; class FormValidator;
@ -13,18 +14,18 @@ class User : public Resource {
RCPP_OBJECT(User, Resource); RCPP_OBJECT(User, Resource);
public: public:
std::string name_user_input; String name_user_input;
std::string email_user_input; String email_user_input;
int rank; int rank;
std::string pre_salt; String pre_salt;
std::string post_salt; String post_salt;
std::string password_hash; String password_hash;
bool banned; bool banned;
std::string password_reset_token; String password_reset_token;
bool locked; bool locked;
std::string to_json(rapidjson::Document *into = nullptr); String to_json(rapidjson::Document *into = nullptr);
void from_json(const std::string &data); void from_json(const String &data);
User(); User();
~User(); ~User();