Skip to content

Commit

Permalink
Merge pull request #478 from analogjupiter/ini
Browse files Browse the repository at this point in the history
Add `arsd.ini` module
  • Loading branch information
adamdruppe authored Feb 17, 2025
2 parents 644c186 + 5d31192 commit 31fa714
Show file tree
Hide file tree
Showing 4 changed files with 3,221 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Go to the file+line number from the error message and change `Event` to `FocusIn

arsd.pixmappresenter, arsd.pixmappaint and arsd.pixmaprecorder were added.

arsd.ini was added.

## 11.0

Released: Planned for May 2023, actually out August 2023.
Expand Down
49 changes: 49 additions & 0 deletions core.d
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,55 @@ ref T reinterpretCast(T, V)(return ref V value) @system {
return *cast(T*)& value;
}

/++
Determines whether `needle` is a slice of `haystack`.
History:
Added on February 11, 2025.
+/
bool isSliceOf(T1, T2)(scope const(T1)[] needle, scope const(T2)[] haystack) @trusted pure nothrow @nogc {
return (
needle.ptr >= haystack.ptr
&& ((needle.ptr + needle.length) <= (haystack.ptr + haystack.length))
);
}

///
@safe unittest {
string s0 = "01234";
const(char)[] s1 = s0[1 .. $];
const(void)[] s2 = s1.castTo!(const(void)[]);
string s3 = s1.idup;

assert( s0.isSliceOf(s0));
assert( s1.isSliceOf(s0));
assert( s2.isSliceOf(s0));
assert(!s3.isSliceOf(s0));

assert(!s0.isSliceOf(s1));
assert( s1.isSliceOf(s1));
assert( s2.isSliceOf(s1));
assert(!s3.isSliceOf(s1));

assert(!s0.isSliceOf(s2));
assert( s1.isSliceOf(s2));
assert( s2.isSliceOf(s2));
assert(!s3.isSliceOf(s2));

assert(!s0.isSliceOf(s3));
assert(!s1.isSliceOf(s3));
assert(!s2.isSliceOf(s3));
assert( s3.isSliceOf(s3));

assert(s1.length == 4);
assert(s1[0 .. 0].isSliceOf(s1));
assert(s1[0 .. 1].isSliceOf(s1));
assert(s1[1 .. 2].isSliceOf(s1));
assert(s1[1 .. 3].isSliceOf(s1));
assert(s1[1 .. $].isSliceOf(s1));
assert(s1[$ .. $].isSliceOf(s1));
}

/++
Does math as a 64 bit number, but saturates at int.min and int.max when converting back to a 32 bit int.
Expand Down
12 changes: 12 additions & 0 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,18 @@
"dflags-dmd": ["-mv=arsd.archive=$PACKAGE_DIR/archive.d"],
"dflags-ldc": ["--mv=arsd.archive=$PACKAGE_DIR/archive.d"],
"dflags-gdc": ["-fmodule-file=arsd.archive=$PACKAGE_DIR/archive.d"]
},
{
"name": "ini",
"description": "INI configuration file support - configurable INI parser and serializer with support for various dialects.",
"targetType": "library",
"sourceFiles": ["ini.d"],
"dependencies": {
"arsd-official:core":"*"
},
"dflags-dmd": ["-mv=arsd.ini=$PACKAGE_DIR/ini.d"],
"dflags-ldc": ["--mv=arsd.ini=$PACKAGE_DIR/ini.d"],
"dflags-gdc": ["-fmodule-file=arsd.ini=$PACKAGE_DIR/ini.d"]
}
]
}
Loading

0 comments on commit 31fa714

Please sign in to comment.