1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
|
# Almost the entire canonical Markdown specification is supported
# https://daringfireball.net/projects/markdown/syntax
# Notable behavioural exceptions are:
# - Block-level HTML elements needn't be separated with blank lines
# - Lists are identation-aware. List items begin and continue after the same
# identation with which the list beginning (e.g. "* " or "5. ") was written.
# The benefit is that all Markdown is parsed as normal inside an item.
#
# [.] Non-standard features
# [x] Strikethrough ~~...~~
# [x] Superscript ^...^
# [x] Subscript ~...~
# [.] Footnote [^...] (with user customizations)
# [x] Task list - [ ] (readonly)
# [x] Definition lists
# [x] Single line
# [x] Multi-line
# [x] Fenced code blocks ```lang ```
# [ ] Tables
# [x] Links
# [x] Link destination (<link> inside anchors)
# [x] Nested links
#
# No character classes have been used, since they aren't supported on every system
# Naming conventions:
# all caps - constants, do not assign to variable (directly)
# begins with "__" - internal, do not use
BEGIN {
footnote_index = 1
## This is used to convert email autolinks into a series of hex values
## Escaped output of: awk 'BEGIN {for (i = 32; i <= 126; ++i){ printf("%c", i) } }'
ascii = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
for (i = 1; i < 97; ++i) {
char_to_dec[char(ascii, i)] = 31 + i
}
## We do character escaping by substituting the escape with some
## "useless" characters, which we're confident won't appear in actual text.
## These are from decimal value 14 to 28 inclusive. They're blank characters,
## related to shifting, device control and data transmission.
escapable = "\\`*_{}[]()#+-.!^~"
for (i = 1; i < 18; ++i) {
escapes[char(escapable, i)] = sprintf("%c", 13 + i)
}
}
{
STATE_assign(STATE_PARAGRAPH_P1, STATE_PARAGRAPH)
STATE_set(STATE_PARAGRAPH)
empty0 = empty($0)
emptyP1 = empty(P1)
}
#== Block markup ==#
#-- Blockquotes --#
blockquote_level > 0 && empty0 {
STATE_unset(STATE_PARAGRAPH_P1)
## Blockquote end also ends codeblock
if (STATE_thenunset(STATE_CODEBLOCK)) {
PNappnd("</code></pre>")
}
for (P1 = P1 ORS; blockquote_level > 0; --blockquote_level) {
P1 = P1 "</blockquote>"
}
}
/^>[ \t]/ {
STATE_set(STATE_BLOCKQUOTE)
## blevel is the amount of ">" in the beginning of the line
## We also remove the leading ">...> " part
match($0, /^[> \t]*> /)
blevel = substr($0, RSTART, RLENGTH)
$0 = substr($0, RSTART + RLENGTH)
gsub(/[ \t]/, "", blevel)
blevel = length(blevel)
for (;blockquote_level < blevel; ++blockquote_level) {
P1 = P1 "<blockquote>"
}
for (;blockquote_level > blevel; --blockquote_level) {
P2 = P2 "</blockquote>"
}
}
STATE_isset(STATE_BLOCKQUOTE) && $0 == ">" {
$0 = ""
empty0 = TRUE
}
#-- Remove list indentation --#
list_level > 0 && !empty0 && !is_blank() {
level = int((indentation() + 2) / 2)
sub("^[ \t]{1," lists_shift[list_level] "}", "")
}
#-- Inline HTML --#
!STATE_isset(STATE_CODEBLOCK) && /^[ \t]{0,3}<\/?[0-9A-Za-z]+/ {
STATE_set(STATE_HTML)
soft_next()
}
STATE_isset(STATE_HTML) {
if (is_blank()) {
STATE_unset(STATE_HTML)
}
else {
soft_next()
}
}
#-- Fenced code blocks --#
STATE_isset(STATE_FENCED_CODEBLOCK) {
## We need to add <pre><code> to the start of the first line inside the fence
## so we don't introduce leading newlines
if (fenced_start) {
$0 = fenced_start $0
fenced_start = ""
soft_next()
}
if (/^```/) {
PNappnd("</code></pre>")
STATE_unset(STATE_PARAGRAPH)
STATE_unset(STATE_CODEBLOCK)
STATE_unset(STATE_FENCED_CODEBLOCK)
next
}
}
#-- Code blocks --#
STATE_isset(STATE_CODEBLOCK) {
if (!empty0 && !STATE_isset(STATE_FENCED_CODEBLOCK) && ! /^( |\t)/) {
PNappnd("</code></pre>")
STATE_unset(STATE_CODEBLOCK)
}
else {
escape_in_codeblock()
soft_next()
}
}
#-- Link definition (ignore) --#
/^\[[^\]]+\]:/ {
next
}
#-- Escapes --#
/\\[-\\`*_{}\[\]()#+.!^~]/ { # has escaped char
while (match($0, /\\[-\\`*_{}\[\]()#+.!^~]/)) {
sub_match(escapes[char($0, RSTART + 1)])
}
}
#-- Horizontal rule --#
/^(---+|- -( -)+|\*\*\*+|\* \*( \*)+|___+|_ _( _)+)$/ {
STATE_unset(STATE_PARAGRAPH)
$0 = "<hr/>"
}
#-- Lists --#
/^[ \t]*[*+-] / { ## Unordered list
level = level + int(indentation() / 2)
match($0, /^[ \t]*[*+-] /)
type = char($0, RSTART + RLENGTH - 2)
shift = RLENGTH
sub_match("")
start_list(level, type, shift)
level = 0
}
/^[ \t]*[0-9]+\. / { ## Ordered list
level = level + int(indentation() / 2)
type = "."
match($0, /^[^.]+\. /)
shift = RLENGTH
sub_match("")
start_list(level, type, shift)
level = 0
}
level > 0 && list_level > 0 && !is_blank() && emptyP1 { ## Non-list line
while (list_level >= level) {
end_list()
}
}
list_level > 0 {
STATE_unset(STATE_PARAGRAPH)
}
# start_list(level, type, shift)
#
# Adds a new list or list item, even when that requires closing other lists. Updates lists and list_level.
#
# level - indentation integer
# type - one of ".", "o", "u"
# shift - where does the list contents start indent-wise
function start_list(level, type, shift) {
STATE_set(STATE_LIST)
## Every two columns we define a new level
level = int((level + 2) / 2)
## When new level is much more indented than current
if (list_level < level - 1) {
list_level = level - 1
}
## When new level is less indented than current
while (list_level > level) {
end_list()
}
## When list type was changed on the same level
if (list_level == level && lists[list_level] != type) {
end_list()
}
## Create a new list
if (list_level < level || lists[list_level] != type) {
P1 = P1 ORS "<" (type == "." ? "o" : "u") "l><li>"
lists[level] = type
lists_shift[level] = shift
list_level = level
}
## Create a new list item
else {
PNappnd("</li>")
P1 = P1 ORS "<li>"
}
}
# end_list()
#
# Closes a list. Also unsets STATE_LIST and decrements list_level.
function end_list() {
STATE_unset(STATE_LIST)
if (list_level == 0) return
PNappnd("</li></" (lists[list_level] == "." ? "o" : "u") "l>")
--list_level
}
#-- Checklists --#
STATE_isset(STATE_LIST) && level == 0 && /^\[[x ]\][ \t]/ {
checked = (char($0, 2) == "x") ? " checked=\"checked\"" : "";
$0 = "<input type=\"checkbox\" disabled=\"disabled\"" checked \
"><label>" substr($0, 5) "</label>"
}
#-- Fenced code blocks (new) --#
/^[ \t]*```/ {
STATE_set(STATE_FENCED_CODEBLOCK)
STATE_set(STATE_CODEBLOCK)
match(P1, /```[^ \t]*/)
fenced_start = ""
if (RLENGTH > 3) {
fenced_start = " class=\"language-" tolower(substr(P1, RSTART + 3, RLENGTH - 3)) "\""
}
fenced_start = "<pre><code" fenced_start ">"
next
}
#-- Code blocks (new) --#
/^( |\t)/ && /[^ \t]/ {
STATE_set(STATE_CODEBLOCK)
escape_in_codeblock()
$0 = "<pre><code>" $0
soft_next()
}
# escape_in_codeblock()
#
# Escape &, < and > with the appropriate HTML entities. Meant to be used with codeblocks.
function escape_in_codeblock() {
for (i = 1; match(substr($0, i), /&/); i += RSTART) {
RSTART += i - 1
sub_match("&")
}
gsub(/</, "\\<")
gsub(/>/, "\\>")
}
#-- Definition lists --#
STATE_isset(STATE_DEFINITION_LIST) {
if (!empty0) {
STATE_unset(STATE_PARAGRAPH)
}
else if (def_started) {
P1 = P1 "</dd>"
}
if ((!empty0 && emptyP1 && /^: /) ||
( empty0 && !emptyP1 && !def_started && P1 !~ /^<dd>/) ||
(!empty0 && !emptyP1 && !def_started && !/^: /))
{
STATE_unset(STATE_DEFINITION_LIST)
P2 = P2 "</dl>"
STATE_set(STATE_PARAGRAPH_P1)
STATE_set(STATE_PARAGRAPH)
P1 = "<p>" P1
}
if (/^: /) {
def_started = TRUE
}
else if (empty0) {
def_started = FALSE
}
}
/^: / && !emptyP1 {
sub(/^<p>/, "", P1)
$0 = substr($0, 3)
P1 = "<dt>" P1 "</dt>"
if (STATE_thenset(STATE_DEFINITION_LIST)) {
P1 = "<dl>" P1
}
$0 = "<dd>" $0
def_started = TRUE
STATE_unset(STATE_PARAGRAPH)
STATE_unset(STATE_PARAGRAPH_P1)
}
#== Inline markup ==#
#-- Autoescape & --#
/&/ {
for (i = 1; match(substr($0, i), /&/); i += RSTART) {
RSTART += i - 1
## Don't escape HTML entities
if (substr($0, RSTART) ~ /&[A-Za-z0-9#]+;/) { continue }
sub_match("&")
}
}
#-- Autoescape < --#
/ < / {
gsub(/ < /, "\\<")
}
#-- Automatic links --#
/<[^ \t<>]+>/ {
## URL: <uri_scheme:...>
while (match($0, /<[A-Za-z][-A-Za-z0-9+.]*:[^ \t<>]+>/)) {
href = substr($0, RSTART + 1, RLENGTH - 2)
sub_match("<a href=\"" href "\">" href "</a>")
}
## Email addresses, with support for quoted local part "..."@...
## and ip address literal ...@[...]
while (match($0, /<([^ \t<>]+|".+")@([-A-Za-z0-9]+\.[^ \t<>]+|\[[0-9A-Fa-f.:]+\])>/)) {
href = substr($0, RSTART + 1, RLENGTH - 2)
href_masked = ""
## The original markdown blogpost calls for convertions of all
## email characters into their hex values. Allegedly, this fools
## many autoharvesting spam bots.
for (i = length(href); i > 0; --i) {
href_masked = sprintf("&#x%X;", char_to_dec[char(href, i)]) href_masked
}
## href="mailto:..."
sub_match("<a href=\"mailto:" href_masked "\">" href_masked "</a>")
}
}
#-- Line break --#
/ $/ {
sub(/[ \t]* $/, "</br>")
}
#-- atx-style headers --#
/^[ \t]*#+/ {
match($0, /#+/)
if (RLENGTH <= 6) {
## Remove prefix/suffix
gsub(/^[ \t]*#+[ \t]*/, "")
gsub(/[ \t]*#+[ \t]*$/, "")
$0 = "<h" RLENGTH ">" $0 "</h" RLENGTH ">"
STATE_unset(STATE_PARAGRAPH)
}
}
#-- setex-style headers --#
!emptyP1 && /^[ \t]*(=|-)+[ \t]*$/ {
hlevel = 1 + ($0 ~ /-/)
P1 = "<h" hlevel ">" substr(P1, 4) "</h" hlevel ">"
$0 = ""
STATE_unset(STATE_PARAGRAPH)
}
#-- Footnote references --#
/\[\^[^\]]+\]/ {
while (match($0, /\[\^[^\]]+\]/)) {
footnote_name = substr($0, RSTART + 2, RLENGTH - 3)
if (!footnote[footnote_name]) {
sub_match("<sup>?" footnote_name "?</sup>")
}
else {
fn = footnote[footnote_name]
delete footnote[footnote_name]
## Escapes for emphasis elements
gsub(/_/, "\\_", footnote_name)
gsub(/\*/, "\\*", footnote_name)
gsub(/~/, "\\~", footnote_name)
gsub(/`/, "\\`", footnote_name)
gsub(/\^/, "\\^", footnote_name)
footnote_short = substr(fn, 0, 97)
if (length(fn) > 97) {
footnote_short = footnote_short "..."
}
sub_match("<sup id=\"ref-" footnote_name "\">" \
"<a href=\"#footnote-" footnote_name "\" title=\"" footnote_short "\">" \
(footnote_index++) "</a></sup>")
footnote_tag = footnote_tag ORS "<li id=\"footnote-" footnote_name "\">" \
"<p>" fn " <a href=\"#ref-" footnote_name "\">^</a></p></li>"
}
}
}
#-- Emphasis --#
{
## Make sure <em> is on the inside for long chains
## E.g. *****a***** will be the same as ****_a_****
surround("___" , "<strong><em>", "</em></strong>")
surround("\\*\\*\\*", "<strong><em>", "</em></strong>", 3)
gsurround("__" , "<strong>", "</strong>")
gsurround("_" , "<em>" , "</em>")
gsurround("\\*\\*", "<strong>", "</strong>", 2)
gsurround("\\*" , "<em>" , "</em>", 1)
gsurround("``" , "<code>" , "</code>")
gsurround("`" , "<code>" , "</code>")
gsurround("~~" , "<s>" , "</s>")
gsurround("~" , "<sub>" , "</sub>")
gsurround("\\^", "<sup>" , "</sup>", 1)
}
# surround(brace, left, right [, blen])
#
# Substitute the shortest leftmost "brace ... brace" with "left ... right".
#
# Since brace is used in a regex, you'll need to escape special characters. In such cases, you need to set blen (brace length) to the count of "real" characters.
function surround(brace, left, right, blen) {
if (blen == "") { blen = length(brace) }
if (match($0, brace (brace == "``" ? "." : "[^" brace "]") "+" brace)) {
elem = left substr($0, RSTART + blen, RLENGTH - 2*blen) right
if (brace == "``") { gsub("`", "\\`", elem) }
sub_match(elem)
return 1;
}
return 0
}
# gsurround(brace, left, right [, blen])
#
# Same as surround, however it substitutes all non-overlapping occurrences.
function gsurround(brace, left, right, blen) {
while (surround(brace, left, right, blen)) {}
if (blen == 1) {
gsub("\\\\", "", brace)
## Surrounding a single character span with spaces should make it a
## literal char. This is inelegant but functional.
gsub(" " left " ", " " brace " ")
gsub(" " right " ", " " brace " ")
}
}
#-- Links --#
/!?\[[^\]]*\] ?[(\[][^)\]]*[\])]/ {
while (match($0, /!?\[[^\]]*\] ?[(\[][^)\]]*[\])]/)) {
link = substr($0, RSTART, RLENGTH)
save_match()
## ](xxxxx)
match(link, /\] ?[(\[][^)\]]*[\])]$/)
has_space = char(link, RSTART + 1) == " "
is_img = char(link, 1) == "!"
## ...[xxxxx](...)...
text = substr(link, 2 + is_img, RSTART - 2 - is_img)
## ...[...](xxxxx)...
href = substr(link, RSTART + has_space + 2, RLENGTH - has_space - 3)
title = "\"\""
if (char(link, RSTART + RLENGTH - 1) == "]") { ## is reference link
if (href == "") href = text # [...][]
## [...]: ... "xxxxx"
title = reference[href, "title"]
## [...]: xxxxx "..."
href = reference[href, "href"]
}
else if (match(href, /[ \t]"[^"]*"[ \t]*$/)) { ## has title
## ...[...](... "xxxxx")...
title = substr(href, RSTART + 1, RLENGTH - 1)
## ...[...](xxxxx "...")...
href = substr(href, 1, RSTART - 1)
}
if (is_img) elem = "<img src=\"" href "\" alt=\"" text "\" title=" title ">"
else elem = "<a href=\"" href "\" title=" title ">" text "</a>"
restore_match()
sub_match(elem)
}
}
#-- Paragraph --#
emptyP1 && !empty0 && STATE_isset(STATE_PARAGRAPH) { $0 = "<p>" $0 }
!emptyP1 && empty0 && STATE_isset(STATE_PARAGRAPH_P1) { P1 = P1 "</p>" }
#== Buffered printing ==#
# Output is buffered on multiple lines, held in these variables:
# P2 = last non-empty line before the previous line
# P1 = previous line
# $0 = current line
# N1 = next new line (N1 is always set by the user)
{
__buffered_print()
}
function __buffered_print() {
empty0 = empty($0)
emptyP1 = empty(P1)
if (empty0 && emptyP1) {
++P1_repeats
}
else if (!empty0 && emptyP1) {
P1 = $0
}
else {
print P2
while (P1_repeats > 0) {
print ""
--P1_repeats
}
P2 = P1
P1 = $0
if (empty0) {
P1_repeats = 1
}
}
if (!empty(N1)) {
if (emptyP1) {
P1 = N1
}
else {
print P2
while (P1_repeats > 0) {
print ""
--P1_repeats
}
P2 = P1
P1 = N1
N1 = ""
}
}
## Fix escaped characters
for (i = 1; i < 18; ++i) {
esc = char(escapable, i)
gsub(escapes[esc], esc, P2)
}
}
END {
if (STATE_isset(STATE_DEFINITION_LIST)) {
PNappnd("</dl>")
}
if (STATE_isset(STATE_PARAGRAPH)) {
$0 = $0 "</p>"
}
print P2
while (P1_repeats > 0) {
print ""
--P1_repeats
}
if (!empty(P1)) { print P1 }
print
if (!empty(N1)) { print N1 }
if (footnote_tag) {
print ORS "<div class=\"footnotes\"><hr><ol>" footnote_tag "</ol></div>"
}
}
# PNappnd(value)
#
# Append value to the previous non-empty line. If P1 is empty, then it's P2, otherwise P1.
function PNappnd(value) {
if (emptyP1) P2 = P2 ORS value
else P1 = P1 ORS value
}
# soft_next()
#
# Print buffered and then do next.
function soft_next() {
__buffered_print()
STATE_unset(STATE_PARAGRAPH)
next
}
#== Boolean "constants" ==#
BEGIN {
FALSE = 0
TRUE = 1
}
#== States system ==#
# To convey the current state of parsing, we're using "states"
# These are nothing more than variables and an array, storing "booleans"
# The main benefit is semantics and syntax usage
# (especially since we're using variables, editors will offer autocompletion)
BEGIN {
# State definitions
STATE_HTML = 0
STATE_FENCED_CODEBLOCK = 1
STATE_CODEBLOCK = 2
STATE_BLOCKQUOTE = 3
STATE_PARAGRAPH = 4
STATE_PARAGRAPH_P1 = 5
STATE_LIST = 6
STATE_DEFINITION_LIST = 7
}
# STATE_set(name)
#
# Set the state to TRUE
function STATE_set(name) {
STATE_unset(STATE_PARAGRAPH)
__state[name] = TRUE
}
# STATE_unset(name)
#
# Set the state to FALSE
function STATE_unset(name) {
__state[name] = FALSE
}
# STATE_assign(name, other)
#
# Set the value of the first state to the value of the second state.
function STATE_assign(name, other) {
__state[name] = __state[other]
}
# STATE_isset(name)
#
# Return boolean
function STATE_isset(name) {
return __state[name]
}
# STATE_thenset(name)
#
# If the state is not set, set it and return TRUE. Otherwise return FALSE.
function STATE_thenset(name) {
if (!__state[name]) {
STATE_set(name)
return TRUE
}
return FALSE
}
# STATE_thenunset(name)
#
# If the state is set, unset it and return TRUE. Otherwise return FALSE.
function STATE_thenunset(name) {
if (__state[name]) {
STATE_unset(STATE_PARAGRAPH)
__state[name] = FALSE
return TRUE
}
return FALSE
}
#== Line information ==#
# indentation()
#
# Return the cound of leading blank characters in $0.
function indentation( len) {
save_match()
match($0, /^[ \t]*/)
len = RLENGTH
restore_match()
return len
}
# is_blank()
#
# Wether $0 contains only blank characters.
function is_blank() {
return ! /[^ \t]/
}
#== Match handling ==#
# save_match()
#
# Backup RSTART and RLENGTH
function save_match() {
backup_rstart = RSTART
backup_rlength = RLENGTH
}
# restore_match()
#
# Restore RSTART and RLENGTH, from save_match's backup.
function restore_match() {
RSTART = backup_rstart
RLENGTH = backup_rlength
}
# sub_match(replacement)
#
# Replace the range, specified by RSTART and RLENGTH (from match function) with the given replacement. Replacement is not a regex.
function sub_match(replacement) {
$0 = substr($0, 1, RSTART - 1) replacement substr($0, RSTART + RLENGTH)
}
#== Other ==#
function empty(value) {
return value == ""
}
# char(string, ind)
#
# Return a single-character string, which is found at the given index. If the index is invalid, a blank string is returned.
function char(string, ind) {
if (1 > ind || ind > length(string)) {
return "";
}
return substr(string, ind, 1)
}
|