use @safe everywhere
with a little bit of evil @trusted magic...
This commit is contained in:
parent
2e93c891fd
commit
8b392c5bab
2 changed files with 28 additions and 17 deletions
9
esv.d
9
esv.d
|
@ -29,7 +29,7 @@ import std.getopt : getoptConfig = config;
|
||||||
import std.path : baseName, dirName, expandTilde, isValidPath;
|
import std.path : baseName, dirName, expandTilde, isValidPath;
|
||||||
import std.process : environment, executeShell;
|
import std.process : environment, executeShell;
|
||||||
import std.regex : regex, matchFirst, replaceAll, replaceFirst;
|
import std.regex : regex, matchFirst, replaceAll, replaceFirst;
|
||||||
import std.stdio : writef, writeln, writefln, stderr;
|
import std.stdio : writef, writeln, writefln, File;
|
||||||
import std.string : splitLines;
|
import std.string : splitLines;
|
||||||
|
|
||||||
import initial;
|
import initial;
|
||||||
|
@ -37,6 +37,8 @@ import initial;
|
||||||
import config;
|
import config;
|
||||||
import esvapi;
|
import esvapi;
|
||||||
|
|
||||||
|
@safe:
|
||||||
|
|
||||||
enum VERSION = "0.2.0";
|
enum VERSION = "0.2.0";
|
||||||
|
|
||||||
bool aFlag; /* audio */
|
bool aFlag; /* audio */
|
||||||
|
@ -49,6 +51,8 @@ bool rFlag, RFlag; /* passage references */
|
||||||
string sFlag; /* search passages */
|
string sFlag; /* search passages */
|
||||||
bool VFlag; /* show version */
|
bool VFlag; /* show version */
|
||||||
|
|
||||||
|
File stderr;
|
||||||
|
|
||||||
version (OpenBSD) {
|
version (OpenBSD) {
|
||||||
immutable(char) *promises;
|
immutable(char) *promises;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +62,9 @@ main(string[] args)
|
||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
|
/* @safe way of opening stderr on Unix */
|
||||||
|
stderr = File("/dev/stderr", "w");
|
||||||
|
|
||||||
version (OpenBSD) {
|
version (OpenBSD) {
|
||||||
import core.sys.openbsd.unistd : pledge;
|
import core.sys.openbsd.unistd : pledge;
|
||||||
import std.string : toStringz;
|
import std.string : toStringz;
|
||||||
|
|
36
esvapi.d
36
esvapi.d
|
@ -30,6 +30,8 @@ import std.stdio : File;
|
||||||
import std.string : capitalize, tr, wrap;
|
import std.string : capitalize, tr, wrap;
|
||||||
import std.net.curl : HTTP;
|
import std.net.curl : HTTP;
|
||||||
|
|
||||||
|
@safe:
|
||||||
|
|
||||||
/** Indentation style to use when formatting passages. */
|
/** Indentation style to use when formatting passages. */
|
||||||
enum ESVIndent
|
enum ESVIndent
|
||||||
{
|
{
|
||||||
|
@ -141,7 +143,7 @@ const string[] ESVAPI_PARAMETERS = [
|
||||||
* Otherwise, returns false.
|
* Otherwise, returns false.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
bookValid(in char[] book) nothrow @safe
|
bookValid(in char[] book) nothrow
|
||||||
{
|
{
|
||||||
foreach (string b; BIBLE_BOOKS) {
|
foreach (string b; BIBLE_BOOKS) {
|
||||||
if (book.capitalize() == b.capitalize())
|
if (book.capitalize() == b.capitalize())
|
||||||
|
@ -154,7 +156,7 @@ bookValid(in char[] book) nothrow @safe
|
||||||
* Otherwise, returns false.
|
* Otherwise, returns false.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
verseValid(in char[] verse) @safe
|
verseValid(in char[] verse)
|
||||||
{
|
{
|
||||||
foreach (string re; [
|
foreach (string re; [
|
||||||
"^\\d{1,3}$",
|
"^\\d{1,3}$",
|
||||||
|
@ -193,7 +195,7 @@ class ESVApi
|
||||||
/**
|
/**
|
||||||
* Constructs an ESVApi object using the given authentication key.
|
* Constructs an ESVApi object using the given authentication key.
|
||||||
*/
|
*/
|
||||||
this(string key, string tmpName = "esv") @safe
|
this(string key, string tmpName = "esv")
|
||||||
{
|
{
|
||||||
_key = key;
|
_key = key;
|
||||||
_tmp = tempDir() ~ tmpName;
|
_tmp = tempDir() ~ tmpName;
|
||||||
|
@ -212,7 +214,7 @@ class ESVApi
|
||||||
* was constructed. This authentication key cannot be changed.
|
* was constructed. This authentication key cannot be changed.
|
||||||
*/
|
*/
|
||||||
final @property string
|
final @property string
|
||||||
key() const nothrow pure @nogc @safe
|
key() const nothrow pure @nogc
|
||||||
{
|
{
|
||||||
return _key;
|
return _key;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +222,7 @@ class ESVApi
|
||||||
* Returns the subdirectory used to store temporary audio passages.
|
* Returns the subdirectory used to store temporary audio passages.
|
||||||
*/
|
*/
|
||||||
final @property string
|
final @property string
|
||||||
tmpDir() const nothrow pure @nogc @safe
|
tmpDir() const nothrow pure @nogc
|
||||||
{
|
{
|
||||||
return _tmp;
|
return _tmp;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +230,7 @@ class ESVApi
|
||||||
* Returns the API URL currently in use.
|
* Returns the API URL currently in use.
|
||||||
*/
|
*/
|
||||||
final @property string
|
final @property string
|
||||||
url() const nothrow pure @nogc @safe
|
url() const nothrow pure @nogc
|
||||||
{
|
{
|
||||||
return _url;
|
return _url;
|
||||||
}
|
}
|
||||||
|
@ -236,7 +238,7 @@ class ESVApi
|
||||||
* Sets the API URL currently in use to the given url argument.
|
* Sets the API URL currently in use to the given url argument.
|
||||||
*/
|
*/
|
||||||
final @property void
|
final @property void
|
||||||
url(immutable(string) url) @safe
|
url(immutable(string) url)
|
||||||
in (!url.matchAll(`^https?://.+\\..+(/.+)?`).empty, "Invalid URL format")
|
in (!url.matchAll(`^https?://.+\\..+(/.+)?`).empty, "Invalid URL format")
|
||||||
{
|
{
|
||||||
_url = url;
|
_url = url;
|
||||||
|
@ -348,19 +350,21 @@ class ESVApi
|
||||||
|
|
||||||
lineLength = lineLength == 0 ? 80 : lineLength;
|
lineLength = lineLength == 0 ? 80 : lineLength;
|
||||||
|
|
||||||
foreach (JSONValue item; resp["results"].array) {
|
() @trusted {
|
||||||
layout ~= format!fmt(
|
foreach (JSONValue item; resp["results"].array) {
|
||||||
item["reference"].str,
|
layout ~= format!fmt(
|
||||||
item["content"].str
|
item["reference"].str,
|
||||||
.wrap(lineLength)
|
item["content"].str
|
||||||
);
|
.wrap(lineLength)
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected char[]
|
protected char[]
|
||||||
makeRequest(in char[] query)
|
makeRequest(in char[] query) @trusted
|
||||||
{
|
{
|
||||||
char[] response;
|
char[] response;
|
||||||
HTTP request;
|
HTTP request;
|
||||||
|
@ -394,7 +398,7 @@ struct ESVApiOptions
|
||||||
* If initialise is true, initialise an ESVApiOptions
|
* If initialise is true, initialise an ESVApiOptions
|
||||||
* structure with the default values.
|
* structure with the default values.
|
||||||
*/
|
*/
|
||||||
this(bool initialise) nothrow @safe
|
this(bool initialise) nothrow
|
||||||
{
|
{
|
||||||
if (!initialise)
|
if (!initialise)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue