Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
81
Task/Multisplit/Ada/multisplit.adb
Normal file
81
Task/Multisplit/Ada/multisplit.adb
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
with Ada.Containers.Indefinite_Doubly_Linked_Lists;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Multisplit is
|
||||
package String_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists
|
||||
(Element_Type => String);
|
||||
use type String_Lists.Cursor;
|
||||
|
||||
function Split
|
||||
(Source : String;
|
||||
Separators : String_Lists.List)
|
||||
return String_Lists.List
|
||||
is
|
||||
Result : String_Lists.List;
|
||||
Next_Position : Natural := Source'First;
|
||||
Prev_Position : Natural := Source'First;
|
||||
Separator_Position : String_Lists.Cursor;
|
||||
Separator_Length : Natural;
|
||||
Changed : Boolean;
|
||||
begin
|
||||
loop
|
||||
Changed := False;
|
||||
Separator_Position := Separators.First;
|
||||
while Separator_Position /= String_Lists.No_Element loop
|
||||
Separator_Length :=
|
||||
String_Lists.Element (Separator_Position)'Length;
|
||||
if Next_Position + Separator_Length - 1 <= Source'Last
|
||||
and then Source
|
||||
(Next_Position .. Next_Position + Separator_Length - 1) =
|
||||
String_Lists.Element (Separator_Position)
|
||||
then
|
||||
if Next_Position > Prev_Position then
|
||||
Result.Append
|
||||
(Source (Prev_Position .. Next_Position - 1));
|
||||
end if;
|
||||
Result.Append (String_Lists.Element (Separator_Position));
|
||||
Next_Position := Next_Position + Separator_Length;
|
||||
Prev_Position := Next_Position;
|
||||
Changed := True;
|
||||
exit;
|
||||
end if;
|
||||
Separator_Position := String_Lists.Next (Separator_Position);
|
||||
end loop;
|
||||
if not Changed then
|
||||
Next_Position := Next_Position + 1;
|
||||
end if;
|
||||
if Next_Position > Source'Last then
|
||||
Result.Append (Source (Prev_Position .. Source'Last));
|
||||
exit;
|
||||
end if;
|
||||
end loop;
|
||||
return Result;
|
||||
end Split;
|
||||
|
||||
Test_Input : constant String := "a!===b=!=c";
|
||||
Test_Separators : String_Lists.List;
|
||||
Test_Result : String_Lists.List;
|
||||
Pos : String_Lists.Cursor;
|
||||
begin
|
||||
Test_Separators.Append ("==");
|
||||
Test_Separators.Append ("!=");
|
||||
Test_Separators.Append ("=");
|
||||
Test_Result := Split (Test_Input, Test_Separators);
|
||||
Pos := Test_Result.First;
|
||||
while Pos /= String_Lists.No_Element loop
|
||||
Ada.Text_IO.Put (" " & String_Lists.Element (Pos));
|
||||
Pos := String_Lists.Next (Pos);
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
-- other order of separators
|
||||
Test_Separators.Clear;
|
||||
Test_Separators.Append ("=");
|
||||
Test_Separators.Append ("!=");
|
||||
Test_Separators.Append ("==");
|
||||
Test_Result := Split (Test_Input, Test_Separators);
|
||||
Pos := Test_Result.First;
|
||||
while Pos /= String_Lists.No_Element loop
|
||||
Ada.Text_IO.Put (" " & String_Lists.Element (Pos));
|
||||
Pos := String_Lists.Next (Pos);
|
||||
end loop;
|
||||
end Multisplit;
|
||||
72
Task/Multisplit/Fortran/multisplit.f
Normal file
72
Task/Multisplit/Fortran/multisplit.f
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
!
|
||||
! Multisplit
|
||||
! tested with Intel ifx (IFX) 2025.2.1 20250806 on Kubuntu 26.04
|
||||
! GNU gfortran (Ubuntu 15.2.0-16ubuntu1) 15.2.0 on Kubuntu 26.04
|
||||
! VSI Fortran x86-64 V8.7-001 on OpenVMS V9.2-3
|
||||
! U.B., April 2026
|
||||
!
|
||||
program Multisplit
|
||||
implicit none
|
||||
|
||||
character (len=*), parameter :: inputString = 'a!===b=!=c'
|
||||
integer, parameter ::nSep=3
|
||||
|
||||
character (len=2), dimension(nSep), parameter :: separators = ['==', '!=', '= ']
|
||||
! Trailing spaces in the separator strings will be ignored
|
||||
! The order in which the separators are defined here is significant because
|
||||
! '=' conflicts with '==' if '=' comes before '=='.
|
||||
|
||||
call split (inputString, separators, nSep)
|
||||
|
||||
contains
|
||||
|
||||
|
||||
! ========================================================================
|
||||
! Split input string "txt", at positions of any of the separators "sep)
|
||||
! print recognised separators in parentheses(), and also the ordinary text
|
||||
! ========================================================================
|
||||
subroutine split (txt, separators, nSep)
|
||||
character (len=*), intent(in) :: txt
|
||||
integer, intent(in) :: nSep
|
||||
character (len=*), dimension(nSep) :: separators
|
||||
|
||||
integer :: ii, idx
|
||||
|
||||
write (*, '("Input: ", A)') txt
|
||||
write (*, '("Result: ")', advance='no')
|
||||
|
||||
ii = 1
|
||||
do while (ii .le. len_trim(txt)) ! step through the entire input string, letter by letter
|
||||
idx = match (txt, ii, separators, nSep) ! Try to find one of the separators at position ii
|
||||
if (idx .eq. 0) then ! If we find no separator at position ii ...
|
||||
write (*, '(A1)', advance='no') txt(ii:ii) ! ... print letter at pos. ii,
|
||||
ii = ii + 1 ! ... and go to next letter
|
||||
else ! If Separator # idx found here,...
|
||||
write (*, '("(",A,")")', advance='no') separators(idx)(:len_trim(separators(idx)) ) ! ... print the separator in (),
|
||||
ii = ii + len_trim(separators(idx)) ! ... and skip to next letter
|
||||
endif
|
||||
end do
|
||||
write (*,*) ! Terminate output line.
|
||||
end subroutine split
|
||||
|
||||
! ==============================================================
|
||||
! Check if txt at position istart matches any of the separators.
|
||||
! If so, return index of the matching separator, otherwise 0.
|
||||
! ==============================================================
|
||||
function match (txt, istart, separators, nsep ) result (ix)
|
||||
|
||||
character (len=*), intent(in) :: txt
|
||||
integer, intent(in) :: nsep, istart
|
||||
character (len=*), dimension(nsep), intent(in) :: separators
|
||||
integer :: ix
|
||||
integer :: ii
|
||||
|
||||
do ii=1, nsep
|
||||
if (txt(istart:istart-1+len_trim(separators(ii))) .eq. separators(ii)(:len_trim(separators(ii)))) then
|
||||
ix = ii
|
||||
return
|
||||
endif
|
||||
enddo
|
||||
ix = 0 ! no match
|
||||
end function match
|
||||
end program Multisplit
|
||||
11
Task/Multisplit/PowerShell/multisplit.ps1
Normal file
11
Task/Multisplit/PowerShell/multisplit.ps1
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
$string = "a!===b=!=c"
|
||||
$separators = [regex]"(==|!=|=)"
|
||||
|
||||
$matchInfo = $separators.Matches($string) |
|
||||
Select-Object -Property Index, Value |
|
||||
Group-Object -Property Value |
|
||||
Select-Object -Property @{Name="Separator"; Expression={$_.Name}},
|
||||
Count,
|
||||
@{Name="Position" ; Expression={$_.Group.Index}}
|
||||
|
||||
$matchInfo
|
||||
27
Task/Multisplit/VBScript/multisplit.vbs
Normal file
27
Task/Multisplit/VBScript/multisplit.vbs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
Function multisplit(s,sep)
|
||||
arr_sep = Split(sep,"|")
|
||||
For i = 0 To UBound(arr_sep)
|
||||
arr_s = Split(s,arr_sep(i))
|
||||
s = Join(arr_s,",")
|
||||
Next
|
||||
multisplit = s
|
||||
End Function
|
||||
|
||||
Function multisplit_extra(s,sep)
|
||||
Set dict_sep = CreateObject("Scripting.Dictionary")
|
||||
arr_sep = Split(sep,"|")
|
||||
For i = 0 To UBound(arr_sep)
|
||||
dict_sep.Add i,"(" & arr_sep(i) & ")"
|
||||
arr_s = Split(s,arr_sep(i))
|
||||
s = Join(arr_s,i)
|
||||
Next
|
||||
For Each key In dict_sep.Keys
|
||||
s = Replace(s,key,dict_sep.Item(key))
|
||||
Next
|
||||
multisplit_extra = s
|
||||
End Function
|
||||
|
||||
WScript.StdOut.Write "Standard: " & multisplit("a!===b=!=c","!=|==|=")
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write "Extra Credit: " & multisplit_extra("a!===b=!=c","!=|==|=")
|
||||
WScript.StdOut.WriteLine
|
||||
Loading…
Add table
Add a link
Reference in a new issue