Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,57 +0,0 @@
|
|||
with Ada.Text_Io;
|
||||
with Ada.Containers.Indefinite_Vectors;
|
||||
with Ada.Strings.Unbounded;
|
||||
|
||||
procedure Tokenize is
|
||||
|
||||
package String_Vectors is
|
||||
new Ada.Containers.Indefinite_Vectors (Positive, String);
|
||||
use String_Vectors;
|
||||
|
||||
function Split (Text : String;
|
||||
Separator : Character := '|';
|
||||
Escape : Character := '^') return Vector
|
||||
is
|
||||
use Ada.Strings.Unbounded;
|
||||
Result : Vector;
|
||||
Escaped : Boolean := False;
|
||||
Accu : Unbounded_String;
|
||||
begin
|
||||
|
||||
for Char of Text loop
|
||||
|
||||
case Escaped is
|
||||
|
||||
when False =>
|
||||
if Char = Escape then
|
||||
Escaped := True;
|
||||
elsif Char = Separator then
|
||||
Append (Result, To_String (Accu));
|
||||
Accu := Null_Unbounded_String;
|
||||
else
|
||||
Append (Accu, Char);
|
||||
end if;
|
||||
|
||||
when True =>
|
||||
Append (Accu, Char);
|
||||
Escaped := False;
|
||||
|
||||
end case;
|
||||
|
||||
end loop;
|
||||
Append (Result, To_String (Accu));
|
||||
|
||||
return Result;
|
||||
end Split;
|
||||
|
||||
procedure Put_Vector (List : Vector) is
|
||||
use Ada.Text_Io;
|
||||
begin
|
||||
for Element of List loop
|
||||
Put ("'"); Put (Element); Put ("'"); New_Line;
|
||||
end loop;
|
||||
end Put_Vector;
|
||||
|
||||
begin
|
||||
Put_Vector (Split ("one^|uno||three^^^^|four^^^|^cuatro|"));
|
||||
end Tokenize;
|
||||
|
|
@ -4,15 +4,15 @@ tokenize: function [s sep esc][
|
|||
loop 0..(size s)-1 [i][
|
||||
chr: get split s i
|
||||
|
||||
if? escaping=1 [
|
||||
switch escaping=1 [
|
||||
prints chr
|
||||
escaping: 0
|
||||
]
|
||||
else [
|
||||
case [chr]
|
||||
when? [=sep] [print ""]
|
||||
when? [=esc] [escaping: 1]
|
||||
else [prints chr]
|
||||
][
|
||||
case chr [
|
||||
sep -> print ""
|
||||
esc -> escaping: 1
|
||||
any -> prints chr
|
||||
]
|
||||
]
|
||||
]
|
||||
print ""
|
||||
|
|
|
|||
|
|
@ -1,135 +0,0 @@
|
|||
>>SOURCE FORMAT FREE
|
||||
identification division.
|
||||
program-id. 'tokenizewithescaping'.
|
||||
environment division.
|
||||
configuration section.
|
||||
repository.
|
||||
function all intrinsic.
|
||||
data division.
|
||||
working-storage section.
|
||||
|
||||
01 escape-char pic x value '^'.
|
||||
01 separator-char pic x value '|'.
|
||||
01 reference-string pic x(64) value
|
||||
'one^|uno||three^^^^|four^^^|^cuatro|'.
|
||||
|
||||
01 input-string pic x(64).
|
||||
01 c pic 99.
|
||||
01 escaped pic x.
|
||||
|
||||
01 t pic 99.
|
||||
01 t-max pic 99.
|
||||
01 t-lim pic 99 value 32.
|
||||
01 token-entry occurs 32.
|
||||
03 token-len pic 99.
|
||||
03 token pic x(16).
|
||||
|
||||
01 l pic 99.
|
||||
01 l-lim pic 99 value 16.
|
||||
|
||||
01 error-found pic x.
|
||||
|
||||
procedure division.
|
||||
start-tokenize-with-escaping.
|
||||
|
||||
move reference-string to input-string
|
||||
perform tokenize
|
||||
|
||||
move 'token' to input-string
|
||||
perform tokenize
|
||||
|
||||
move '^^^^^^^^' to input-string
|
||||
perform tokenize
|
||||
|
||||
move '||||||||' to input-string
|
||||
perform tokenize
|
||||
|
||||
move all 'token' to input-string
|
||||
perform tokenize
|
||||
|
||||
move all 't|' to input-string
|
||||
perform tokenize
|
||||
|
||||
move spaces to input-string
|
||||
perform tokenize
|
||||
|
||||
display space
|
||||
|
||||
stop run
|
||||
.
|
||||
tokenize.
|
||||
display space
|
||||
display 'string:'
|
||||
display input-string
|
||||
|
||||
move 'N' to escaped error-found
|
||||
move 1 to t-max
|
||||
initialize token-entry(t-max)
|
||||
move 0 to l
|
||||
|
||||
perform varying c from 1 by 1 until
|
||||
c > length(input-string)
|
||||
or input-string(c:) = spaces
|
||||
|
||||
evaluate escaped also input-string(c:1)
|
||||
when 'N' also escape-char
|
||||
move 'Y' to escaped
|
||||
when 'N' also separator-char
|
||||
perform increment-t-max
|
||||
if error-found = 'Y'
|
||||
exit paragraph
|
||||
end-if
|
||||
when 'N' also any
|
||||
perform move-c
|
||||
if error-found = 'Y'
|
||||
exit paragraph
|
||||
end-if
|
||||
when 'Y' also any
|
||||
perform move-c
|
||||
if error-found = 'Y'
|
||||
exit paragraph
|
||||
end-if
|
||||
move 'N' to escaped
|
||||
end-evaluate
|
||||
|
||||
end-perform
|
||||
if l > 0
|
||||
move l to token-len(t-max)
|
||||
end-if
|
||||
|
||||
if c = 1
|
||||
display 'no tokens'
|
||||
else
|
||||
display 'tokens:'
|
||||
perform varying t from 1 by 1 until t > t-max
|
||||
if token-len(t) > 0
|
||||
display t ': ' token-len(t) space token(t)
|
||||
else
|
||||
display t ': ' token-len(t)
|
||||
end-if
|
||||
end-perform
|
||||
end-if
|
||||
.
|
||||
increment-t-max.
|
||||
if t-max >= t-lim
|
||||
display 'error: at ' c ' number of tokens exceeds ' t-lim
|
||||
move 'Y' to error-found
|
||||
else
|
||||
move l to token-len(t-max)
|
||||
add 1 to t-max
|
||||
initialize token-entry(t-max)
|
||||
move 0 to l
|
||||
move 'N' to error-found
|
||||
end-if
|
||||
.
|
||||
move-c.
|
||||
if l >= l-lim
|
||||
display 'error: at ' c ' token length exceeds ' l-lim
|
||||
move 'Y' to error-found
|
||||
else
|
||||
add 1 to l
|
||||
move input-string(c:1) to token(t-max)(l:1)
|
||||
move 'N' to error-found
|
||||
end-if
|
||||
.
|
||||
end program 'tokenizewithescaping'.
|
||||
|
|
@ -38,9 +38,9 @@ extension op : String
|
|||
}
|
||||
}
|
||||
|
||||
const string testcase = "one^|uno||three^^^^|four^^^|^cuatro|";
|
||||
const string Testcase = "one^|uno||three^^^^|four^^^|^cuatro|";
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
testcase.tokenize("|", "^").forEach(printingLn)
|
||||
Testcase.tokenize("|", "^").forEach(PrintingLn)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
function Split-String ([string]$String, [char]$Separator, [char]$Escape)
|
||||
{
|
||||
if ($String -notmatch "\$Separator|\$Escape") {return $String}
|
||||
|
||||
[bool]$escaping = $false
|
||||
[string]$output = ""
|
||||
|
||||
for ($i = 0; $i -lt $String.Length; $i++)
|
||||
{
|
||||
[char]$character = $String.Substring($i,1)
|
||||
|
||||
if ($escaping)
|
||||
{
|
||||
$output += $character
|
||||
$escaping = $false
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($character)
|
||||
{
|
||||
{$_ -eq $Separator} {$output; $output = ""; break}
|
||||
{$_ -eq $Escape} {$escaping = $true ; break}
|
||||
Default {$output += $character}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($String[-1] -eq $Separator) {[String]::Empty}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
Split-String "one^|uno||three^^^^|four^^^|^cuatro|" -Separator "|" -Escape "^" | ForEach-Object `
|
||||
-Begin {$n = 0} `
|
||||
-Process {$n+= 1; "{0}: {1}" -f $n, $_}
|
||||
Loading…
Add table
Add a link
Reference in a new issue