Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,26 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
const commentChars = "#;"
|
||||
|
||||
func stripComment(source string) string {
|
||||
if cut := strings.IndexAny(source, commentChars); cut >= 0 {
|
||||
return source[:cut]
|
||||
}
|
||||
return source
|
||||
if cut := strings.IndexAny(source, commentChars); cut >= 0 {
|
||||
return strings.TrimRightFunc(source[:cut], unicode.IsSpace)
|
||||
}
|
||||
return source
|
||||
}
|
||||
|
||||
func main() {
|
||||
for _, s := range []string{
|
||||
"apples, pears # and bananas",
|
||||
"apples, pears ; and bananas",
|
||||
"no bananas",
|
||||
} {
|
||||
fmt.Printf("source: %q\n", s)
|
||||
fmt.Printf("stripped: %q\n", stripComment(s))
|
||||
}
|
||||
for _, s := range []string{
|
||||
"apples, pears # and bananas",
|
||||
"apples, pears ; and bananas",
|
||||
"no bananas",
|
||||
} {
|
||||
fmt.Printf("source: %q\n", s)
|
||||
fmt.Printf("stripped: %q\n", stripComment(s))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
> use StringTools in map( Trim@Take, [ "\t\t apples, pears \t# and bananas", " apples, pears ; and bananas \t" ], "#;" ) end;
|
||||
["apples, pears", "apples, pears"]
|
||||
|
|
@ -13,29 +13,29 @@ 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. */
|
||||
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='#;' /*delimiter list to be used. */
|
||||
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. */
|
||||
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=';#' /*delimiter list to be used. */
|
||||
do j=1 for length(d) /*process each delimiter singly. */
|
||||
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. */
|
||||
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=';#' /*delimiter list to be used. */
|
||||
do k=1 for length(d) /*process each delimiter singly. */
|
||||
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.*/
|
||||
if p\==0 then x=left(x,p-1) /*shorten the X string.*/
|
||||
end /*k*/
|
||||
return strip(x) /*return striped shortened string*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue