Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,20 @@
function striplinecomment{T<:String,U<:String}(a::T, cchars::U="#;")
b = strip(a)
0 < length(cchars) || return b
for c in cchars
r = Regex(@sprintf "\\%c.*" c)
b = replace(b, r, "")
end
strip(b)
end
tests = {"apples, pears # and bananas",
"apples, pears ; and bananas",
" apples, pears & bananas ",
" # "}
for t in tests
s = striplinecomment(t)
println("Testing \"", t, "\":")
println(" \"", s, "\"")
end

View file

@ -0,0 +1,5 @@
import re
m = re.match(r'^([^#]*)#(.*)$', line)
if m: # The line contains a hash / comment
line = m.group(1)

View file

@ -0,0 +1,41 @@
/*REXX program strips a string delineated by a hash (#) or a semicolon (;). */
old1=' apples, pears # and bananas' ; say ' old 'old1"◄───"
new1=stripCom1(old1) ; say '1st version new 'new1"◄───"
new2=stripCom2(old1) ; say '2nd version new 'new2"◄───"
new3=stripCom3(old1) ; say '3rd version new 'new3"◄───"
new4=stripCom4(old1) ; say '4th version new 'new4"◄───"
say copies('',55)
old2=' apples, pears ; and bananas' ; say ' old 'old2"◄───"
new1=stripCom1(old2) ; say '1st version new 'new1"◄───"
new2=stripCom2(old2) ; say '2nd version new 'new2"◄───"
new3=stripCom3(old2) ; say '3rd version new 'new3"◄───"
new4=stripCom4(old2) ; say '4th version new 'new4"◄───"
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
stripCom1: procedure; parse arg x /*obtain the argument (the X string).*/
x=translate(x, '#', ";") /*translate semicolons to a hash (#). */
parse var x x '#' /*parse the X string, ending in hash. */
return strip(x) /*return the striped shortened string. */
/*────────────────────────────────────────────────────────────────────────────*/
stripCom2: procedure; parse arg x /*obtain the argument (the X string).*/
d = ';#' /*this is the delimiter list to be used*/
d1=left(d,1) /*get the first character in delimiter.*/
x=translate(x,copies(d1,length(d)),d) /*translates delimiters ──► 1st delim.*/
parse var x x (d1) /*parse the string, ending in a hash. */
return strip(x) /*return the striped shortened string. */
/*────────────────────────────────────────────────────────────────────────────*/
stripCom3: procedure; parse arg x /*obtain the argument (the X string).*/
d = ';#' /*this is the delimiter list to be used*/
do j=1 for length(d) /*process each of the delimiters singly*/
_=substr(d,j,1) /*use only one delimiter at a time. */
parse var x x (_) /*parse the X string for each delim. */
end /*j*/ /* [↑] (_) means stop parsing at _ */
return strip(x) /*return the striped shortened string. */
/*────────────────────────────────────────────────────────────────────────────*/
stripCom4: procedure; parse arg x /*obtain the argument (the X string).*/
d = ';#' /*this is the delimiter list to be used*/
do k=1 for length(d) /*process each of the delimiters singly*/
p=pos(substr(d,k,1), x) /*see if a delimiter is in the X string*/
if p\==0 then x=left(x,p-1) /*shorten the X string by one character*/
end /*k*/ /* [↑] If p==0, then char wasn't found*/
return strip(x) /*return the striped shortened string. */

View file

@ -0,0 +1,14 @@
Call stripd ' apples, pears # and bananas'
Call stripd ' apples, pears and bananas'
Exit
stripd:
Parse Arg old
dlist='#;' /* delimiter list */
p=verify(old,dlist,'M') /* find position of delimiter */
If p>0 Then /* delimiter found */
new=strip(left(old,p-1))
Else
new=strip(old)
Say '>'old'<'
Say '>'new'<'
Return

View file

@ -1,41 +0,0 @@
/*REXX program strips a string delinated by a hash (#) or semicolon (;).*/
old1=' apples, pears # and bananas' ; say ' old 'old1"◄───"
new1=stripCom1(old1) ; say '1st version new 'new1"◄───"
new2=stripCom2(old1) ; say '2nd version new 'new2"◄───"
new3=stripCom3(old1) ; say '3rd version new 'new3"◄───"
new4=stripCom3(old1) ; say '4th version new 'new4"◄───"
say copies('',55)
old2=' apples, pears ; and bananas' ; say ' old 'old2"◄───"
new1=stripCom1(old2) ; say '1st version new 'new1"◄───"
new2=stripCom2(old2) ; say '2nd version new 'new2"◄───"
new3=stripCom3(old2) ; say '3rd version new 'new3"◄───"
new4=stripCom3(old2) ; say '4th version new 'new4"◄───"
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────STRIPCOM1 subroutine────────────────*/
stripCom1: procedure; parse arg x /*get the argument (string). */
x=translate(x, '#', ";") /*translate semicolons to hash. */
parse var x x '#' /*parse string, ending in hash. */
return strip(x) /*return striped shortened string*/
/*──────────────────────────────────STRIPCOM2 subroutine────────────────*/
stripCom2: procedure; parse arg x /*get the argument (string). */
d = ';#' /*the delimiter list to be used. */
d1=left(d,1) /*get the 1st character in delim.*/
x=translate(x,copies(d1,length(d)),d) /*trans all delims ──► 1st delim.*/
parse var x x (d1) /*parse string, ending in hash. */
return strip(x) /*return striped shortened string*/
/*──────────────────────────────────STRIPCOM3 subroutine────────────────*/
stripCom3: procedure; parse arg x /*get the argument (string). */
d = ';#' /*the delimiter list to be used. */
do j=1 for length(d) /*process each delimiter singly. */
_=substr(d,j,1) /*use one delimiter at a time. */
parse var x x (_) /*parse X string for each delim. */
end /*j*/
return strip(x) /*return striped shortened string*/
/*──────────────────────────────────STRIPCOM4 subroutine────────────────*/
stripCom4: procedure; parse arg x /*get the argument (string). */
d = ';#' /*the delimiter list to be used. */
do k=1 for length(d) /*process each delimiter singly. */
p=pos(substr(d,k,1),x) /*see if a delimiter is in X. */
if p\==0 then x=left(x,p-1) /*shorten the X string.*/
end /*k*/
return strip(x) /*return striped shortened string*/

View file

@ -0,0 +1,11 @@
Function strip_comments(s,char)
If InStr(1,s,char) > 0 Then
arr = Split(s,char)
strip_comments = RTrim(arr(0))
Else
strip_comments = s
End If
End Function
WScript.StdOut.WriteLine strip_comments("apples, pears # and bananas","#")
WScript.StdOut.WriteLine strip_comments("apples, pears ; and bananas",";")