Now with the ability to ask for formtted text
This commit is contained in:
+27
-17
@@ -1,24 +1,34 @@
|
||||
#include "mgr.h"
|
||||
#include <sword/markupfiltmgr.h>
|
||||
|
||||
Mgr::Mgr() { }
|
||||
namespace sword_rs {
|
||||
Mgr::Mgr() { }
|
||||
|
||||
// Only the last argument is different from default - we want to limit this to ONLY the given directory
|
||||
Mgr::Mgr(const char *path) : sword::SWMgr(path, true, 0, false, false) { }
|
||||
// Set the desired output format
|
||||
Mgr::Mgr(uint8_t format) : sword::SWMgr(0, 0, true, new sword::MarkupFilterMgr(format)) { }
|
||||
|
||||
rust::Vec<rust::String> Mgr::get_modules() const {
|
||||
rust::Vec<rust::String> v;
|
||||
v.reserve(this->getModules().size());
|
||||
for (sword::ModMap::const_iterator it = this->getModules().begin(); it != this->getModules().end(); ++it) {
|
||||
v.push_back(rust::String(it->first.c_str()));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
// Only the last argument is different from default - we want to limit this to ONLY the given directory
|
||||
Mgr::Mgr(const char *path) : sword::SWMgr(path, true, 0, false, false) { }
|
||||
|
||||
std::unique_ptr<Mgr> new_mgr() {
|
||||
return std::unique_ptr<Mgr>(new Mgr());
|
||||
}
|
||||
rust::Vec<rust::String> Mgr::get_modules() const {
|
||||
rust::Vec<rust::String> v;
|
||||
v.reserve(this->getModules().size());
|
||||
for (sword::ModMap::const_iterator it = this->getModules().begin(); it != this->getModules().end(); ++it) {
|
||||
v.push_back(rust::String(it->first.c_str()));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
std::unique_ptr<Mgr> new_mgr_with_path(const rust::String &path) {
|
||||
std::string cpath(path);
|
||||
return std::unique_ptr<Mgr>(new Mgr(cpath.c_str()));
|
||||
std::unique_ptr<Mgr> new_mgr() {
|
||||
return std::unique_ptr<Mgr>(new Mgr());
|
||||
}
|
||||
|
||||
std::unique_ptr<Mgr> new_mgr_format(uint8_t format) {
|
||||
return std::unique_ptr<Mgr>(new Mgr(format));
|
||||
}
|
||||
|
||||
std::unique_ptr<Mgr> new_mgr_with_path(const rust::String &path) {
|
||||
std::string cpath(path);
|
||||
return std::unique_ptr<Mgr>(new Mgr(cpath.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-11
@@ -7,15 +7,19 @@
|
||||
#include "rust/cxx.h"
|
||||
#include "module.h"
|
||||
|
||||
class Mgr : public sword::SWMgr {
|
||||
public:
|
||||
Mgr();
|
||||
Mgr(const char*);
|
||||
rust::Vec<rust::String> get_modules() const;
|
||||
std::unique_ptr<Module> get_module(const rust::String &name) {
|
||||
return std::unique_ptr<Module>(new Module(this->getModule(std::string(name).c_str())));
|
||||
};
|
||||
};
|
||||
namespace sword_rs {
|
||||
class Mgr : public sword::SWMgr {
|
||||
public:
|
||||
Mgr();
|
||||
Mgr(uint8_t format);
|
||||
Mgr(const char*);
|
||||
rust::Vec<rust::String> get_modules() const;
|
||||
std::unique_ptr<Module> get_module(const rust::String &name) {
|
||||
return std::unique_ptr<Module>(new Module(this->getModule(std::string(name).c_str())));
|
||||
};
|
||||
};
|
||||
|
||||
std::unique_ptr<Mgr> new_mgr();
|
||||
std::unique_ptr<Mgr> new_mgr_with_path(const rust::String &path);
|
||||
std::unique_ptr<Mgr> new_mgr();
|
||||
std::unique_ptr<Mgr> new_mgr_format(uint8_t format);
|
||||
std::unique_ptr<Mgr> new_mgr_with_path(const rust::String &path);
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
#[cxx::bridge]
|
||||
#[cxx::bridge(namespace = "sword_rs")]
|
||||
pub mod ffi {
|
||||
unsafe extern "C++" {
|
||||
include!("sword_rs/src/cxx/mgr.h");
|
||||
@@ -7,6 +7,7 @@ pub mod ffi {
|
||||
type Mgr;
|
||||
|
||||
fn new_mgr() -> UniquePtr<Mgr>;
|
||||
fn new_mgr_format(format: u8) -> UniquePtr<Mgr>;
|
||||
fn new_mgr_with_path(path: &String) -> UniquePtr<Mgr>;
|
||||
fn get_modules(self: &Mgr) -> Vec<String>;
|
||||
fn get_module(self: Pin<&mut Mgr>, name: &String) -> UniquePtr<Module>;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "module.h"
|
||||
|
||||
namespace sword_rs {
|
||||
Module::Module(sword::SWModule* module) : module(module) { }
|
||||
|
||||
rust::String Module::get_name() const {
|
||||
return rust::String(this->module->getName());
|
||||
}
|
||||
|
||||
rust::String Module::strip_text() {
|
||||
return std::string(
|
||||
(const char*) this->module->stripText()
|
||||
);
|
||||
}
|
||||
|
||||
void Module::set_key_text(const rust::String& keyText) {
|
||||
this->module->setKeyText(std::string(keyText).c_str());
|
||||
}
|
||||
}
|
||||
+12
-17
@@ -1,27 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <sword/swmodule.h>
|
||||
#include <string>
|
||||
|
||||
#include "rust/cxx.h"
|
||||
|
||||
class Module {
|
||||
private:
|
||||
sword::SWModule* module;
|
||||
namespace sword_rs {
|
||||
class Module {
|
||||
private:
|
||||
sword::SWModule* module;
|
||||
|
||||
public:
|
||||
Module(sword::SWModule* module) : module(module) { };
|
||||
public:
|
||||
Module(sword::SWModule* module);
|
||||
|
||||
rust::String get_name() const {
|
||||
return rust::String(this->module->getName());
|
||||
}
|
||||
rust::String get_name() const;
|
||||
|
||||
rust::String strip_text() {
|
||||
return std::string(
|
||||
(const char*) this->module->stripText()
|
||||
);
|
||||
}
|
||||
rust::String strip_text();
|
||||
|
||||
void set_key_text(const rust::String& keyText) {
|
||||
this->module->setKeyText(std::string(keyText).c_str());
|
||||
}
|
||||
};
|
||||
void set_key_text(const rust::String& keyText);
|
||||
};
|
||||
}
|
||||
|
||||
+23
@@ -2,6 +2,23 @@ use crate::cxx::ffi;
|
||||
use crate::module::Module;
|
||||
use cxx::UniquePtr;
|
||||
|
||||
// The enum we are mimicking in sword has no name, therefore we cannot readily
|
||||
// check ourselves against it
|
||||
pub enum Format {
|
||||
Unknown = 0,
|
||||
Plain = 1,
|
||||
ThML = 2,
|
||||
GBF = 3,
|
||||
HTML = 4,
|
||||
HTMLHref = 5,
|
||||
RTF = 6,
|
||||
OSIS = 7,
|
||||
WebIf = 8,
|
||||
TEI = 9,
|
||||
XHTML = 10,
|
||||
Latex = 11,
|
||||
}
|
||||
|
||||
pub struct Mgr {
|
||||
mgr: UniquePtr<ffi::Mgr>,
|
||||
}
|
||||
@@ -13,6 +30,12 @@ impl Mgr {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_format(format: Format) -> Self {
|
||||
Self {
|
||||
mgr: ffi::new_mgr_format(format as u8),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_path(path: &String) -> Self {
|
||||
Self {
|
||||
mgr: ffi::new_mgr_with_path(path),
|
||||
|
||||
Reference in New Issue
Block a user