File tree 3 files changed +51
-6
lines changed 3 files changed +51
-6
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,10 @@ <h2><a href="#Miscellaneous">Miscellaneous </a></h2>
167
167
< td class ="summary "> Check if a string starts with a given prefix
168
168
returns true if it does, false otherwise</ td >
169
169
</ tr >
170
+ < tr >
171
+ < td class ="name " nowrap > < a href ="#pad_left "> pad_left (s, l, p)</ a > </ td >
172
+ < td class ="summary "> Pad a string on the left</ td >
173
+ </ tr >
170
174
</ table >
171
175
< h2 > < a href ="#tostr "> tostr </ a > </ h2 >
172
176
< table class ="function_list ">
@@ -662,6 +666,35 @@ <h3>Parameters:</h3>
662
666
663
667
664
668
669
+ </ dd >
670
+ < dt >
671
+ < a name = "pad_left "> </ a >
672
+ < strong > pad_left (s, l, p)</ strong >
673
+ </ dt >
674
+ < dd >
675
+ Pad a string on the left
676
+
677
+
678
+ < h3 > Parameters:</ h3 >
679
+ < ul >
680
+ < li > < span class ="parameter "> s</ span >
681
+ < span class ="types "> < a class ="type " href ="https://www.lua.org/manual/5.4/manual.html#6.4 "> string</ a > </ span >
682
+ String to pad
683
+ </ li >
684
+ < li > < span class ="parameter "> l</ span >
685
+ < span class ="types "> < span class ="type "> number</ span > </ span >
686
+ Length to pad to
687
+ </ li >
688
+ < li > < span class ="parameter "> p</ span >
689
+ < span class ="types "> < a class ="type " href ="https://www.lua.org/manual/5.4/manual.html#6.4 "> string</ a > </ span >
690
+ Padding character
691
+ </ li >
692
+ </ ul >
693
+
694
+
695
+
696
+
697
+
665
698
</ dd >
666
699
</ dl >
667
700
< h2 class ="section-header "> < a name ="tostr "> </ a > tostr </ h2 >
Original file line number Diff line number Diff line change @@ -24,13 +24,12 @@ local P8LIBLOGUTC = false
24
24
-- @tparam string prefix A prefix to prepend to the message
25
25
local function log (any , prefix )
26
26
tz = P8LIBLOGUTC and 80 or 90
27
- seconds = stat (tz + 5 )
28
27
printh (stat (tz ) .. " -" ..
29
- stat (tz + 1 ) .. " -" ..
30
- stat (tz + 2 ) .. " " ..
31
- stat (tz + 3 ) .. " :" ..
32
- stat (tz + 4 ) .. " :" ..
33
- ( seconds < 10 and " 0" .. seconds or seconds )
28
+ pad_left ( tostr ( stat (tz + 1 )), 2 , " 0 " ) .. " -" ..
29
+ pad_left ( tostr ( stat (tz + 2 )), 2 , " 0 " ) .. " " ..
30
+ pad_left ( tostr ( stat (tz + 3 )), 2 , " 0 " ) .. " :" ..
31
+ pad_left ( tostr ( stat (tz + 4 )), 2 , " 0 " ) .. " :" ..
32
+ pad_left ( tostr ( stat ( tz + 5 )), 2 , " 0" )
34
33
.. " " .. (prefix or " LOG" ) .. " - " .. tostr (any ))
35
34
end
36
35
Original file line number Diff line number Diff line change 379
379
local function starts_with (str , prefix )
380
380
return ssub (str , 0 , # prefix ) == prefix
381
381
end
382
+
383
+
384
+ --- Pad a string on the left
385
+ -- @tparam string s String to pad
386
+ -- @tparam number l Length to pad to
387
+ -- @tparam string p Padding character
388
+ local function pad_left (s , l , p )
389
+ while # s < l do
390
+ s = p .. s
391
+ end
392
+ return s
393
+ end
394
+
You can’t perform that action at this time.
0 commit comments