using more useful functions

This commit is contained in:
Adam D. Ruppe 2025-11-03 19:22:09 -05:00
parent e73713c026
commit e8cacb7277
4 changed files with 97 additions and 5 deletions

View File

@ -11,10 +11,26 @@
"description": "Shared components across other arsd modules", "description": "Shared components across other arsd modules",
"targetType": "library", "targetType": "library",
"libs-windows": ["user32", "ws2_32"], "libs-windows": ["user32", "ws2_32"],
"dflags-dmd": ["-mv=arsd.core=$PACKAGE_DIR/core.d"], "dflags-dmd": [
"dflags-ldc": ["--mv=arsd.core=$PACKAGE_DIR/core.d"], "-mv=arsd.core=$PACKAGE_DIR/core.d",
"dflags-gdc": ["-fmodule-file=arsd.core=$PACKAGE_DIR/core.d"], "-mv=arsd.string=$PACKAGE_DIR/string.d",
"sourceFiles": ["core.d"] "-mv=arsd.conv=$PACKAGE_DIR/conv.d"
],
"dflags-ldc": [
"--mv=arsd.core=$PACKAGE_DIR/core.d",
"--mv=arsd.string=$PACKAGE_DIR/string.d",
"--mv=arsd.conv=$PACKAGE_DIR/conv.d"
],
"dflags-gdc": [
"-fmodule-file=arsd.core=$PACKAGE_DIR/core.d",
"-fmodule-file=arsd.string=$PACKAGE_DIR/string.d",
"-fmodule-file=arsd.conv=$PACKAGE_DIR/conv.d"
],
"sourceFiles": [
"core.d",
"string.d",
"conv.d"
]
}, },
{ {
"name": "simpledisplay", "name": "simpledisplay",

View File

@ -2,7 +2,8 @@
module arsd.oauth; module arsd.oauth;
import arsd.curl; import arsd.curl;
import arsd.cgi; // for decodeVariables import arsd.uri;
import arsd.cgi : Cgi;
import std.array; import std.array;
static import std.uri; static import std.uri;
static import std.algorithm; static import std.algorithm;

View File

@ -53,3 +53,76 @@ deprecated("D calls this `stripRight` instead") alias trimRight = stripRight;
alias stringz = arsd.core.stringz; alias stringz = arsd.core.stringz;
// CharzBuffer // CharzBuffer
// WCharzBuffer // WCharzBuffer
// ********* UTILITIES **************
string[] split(string s, string onWhat) {
assert(onWhat.length);
string[] ret;
more:
auto idx = s.indexOf(onWhat);
if(idx == -1) {
ret ~= s;
return ret;
}
ret ~= s[0 .. idx];
s = s[idx + onWhat.length .. $];
goto more;
}
unittest {
assert("foo.bar".split(".") == ["foo", "bar"]);
}
ptrdiff_t lastIndexOf(string s, string what) {
assert(what.length);
if(s.length < what.length)
return -1;
ptrdiff_t checking = s.length - what.length;
while(checking >= 0) {
if(s[checking .. checking + what.length] == what)
return checking;
checking--;
}
return -1;
}
unittest {
assert("31234".lastIndexOf("3") == 3);
}
string join(string[] str, string w) {
string ret;
foreach(i, s; str) {
if(i)
ret ~= w;
ret ~= s;
}
return ret;
}
unittest {
assert(["a", "b"].join(" ") == "a b");
}
string replace(string str, string find, string repacement) {
assert(find.length);
string ret;
more:
auto idx = str.indexOf(find);
if(idx == -1) {
ret ~= str;
return ret;
}
ret ~= str[0 .. idx];
ret ~= repacement;
str = str[idx + find.length .. $];
goto more;
}
unittest {
assert("foobarfoo".replace("foo", "bar") == "barbarbar");
}

2
web.d
View File

@ -11,6 +11,8 @@
+/ +/
module arsd.web; module arsd.web;
import arsd.uri : decodeVariablesSingle, encodeVariables;
static if(__VERSION__ <= 2076) { static if(__VERSION__ <= 2076) {
// compatibility shims with gdc // compatibility shims with gdc
enum JSONType { enum JSONType {