Now with the ability to ask for formtted text
This commit is contained in:
@@ -5,6 +5,7 @@ fn main() {
|
|||||||
|
|
||||||
cxx_build::bridge("src/cxx/mod.rs")
|
cxx_build::bridge("src/cxx/mod.rs")
|
||||||
.file("src/cxx/mgr.cc")
|
.file("src/cxx/mgr.cc")
|
||||||
|
.file("src/cxx/module.cc")
|
||||||
.includes(deps.all_include_paths())
|
.includes(deps.all_include_paths())
|
||||||
.cpp_link_stdlib("stdc++")
|
.cpp_link_stdlib("stdc++")
|
||||||
.flag("-Os")
|
.flag("-Os")
|
||||||
|
|||||||
+27
-17
@@ -1,24 +1,34 @@
|
|||||||
#include "mgr.h"
|
#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
|
// Set the desired output format
|
||||||
Mgr::Mgr(const char *path) : sword::SWMgr(path, true, 0, false, false) { }
|
Mgr::Mgr(uint8_t format) : sword::SWMgr(0, 0, true, new sword::MarkupFilterMgr(format)) { }
|
||||||
|
|
||||||
rust::Vec<rust::String> Mgr::get_modules() const {
|
// Only the last argument is different from default - we want to limit this to ONLY the given directory
|
||||||
rust::Vec<rust::String> v;
|
Mgr::Mgr(const char *path) : sword::SWMgr(path, true, 0, false, false) { }
|
||||||
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() {
|
rust::Vec<rust::String> Mgr::get_modules() const {
|
||||||
return std::unique_ptr<Mgr>(new Mgr());
|
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::unique_ptr<Mgr> new_mgr() {
|
||||||
std::string cpath(path);
|
return std::unique_ptr<Mgr>(new Mgr());
|
||||||
return std::unique_ptr<Mgr>(new Mgr(cpath.c_str()));
|
}
|
||||||
|
|
||||||
|
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 "rust/cxx.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
class Mgr : public sword::SWMgr {
|
namespace sword_rs {
|
||||||
public:
|
class Mgr : public sword::SWMgr {
|
||||||
Mgr();
|
public:
|
||||||
Mgr(const char*);
|
Mgr();
|
||||||
rust::Vec<rust::String> get_modules() const;
|
Mgr(uint8_t format);
|
||||||
std::unique_ptr<Module> get_module(const rust::String &name) {
|
Mgr(const char*);
|
||||||
return std::unique_ptr<Module>(new Module(this->getModule(std::string(name).c_str())));
|
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();
|
||||||
std::unique_ptr<Mgr> new_mgr_with_path(const rust::String &path);
|
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 {
|
pub mod ffi {
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!("sword_rs/src/cxx/mgr.h");
|
include!("sword_rs/src/cxx/mgr.h");
|
||||||
@@ -7,6 +7,7 @@ pub mod ffi {
|
|||||||
type Mgr;
|
type Mgr;
|
||||||
|
|
||||||
fn new_mgr() -> UniquePtr<Mgr>;
|
fn new_mgr() -> UniquePtr<Mgr>;
|
||||||
|
fn new_mgr_format(format: u8) -> UniquePtr<Mgr>;
|
||||||
fn new_mgr_with_path(path: &String) -> UniquePtr<Mgr>;
|
fn new_mgr_with_path(path: &String) -> UniquePtr<Mgr>;
|
||||||
fn get_modules(self: &Mgr) -> Vec<String>;
|
fn get_modules(self: &Mgr) -> Vec<String>;
|
||||||
fn get_module(self: Pin<&mut Mgr>, name: &String) -> UniquePtr<Module>;
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <sword/swmodule.h>
|
#include <sword/swmodule.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "rust/cxx.h"
|
#include "rust/cxx.h"
|
||||||
|
|
||||||
class Module {
|
namespace sword_rs {
|
||||||
private:
|
class Module {
|
||||||
sword::SWModule* module;
|
private:
|
||||||
|
sword::SWModule* module;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Module(sword::SWModule* module) : module(module) { };
|
Module(sword::SWModule* module);
|
||||||
|
|
||||||
rust::String get_name() const {
|
rust::String get_name() const;
|
||||||
return rust::String(this->module->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
rust::String strip_text() {
|
rust::String strip_text();
|
||||||
return std::string(
|
|
||||||
(const char*) this->module->stripText()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_key_text(const rust::String& keyText) {
|
void set_key_text(const rust::String& keyText);
|
||||||
this->module->setKeyText(std::string(keyText).c_str());
|
};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|||||||
+23
@@ -2,6 +2,23 @@ use crate::cxx::ffi;
|
|||||||
use crate::module::Module;
|
use crate::module::Module;
|
||||||
use cxx::UniquePtr;
|
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 {
|
pub struct Mgr {
|
||||||
mgr: UniquePtr<ffi::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 {
|
pub fn new_with_path(path: &String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
mgr: ffi::new_mgr_with_path(path),
|
mgr: ffi::new_mgr_with_path(path),
|
||||||
|
|||||||
Reference in New Issue
Block a user