On 2/5/19 8:26 AM, Curt Tilmes wrote:
If you have glibc (probably yes for Linux or Mac, probably no for
Windows), you can call memmem():
use NativeCall;
sub memmem(Blob $haystack, size_t $haystacklen,
Blob $needle, size_t $needlelen --> Pointer) is native {}
sub buf-index(Blob
On 2/5/19 7:55 AM, Brad Gilbert wrote:
`index` is an NQP op, which means in this case that it is written in C
(assuming you are using MoarVM)
https://github.com/MoarVM/MoarVM/blob/ddde09508310a5f60c63474db8f9682bc922700b/src/strings/ops.c#L557-L656
The code I gave for finding a Buf inside of an
If you have glibc (probably yes for Linux or Mac, probably no for Windows),
you can call memmem():
use NativeCall;
sub memmem(Blob $haystack, size_t $haystacklen,
Blob $needle, size_t $needlelen --> Pointer) is native {}
sub buf-index(Blob $buffer, Blob $needle) {
(memmem($buffe
`index` is an NQP op, which means in this case that it is written in C
(assuming you are using MoarVM)
https://github.com/MoarVM/MoarVM/blob/ddde09508310a5f60c63474db8f9682bc922700b/src/strings/ops.c#L557-L656
The code I gave for finding a Buf inside of another one was quickly
made in a way to pr
On 2/2/19 9:29 PM, Brad Gilbert wrote:
Subs do not need to have a `return` statement if it is returning the last value.
You also broke the return value of the subroutine that I wrote by
assigning it to a variable.
What I wrote would return `Nil` if it failed to find a match, yours
will return a
On 2/2/19 9:29 PM, Brad Gilbert wrote:
It is also weird that you are using CamelCase for variables,
and a mixture of CamelCase and snake-case for the subroutine name.
Hi Brad,
An explanation. I do this for "maintainability".
I have been able to "type" since high school typing
class. Upper
> On Sat, Feb 2, 2019 at 10:05 PM ToddAndMargo via perl6-users
> wrote:
>>
>> On 2/2/19 6:09 AM, Brad Gilbert wrote:
>>> sub buf-index ( Buf $buf, +@match ) {
>>> my $elems = @match.elems;
>>> $buf.rotor( $elems => 1 - $elems ).first(* eqv
@match.List, :k)
>>> }
Subs do not need to have a `return` statement if it is returning the last value.
You also broke the return value of the subroutine that I wrote by
assigning it to a variable.
What I wrote would return `Nil` if it failed to find a match, yours
will return an undefined `Int`.
It should return `Nil`
On 2/2/19 6:09 AM, Brad Gilbert wrote:
sub buf-index ( Buf $buf, +@match ) {
my $elems = @match.elems;
$buf.rotor( $elems => 1 - $elems ).first(* eqv @match.List, :k)
}
my $buf = Buf[uint8].new(0x4D, 0x5A, 0x90, 0x00, 0x03);
say buf-index( $buf, (0x90, 0x00
> On Fri, Feb 1, 2019 at 11:02 PM ToddAndMargo via perl6-users>
wrote:
>>
>> On 2/1/19 8:26 PM, ToddAndMargo via perl6-users wrote:
>>> On 2/1/19 8:07 PM, ToddAndMargo via perl6-users wrote:
On 2/1/19 8:03 PM, ToddAndMargo via perl6-users wrote:
> > On Fri, Feb 1, 2019 at 9:37 PM Todd
sub buf-index ( Buf $buf, +@match ) {
my $elems = @match.elems;
$buf.rotor( $elems => 1 - $elems ).first(* eqv @match.List, :k)
}
my $buf = Buf[uint8].new(0x4D, 0x5A, 0x90, 0x00, 0x03);
say buf-index( $buf, (0x90, 0x00, 0x03)); # 2
On Fri, Feb 1, 2019 at 11:02 PM
On 2/1/19 8:26 PM, ToddAndMargo via perl6-users wrote:
On 2/1/19 8:07 PM, ToddAndMargo via perl6-users wrote:
On 2/1/19 8:03 PM, ToddAndMargo via perl6-users wrote:
> On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users
> wrote:
>>
>> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users
On 2/1/19 8:07 PM, ToddAndMargo via perl6-users wrote:
On 2/1/19 8:03 PM, ToddAndMargo via perl6-users wrote:
> On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users
> wrote:
>>
>> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>>
>>> On a type Buf, what do I u
On 2/1/19 8:03 PM, ToddAndMargo via perl6-users wrote:
> On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users
> wrote:
>>
>> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>>
>>> On a type Buf, what do I use to check for the
>>> position of a byte pattern?
>>
> On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users
> wrote:
>>
>> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>>
>>> On a type Buf, what do I use to check for the
>>> position of a byte pattern?
>>>
>>>
>>> Many thanks,
>>> -T
>>
>>
>> Basically, what am I doing
`eq` is string equality
`==` is numeric equality
a Buf is neither.
You want `eqv` (equivalent)
$b[2..4] eqv (0x90,0x00,0x04)
On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users
wrote:
>
> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > On a type Buf, what
On 2/1/19 7:37 PM, ToddAndMargo via perl6-users wrote:
On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote:
Hi All,
On a type Buf, what do I use to check for the
position of a byte pattern?
Many thanks,
-T
Basically, what am I doing wrong here?
$ p6 'my $handle=open("filever.exe", :bin,
>
> On Fri, Feb 1, 2019 at 9:22 PM ToddAndMargo via perl6-users
> wrote:
>>
>> Hi All,
>>
>> On a type Buf, what do I use to check for the
>> position of a byte pattern?
>>
>>
>> Many thanks,
>> -T
On 2/1/19 7:35 PM, Brad Gilbert wrote:
This would work:
my $b = Buf.new( 0,0,0, 1, 2, 0 );
On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote:
Hi All,
On a type Buf, what do I use to check for the
position of a byte pattern?
Many thanks,
-T
Basically, what am I doing wrong here?
$ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b=
$handle.read(5); say $b; say $b[2
This would work:
my $b = Buf.new( 0,0,0, 1, 2, 0 );
my $match = Buf.new( 1, 2 );
$b.rotor( $match.elems => 1 - $match.elems ).grep(* eqv $match.List, :k)
If you only need the first one, swap out `grep` for `first`
Another iffy option is to decode it as latin1
$b.decode('latin1'
Hi All,
On a type Buf, what do I use to check for the
position of a byte pattern?
Many thanks,
-T
21 matches
Mail list logo