Index

joshstock.in / 460da80

Source for serving and static templating/compiling of https://joshstock.in.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
8825 Aug 2020 16:09c8cb357Begin base git history rewriteJosh Stockin1380G

Blob @ joshstock.in / git-history / utils.lua

text/plain1040 bytesdownload raw
1-- utils.lua
2-- basic utilities for git status site implementation
3
4-- Copyright (c) 2020 Joshua 'joshuas3' Stockin
5-- <https://github.com/JoshuaS3/joshstock.in>
6-- <https://joshstock.in>
7
8
9string.split = function(str, delimiter)
10 local t = {}
11 if not str or str == "" then
12 return t
13 end
14 if delimiter == "" then -- string to table
15 string.gsub(str, ".", function(c) table.insert(t, c) end)
16 return t
17 end
18 delimiter = delimiter or "%s"
19 local str_len = string.len(str)
20 local ptr = 1
21 while true do
22 local sub = string.sub(str, ptr, str_len)
23 local pre, after = string.find(sub, delimiter)
24 if pre then -- delimiter found
25 table.insert(t, string.sub(str, ptr, ptr + (pre - 2)))
26 ptr = ptr + after
27 else -- delimiter not found
28 table.insert(t, string.sub(str, ptr, str_len))
29 break
30 end
31 end
32 return t
33end
34
35
36string.trim = function(str)
37 return str:match('^()%s*$') and '' or str:match('^%s*(.*%S)')
38end
39