DFortune

Unix fortune-cookie parser written in D
git clone git://xatko.vsos.ethz.ch/DFortune.git
Log | Files | Refs

commit 58ce650562517fad96c1974e391b70a8a86c7fd8
parent c2ab712cfbf52e9678eade4ff08052ce9e943a31
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Sun,  9 Aug 2015 14:50:14 +0200

Split readFortune into two functions.

Diffstat:
dfortune.d | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/dfortune.d b/dfortune.d @@ -75,13 +75,11 @@ class Fortune : RandomAccessFinite!(string){ return bigEndianToNative!(uint,uint.sizeof)(b); } - public string readFortune(uint i) + public string sliceFile(uint pos, uint end) in{ assert(table.isOpen && content.isOpen, "Fortunes must be opened before reading"); } body{ - uint pos=getOffset(i); - uint end=getOffset(i+1)-3; //-3 to exclude \n%\n content.seek(pos); ubyte buf[]=new ubyte[end-pos]; content.rawRead(buf); @@ -102,6 +100,12 @@ class Fortune : RandomAccessFinite!(string){ return cast(string)str; } + public string readFortune(uint i){ + uint pos=getOffset(i); + uint end=getOffset(i+1)-3; //-3 to exclude \n%\n + return sliceFile(pos,end); + } + public void close(){ table.close(); content.close();