all repos — min @ 780ed061a9fc8ccfcd83aa61dbbc99a0bacb1850

A small but practical concatenative programming language.

site/contents/reference-str.md

 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
-----
content-type: "page"
title: "str Module"
-----
{@ _defs_.md || 0 @}

{#alias||%||interpolate#}

{#alias||=%||apply-interpolate#}

{#alias||=~||regex#}

{#op||apply-interpolate||{{s}} {{q}}||{{s}}||
The same as pushing `apply` and then `interpolate` on the stack.#}

{#op||capitalize||{{sl}}||{{s}}||
Returns a copy of {{sl}} with the first character capitalized.#}

{#op||chr||{{i}}||{{s}}||
Returns the single character {{s}} obtained by interpreting {{i}} as an ASCII code.#}

{#op||escape||{{sl}}||{{s}}||
Returns a copy of {{sl}} with quotes and backslashes escaped with a backslash.#}

{#op||from-semver||{{s}}||{{d}}||
Given a basic [SemVer](https://semver.org)-compliant string (with no additional labels) {{s}}, 
it pushes a dictionary {{d}} on the stack containing a **major**, **minor**, and **patch** key/value pairs.#}

{#op||indent||{{sl}} {{i}}||{{s}}||
Returns {{s}} containing {{sl}} indented with {{i}} spaces.#}

{#op||indexof||{{s1}} {{s2}}||{{i}}||
If {{s2}} is contained in {{s1}}, returns the index of the first match or -1 if no match is found. #}

{#op||interpolate||{{s}} {{q}}||{{s}}||
> Substitutes the placeholders included in {{s}} with the values in {{q}}.
> > %note%
> > Notes
> > 
> > * If {{q}} contains symbols or quotations, they are not interpreted. To do so, call `apply` before interpolating or use `apply-interpolate` instead.
> > * You can use the `$#` placeholder to indicate the next placeholder that has not been already referenced in the string.
> > * You can use named placeholders like `$pwd`, but in this case {{q}} must contain a quotation containing both the placeholder names (odd items) and the values (even items).
> 
> > %sidebar%
> > Example
> >  
> > The following code (executed in a directory called '/Users/h3rald/Development/min' containing 19 files):
> > 
> > `"Directory '$1' includes $2 files." (. (. ls 'file? filter size)) apply interpolate`
> > 
> > produces:
> > 
> > `"Directory '/Users/h3rald/Development/min' includes 19 files."`#}

{#op||join||{{q}} {{sl}}||{{s}}||
Joins the elements of {{q}} using separator {{sl}}, producing {{s}}.#}

{#op||length||{{sl}}||{{i}}||
Returns the length of {{sl}}.#}

{#op||lowercase||{{sl}}||{{s}}||
Returns a copy of {{sl}} converted to lowercase.#}

{#op||match?||{{s1}} {{s2}}||{{b}}||
> Returns {{t}} if {{s2}} matches {{s1}}, {{f}} otherwise.
> > %tip%
> > Tip
> > 
> > {{s2}} is a {{pcre}}#}.

{#op||ord||{{s}}||{{i}}||
Returns the ASCII code {{i}} corresponding to the single character {{s}}.#}

{#op||parse-url||{{s}}||{{url}}||
Parses the url {{s}} into its components and stores them into {{url}}.#} 

{#op||prefix||{{sl1}} {{sl2}}||{{s}}||
Prepends {{sl2}} to {{sl1}}.#}

{#op||repeat||{{sl}} {{i}}||{{s}}||
Returns {{s}} containing {{sl}} repeated {{i}} times.#}

{#op||replace||{{s1}} {{s2}} {{s3}}||{{s4}}||
> Returns a copy of {{s1}} containing all occurrences of {{s2}} replaced by {{s3}}
> > %tip%
> > Tip
> > 
> > {{s2}} is a {{pcre}}.
> 
> > %sidebar%
> > Example
> > 
> > The following:
> > 
> > `"This is a stupid test. Is it really a stupid test?" " s[a-z]+" " simple" replace`
> > 
> > produces:
> > 
> > `"This is a simple test. Is it really a simple test?"`#}

{#op||replace-apply||{{s1}} {{s2}} {{q}}||{{s3}}||
> Returns a copy of {{s1}} containing all occurrences of {{s2}} replaced by applying {{q}} to each quotation correponding to each match.
> > %tip%
> > Tip
> > 
> > {{s2}} is a {{pcre}}.
> 
> > %sidebar%
> > Example
> > 
> > The following:
> > 
> > `":1::2::3::4:" ":(\d):" (=m m 1 get :d "-$#-" (d) =%) replace-apply`
> > 
> > produces:
> > 
> > `"-1--2--3--4-"`
> > 
> > Note that for each match the following quotations (each containing tbe full matcb and the captured matches) are produced as input for the replace quotation:
> >      ("-1-" "1")
> >      ("-2-" "2")
> >      ("-3-" "3")
> >      ("-4-" "4") #}

{#op||search||{{s1}} {{s2}}||{{q}}||
> Returns a quotation containing the first occurrence of {{s2}} within {{s1}}. Note that:
> 
>   * The first element of {{q}} is the matching substring.
>   * Other elements (if any) contain captured substrings.
>   * If no matches are found, the quotation contains empty strings.
> 
> > %tip%
> > Tip
> > 
> > {{s2}} is a {{pcre}}.
> 
> > %sidebar%
> > Example
> > 
> > The following:
> > 
> > `"192.168.1.1, 127.0.0.1" "[0-9]+\.[0-9]+\.([0-9]+)\.([0-9]+)" search`
> > 
> > produces: `("192.168.1.1", "1", "1")`#}

{#op||search-all||{{s1}} {{s2}}||{{q}}||
Returns a quotation of quotations (like the one returned by the search operator) containing all occurrences of {{s2}} within {{s1}}. #}

{#op||semver-inc-major||{{s1}}||{{s2}}||
Increments the major digit of the [SemVer](https://semver.org)-compliant string (with no additional labels) {{s1}}. #}

{#op||semver-inc-minor||{{s1}}||{{s2}}||
Increments the minor digit of the [SemVer](https://semver.org)-compliant string (with no additional labels) {{s1}}. #}

{#op||semver-inc-patch||{{s1}}||{{s2}}||
Increments the patch digit of the [SemVer](https://semver.org)-compliant string (with no additional labels) {{s1}}. #}

{#op||semver?||{{s}}||{{b}}||
Checks whether {{s}} is a [SemVer](https://semver.org)-compliant version or not. #}

{#op||split||{{sl1}} {{sl2}}||{{q}}||
Splits {{sl1}} using separator {{sl2}} (a {{pcre}}) and returns the resulting strings within the quotation {{q}}. #}

{#op||strip||{{sl}}||{{s}}||
Returns {{s}}, which is set to {{sl}} with leading and trailing spaces removed.#} 

{#op||substr||{{s1}} {{i1}} {{i2}}||{{s2}}||
Returns a substring {{s2}} obtained by retriving {{i2}} characters starting from index {{i1}} within {{s1}}.#}

{#op||suffix||{{sl1}} {{sl2}}||{{s}}||
Appends {{sl2}} to {{sl1}}.#}

{#op||titleize||{{sl}}||{{s}}||
Returns a copy of {{sl}} in which the first character of each word is capitalized.#}

{#op||to-semver||{{d}}||{{s}}||
Given a a dictionary {{d}} containing a **major**, **minor**, and **patch** key/value pairs , it pushes a basic [SemVer](https://semver.org)-compliant string (with no additional labels) {{s}} on the stack.#}

{#op||uppercase||{{sl1}}||{{sl2}}||
Returns a copy of {{sl}} converted to uppercase.#}