Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,5 @@
(string-suffix? "nette" "Antoinette") → #t
(string-prefix? "Simon" "Simon & Garfunkel") → #t
(string-match "Antoinette" "net") → #t ;; contains
(string-index "net" "Antoinette") → 5 ;; substring location

View file

@ -0,0 +1,26 @@
' FB 1.05.0 Win64
Dim As String s1 = "abracadabra"
Dim As String s2 = "abra"
Print "First string : "; s1
Print "Second string : "; s2
Print
Print "First string begins with second string : "; CBool(s2 = Left(s1, Len(s2)))
Dim As Integer i1 = Instr(s1, s2)
Dim As Integer i2
Print "First string contains second string : ";
If i1 Then
Print "at index"; i1;
i2 = Instr(i1 + Len(s2), s1, s2)
If i2 Then
Print " and at index"; i2
Else
Print
End If
Else
Print "false";
End If
Print "First string ends with second string : "; CBool(s2 = Right(s1, Len(s2)))
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,14 @@
local(
a = 'a quick brown peanut jumped over a quick brown fox',
b = 'a quick brown'
)
//Determining if the first string starts with second string
#a->beginswith(#b) // true
//Determining if the first string contains the second string at any location
#a >> #b // true
#a->contains(#b) // true
//Determining if the first string ends with the second string
#a->endswith(#b) // false

View file

@ -0,0 +1,22 @@
a = "Hello world!"
b = "Hello"
-- Determining if the first string starts with second string
put a starts b
-- 1
-- Determining if the first string contains the second string at any location
put a contains b
-- 1
-- Determining if the first string ends with the second string
put a.char[a.length-b.length+1..a.length] = b
-- 0
b = "world!"
put a.char[a.length-b.length+1..a.length] = b
-- 1
-- Print the location of the match for part 2
put offset(b, a)
-- 7

View file

@ -0,0 +1,10 @@
import strutils
var s: string = "The quick brown fox"
if startsWith(s, "The quick"):
echo("Starts with: The quick")
if endsWith(s, "brown Fox"):
echo("Ends with: brown fox")
var pos = find(s, " brown ") # -1 if not found
if contains(s, " brown "): # showing the contains() proc, but could use if pos!=-1:
echo('"' & " brown " & '"' & " is located at position: " & $pos)

View file

@ -0,0 +1,14 @@
: stringMatching(s1, s2)
| i |
s2 isAllAt(s1, 1) ifTrue: [ System.Out s1 << " begins with " << s2 << cr ]
s2 isAllAt(s1, s1 size s2 size - 1 + ) ifTrue: [ System.Out s1 << " ends with " << s2 << cr ]
s1 indexOfAll(s2) ->i
i ifNotNull: [ System.Out s1 << " includes " << s2 << " at position : " << i << cr ]
"\nAll positions : " println
1 ->i
while (s1 indexOfAllFrom(s2, i) dup ->i notNull) [
System.Out s1 << " includes " << s2 << " at position : " << i << cr
i s2 size + ->i
] ;

View file

@ -0,0 +1,29 @@
constant word = "the", -- (also try this with "th"/"he")
sentence = "the last thing the man said was the"
-- sentence = "thelastthingthemansaidwasthe" -- (practically the same results)
-- A common, but potentially inefficient idiom for checking for a substring at the start is:
if match(word,sentence)=1 then
?"yes(1)"
end if
-- A more efficient method is to test the appropriate slice
if length(sentence)>=length(word)
and sentence[1..length(word)]=word then
?"yes(2)"
end if
-- Which is almost identical to checking for a word at the end
if length(sentence)>=length(word)
and sentence[-length(word)..-1]=word then
?"yes(3)"
end if
-- Or sometimes you will see this, a tiny bit more efficient:
if length(sentence)>=length(word)
and match(word,sentence,length(sentence)-length(word)+1) then
?"yes(4)"
end if
-- Finding all occurences is a snap:
integer r = match(word,sentence)
while r!=0 do
?r
r = match(word,sentence,r+1)
end while

View file

@ -0,0 +1,4 @@
aString = "Welcome to the Ring Programming Language"
bString = "Ring"
bStringIndex = substr(aString,bString)
if bStringIndex > 0 see "" + bStringIndex + " : " + bString ok

View file

@ -0,0 +1,15 @@
var first = "abc-abcdef-abcd";
var second = "abc";
say first.begins_with(second); #=> true
say first.contains(second); #=> true
say first.ends_with(second); #=> false
# Get and print the location of the match
say first.index(second); #=> 0
# Find multiple occurrences of a string
var pos = -1;
while (pos = first.index(second, pos+1) != -1) {
say "Match at pos: #{pos}";
}

View file

@ -0,0 +1,9 @@
var str = "Hello, playground"
str.hasPrefix("Hell") //True
str.hasPrefix("hell") //False
str.containsString("llo") //True
str.containsString("xxoo") //False
str.hasSuffix("playground") //True
str.hasSuffix("world") //False

View file

@ -0,0 +1,3 @@
# startswith/1 is boolean:
"abc" | startswith("ab")
#=> true

View file

@ -0,0 +1,6 @@
# index/1 returns the index or null,
# so the jq test "if index(_) then ...." can be used
# without any type conversion.
"abcd" | index( "bc")
#=> 1

View file

@ -0,0 +1,3 @@
# endswith/1 is also boolean:
"abc" | endswith("bc")
#=> true

View file

@ -0,0 +1,5 @@
"abc" | test( "^ab")
"abcd" | test("bc")
"abcd" | test("cd$")

View file

@ -0,0 +1,6 @@
# In jq 1.4 or later:
jq -n '"abcdabcd" | indices("bc")'
[
1,
5
]

View file

@ -0,0 +1,3 @@
$ jq -n '"abcdabcd" | match("bc"; "g") | .offset'
1
5