Tokenize a string with escaping: Difference between revisions

m
Sidef comes before Simula (once again!)
m (Sidef comes before Simula (once again!))
Line 2,116:
 
{{Out}}See it in running in your browser by [https://scalafiddle.io/sf/EsIjPQg/0 ScalaFiddle (JavaScript)] or by [https://scastie.scala-lang.org/O3DgMmuOSCS5DD6zQXK7MA Scastie (JVM)].
 
=={{header|Sidef}}==
{{trans|Perl}}
<lang ruby>func tokenize(string, sep, esc) {
var fields = string.split(
Regex(esc.escape + '.(*SKIP)(*FAIL)|' + sep.escape, 's'), -1
)
fields.map{.gsub(Regex(esc + '(.)'), {|s1| s1 }) }
 
tokenize("one^|uno||three^^^^|four^^^|^cuatro|", '|', '^').each { |str|
say str.dump
}</lang>
{{out}} NOTE: the output is different from the one given in the task
<pre>
"one^|uno"
""
"three^^^^"
"four^^^|^cuatro"
""
</pre>
 
=={{header|Simula}}==
<lang simula>
Line 2,190 ⟶ 2,212:
PART4: 'FOUR^|CUATRO'
PART5: ''
</pre>
=={{header|Sidef}}==
{{trans|Perl}}
<lang ruby>func tokenize(string, sep, esc) {
var fields = string.split(
Regex(esc.escape + '.(*SKIP)(*FAIL)|' + sep.escape, 's'), -1
)
fields.map{.gsub(Regex(esc + '(.)'), {|s1| s1 }) }
 
tokenize("one^|uno||three^^^^|four^^^|^cuatro|", '|', '^').each { |str|
say str.dump
}</lang>
{{out}} NOTE: the output is different from the one given in the task
<pre>
"one^|uno"
""
"three^^^^"
"four^^^|^cuatro"
""
</pre>
 
2,747

edits