summaryrefslogtreecommitdiff
path: root/src/ZNC.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2026-04-07 20:08:09 +0200
committerTom Smeding <tom@tomsmeding.com>2026-04-07 20:10:29 +0200
commiteea899462d042d52b4827a314ce690d1651a79fa (patch)
tree11bb9ab2c300ad7159e276f0b8c55d56baf86329 /src/ZNC.hs
parent63bcac7e00d5dfe857ec57f0eb999dad5b3964b6 (diff)
Event hotlinking
Diffstat (limited to 'src/ZNC.hs')
-rw-r--r--src/ZNC.hs47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/ZNC.hs b/src/ZNC.hs
index 36d3d4f..4618025 100644
--- a/src/ZNC.hs
+++ b/src/ZNC.hs
@@ -4,6 +4,7 @@ module ZNC (
Nick, Event(..),
preparseLog,
parseLog, parseLogRange,
+ parseLogTimesOnly,
) where
import Control.Applicative
@@ -19,8 +20,6 @@ import Data.Text.Encoding qualified as TE
import Data.Vector.Storable qualified as VS
import Data.Word (Word8, Word32)
-import Debug.Trace
-
import Util
@@ -58,6 +57,12 @@ preparseLog = VS.fromList . findLineStarts 0
parseLog :: ByteString -> [(HMS, Event)]
parseLog = map parseLogLine . BS8.lines
+{-# INLINE parseLogTimesOnly #-}
+parseLogTimesOnly :: VS.Vector Word32 -> ByteString -> [HMS]
+parseLogTimesOnly linestarts bs =
+ map (fromRight (HMS 0 0 0) . P.parseOnly parseTOD) $
+ splitWithLineStarts 0 linestarts bs
+
-- (start line, number of lines (default to rest of file))
{-# INLINE parseLogRange #-}
parseLogRange :: (Int, Maybe Int) -> VS.Vector Word32 -> ByteString -> [(HMS, Event)]
@@ -66,33 +71,27 @@ parseLogRange (startln, mnumln) linestarts topbs =
splitted = splitWithLineStarts 0 (VS.slice startln numln linestarts) topbs
in -- traceShow ("pLR"::String, splitted) $
map parseLogLine splitted
+
+{-# INLINE splitWithLineStarts #-}
+splitWithLineStarts :: Int -> VS.Vector Word32 -> ByteString -> [ByteString]
+splitWithLineStarts idx starts bs
+ | idx >= VS.length starts = []
+ | idx == VS.length starts - 1 =
+ [BS.takeWhile (\b -> b /= 13 && b /= 10) (BS.drop (at idx) bs)]
+ | otherwise =
+ trimCR (BS.drop (at idx) (BS.take (at (idx + 1) - 1) bs))
+ : splitWithLineStarts (idx + 1) starts bs
where
- {-# INLINE splitWithLineStarts #-}
- splitWithLineStarts :: Int -> VS.Vector Word32 -> ByteString -> [ByteString]
- splitWithLineStarts idx starts bs
- | idx >= VS.length starts = []
- | idx == VS.length starts - 1 =
- [BS.takeWhile (\b -> b /= 13 && b /= 10) (BS.drop (at idx) bs)]
- | otherwise =
- trimCR (BS.drop (at idx) (BS.take (at (idx + 1) - 1) bs))
- : splitWithLineStarts (idx + 1) starts bs
- where
- at i = fromIntegral @Word32 @Int (starts VS.! i)
+ at i = fromIntegral @Word32 @Int (starts VS.! i)
trimCR :: ByteString -> ByteString
- trimCR bs = case BS.unsnoc bs of
- Just (bs', c) | c == 13 -> bs'
- _ -> bs
+ trimCR b = case BS.unsnoc b of
+ Just (b', c) | c == 13 -> b'
+ _ -> b
+{-# NOINLINE parseLogLine #-}
parseLogLine :: ByteString -> (HMS, Event)
-parseLogLine bs =
- case parseLogLine' bs of
- res@(HMS 0 0 0, ParseError) -> traceShow ("PE" :: String, bs) res
- res -> res
-
-{-# NOINLINE parseLogLine' #-}
-parseLogLine' :: ByteString -> (HMS, Event)
-parseLogLine' = fromRight (HMS 0 0 0, ParseError) . P.parseOnly parseLine
+parseLogLine = fromRight (HMS 0 0 0, ParseError) . P.parseOnly parseLine
parseLine :: P.Parser (HMS, Event)
parseLine = (,) <$> parseTOD <*> parseEvent