<commit_before>module IgrepCashbook
( Item
, parseLine
, parseItemLine
, getDate
, isComment
, isCommentLine
)
where

-- for old style cashbook

type Item = [String]

parseLine :: String -> Item
parseLine s
  | isCommentLine s = [s]
  | otherwise = parseItemLine s

parseItemLine :: String -> Item
parseItemLine s = fst folded : snd folded
  where
    folded = foldr f ("", []) s
    f :: Char -> (String, Item) -> (String, Item)
    f ' ' (' ':t, i) = ("", t:i)
    f '\t' (t, i) = ("", t:i)
    f c (t, i) = (c:t, i)

getDate :: Item -> String
getDate = (!!0)

isComment :: Item -> Bool
isComment [x] = isCommentLine x
isComment _ = False

isCommentLine :: String -> Bool
isCommentLine ('#':_) = True
isCommentLine _ = False<commit_msg>parseItemLine in IgrepCashbook.hs splits 2 or more spaces but doesn't tab as a separator any more!<commit_after>module IgrepCashbook
( Item
, parseLine
, parseItemLine
, getDate
, isComment
, isCommentLine
)
where

-- for old style cashbook

type Item = [String]

parseLine :: String -> Item
parseLine s
  | isCommentLine s = [s]
  | otherwise = parseItemLine s

parseItemLine :: String -> Item
parseItemLine s = lastCell : accum
  where
    ( lastCell, accum, _ ) = folded
    folded = foldr f ("", [], False) s
    -- The 3rd value of the tuple means "in spaces"
    f :: Char -> (String, Item, Bool) -> (String, Item, Bool)
    f ' ' (' ':t, i, False) = (t, i, True)
    f ' ' (t, i, True) = (t, i, True)
    f c (t, i, True) = ([c], t:i, False)
    f c (t, i, False) = (c:t, i, False)

getDate :: Item -> String
getDate = (!!0)

isComment :: Item -> Bool
isComment [x] = isCommentLine x
isComment _ = False

isCommentLine :: String -> Bool
isCommentLine ('#':_) = True
isCommentLine _ = False
{'fraction_non_alphanumeric': 0.14878892733564014, 'fraction_numerical': 0.002306805074971165, 'mean_word_length': 3.252450980392157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5858132', 'n_tokens_mistral': 631, 'n_tokens_neox': 615, 'n_words': 208}