use @safe everywhere

with a little bit of evil @trusted magic...
This commit is contained in:
Jeremy Baxter 2024-02-13 09:40:44 +13:00
parent 2e93c891fd
commit 8b392c5bab
2 changed files with 28 additions and 17 deletions

View file

@ -30,6 +30,8 @@ import std.stdio : File;
import std.string : capitalize, tr, wrap;
import std.net.curl : HTTP;
@safe:
/** Indentation style to use when formatting passages. */
enum ESVIndent
{
@ -141,7 +143,7 @@ const string[] ESVAPI_PARAMETERS = [
* Otherwise, returns false.
*/
bool
bookValid(in char[] book) nothrow @safe
bookValid(in char[] book) nothrow
{
foreach (string b; BIBLE_BOOKS) {
if (book.capitalize() == b.capitalize())
@ -154,7 +156,7 @@ bookValid(in char[] book) nothrow @safe
* Otherwise, returns false.
*/
bool
verseValid(in char[] verse) @safe
verseValid(in char[] verse)
{
foreach (string re; [
"^\\d{1,3}$",
@ -193,7 +195,7 @@ class ESVApi
/**
* Constructs an ESVApi object using the given authentication key.
*/
this(string key, string tmpName = "esv") @safe
this(string key, string tmpName = "esv")
{
_key = key;
_tmp = tempDir() ~ tmpName;
@ -212,7 +214,7 @@ class ESVApi
* was constructed. This authentication key cannot be changed.
*/
final @property string
key() const nothrow pure @nogc @safe
key() const nothrow pure @nogc
{
return _key;
}
@ -220,7 +222,7 @@ class ESVApi
* Returns the subdirectory used to store temporary audio passages.
*/
final @property string
tmpDir() const nothrow pure @nogc @safe
tmpDir() const nothrow pure @nogc
{
return _tmp;
}
@ -228,7 +230,7 @@ class ESVApi
* Returns the API URL currently in use.
*/
final @property string
url() const nothrow pure @nogc @safe
url() const nothrow pure @nogc
{
return _url;
}
@ -236,7 +238,7 @@ class ESVApi
* Sets the API URL currently in use to the given url argument.
*/
final @property void
url(immutable(string) url) @safe
url(immutable(string) url)
in (!url.matchAll(`^https?://.+\\..+(/.+)?`).empty, "Invalid URL format")
{
_url = url;
@ -348,19 +350,21 @@ class ESVApi
lineLength = lineLength == 0 ? 80 : lineLength;
foreach (JSONValue item; resp["results"].array) {
layout ~= format!fmt(
item["reference"].str,
item["content"].str
.wrap(lineLength)
);
}
() @trusted {
foreach (JSONValue item; resp["results"].array) {
layout ~= format!fmt(
item["reference"].str,
item["content"].str
.wrap(lineLength)
);
}
}();
return layout;
}
protected char[]
makeRequest(in char[] query)
makeRequest(in char[] query) @trusted
{
char[] response;
HTTP request;
@ -394,7 +398,7 @@ struct ESVApiOptions
* If initialise is true, initialise an ESVApiOptions
* structure with the default values.
*/
this(bool initialise) nothrow @safe
this(bool initialise) nothrow
{
if (!initialise)
return;