[Chicken-users] Fwd: Peeking N characters in string ports

2019-01-11 Thread David Ireland
Hi there,

I'm reading from a (string) port and have a need to peek 2 characters
inside without actually reading off the port (read-char).

I believe procedures such as unread-char seen in other Schemes would solve
my problem however, this isn't available in Chicken it seems.

Would anyone have any suggestions?

Thanks
David
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Fwd: Peeking N characters in string ports

2019-01-11 Thread Jörg F . Wittenberger

Hi David,

On Jan 11 2019, David Ireland wrote:


Hi there,

I'm reading from a (string) port and have a need to peek 2 characters
inside without actually reading off the port (read-char).

I believe procedures such as unread-char seen in other Schemes would solve
my problem however, this isn't available in Chicken it seems.


I do not recall that I ever used unread-char ever. I roughly recall that it 
usually can only "un-read" a single character. But that might be wrong.



Would anyone have any suggestions?


If you really need such a thing, my only suggestion would be to look into
http://wiki.call-cc.org/man/5/Module%20(chicken%20port)

make-input-port combined with make-concatenated-port and some tricks could 
do the trick.


Best

/Jörg


___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Fwd: Peeking N characters in string ports

2019-01-11 Thread Vasilij Schneidermann
Hello David,

I've run into a similar problem when trying to detect magic bytes for
unknown image formats.  Most allowed figuring out the format by checking
four bytes, one after three bytes.  I've solved this problem by
rethinking it a bit, first read in three bytes and compare, if it's not
the three bytes format, read in one more byte and check the remaining
signatures against the combination of the last three bytes and the
fourth one.  While this was slightly more verbose than an `unread-char`
solution, it was still simple enough to understand.

Vasilij


signature.asc
Description: PGP signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users