mirror of https://github.com/adamdruppe/arsd.git
using more useful functions
This commit is contained in:
parent
e73713c026
commit
e8cacb7277
24
dub.json
24
dub.json
|
|
@ -11,10 +11,26 @@
|
|||
"description": "Shared components across other arsd modules",
|
||||
"targetType": "library",
|
||||
"libs-windows": ["user32", "ws2_32"],
|
||||
"dflags-dmd": ["-mv=arsd.core=$PACKAGE_DIR/core.d"],
|
||||
"dflags-ldc": ["--mv=arsd.core=$PACKAGE_DIR/core.d"],
|
||||
"dflags-gdc": ["-fmodule-file=arsd.core=$PACKAGE_DIR/core.d"],
|
||||
"sourceFiles": ["core.d"]
|
||||
"dflags-dmd": [
|
||||
"-mv=arsd.core=$PACKAGE_DIR/core.d",
|
||||
"-mv=arsd.string=$PACKAGE_DIR/string.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",
|
||||
|
|
|
|||
3
oauth.d
3
oauth.d
|
|
@ -2,7 +2,8 @@
|
|||
module arsd.oauth;
|
||||
|
||||
import arsd.curl;
|
||||
import arsd.cgi; // for decodeVariables
|
||||
import arsd.uri;
|
||||
import arsd.cgi : Cgi;
|
||||
import std.array;
|
||||
static import std.uri;
|
||||
static import std.algorithm;
|
||||
|
|
|
|||
73
string.d
73
string.d
|
|
@ -53,3 +53,76 @@ deprecated("D calls this `stripRight` instead") alias trimRight = stripRight;
|
|||
alias stringz = arsd.core.stringz;
|
||||
// CharzBuffer
|
||||
// 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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue