Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split multiline strings #164

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

akihiro17
Copy link
Contributor

I'd like the split function to work with multiline strings, similar to the lines function. In this commit, the split function reads the text until it encounters a NULL character.

And I use printf to pass the text instead of a here document to avoid the extra newline.

$ cat < <(printf %s "Hello, world") | od -c
0000000   H   e   l   l   o   ,       w   o   r   l   d
0000014
$ cat <<< "Hello, world" | od -c
0000000   H   e   l   l   o   ,       w   o   r   l   d  \n
0000015

script

import { words } from "std"

let str = "abd\txd e\nfgh:i"
loop word in words(str) {
  echo "==="
  echo word
  echo "==="
}

heredoc
unsafe $IFS="{delimiter}" read -rd '' -a {nameof result} <<<"\${nameof text}"$

===
abd	xd
===
===
e
fgh:i

===

printf

===
abd	xd
===
===
e
fgh:i
===

@arapower
Copy link
Contributor

arapower commented Jun 9, 2024

First, I confirmed that the differences in the behavior of the sample scripts are as follows:

// Amber script
import { words } from "std"

let str = "abd\txd e\nfgh:i"
loop word in words(str) {
  echo "==="
  echo word
  echo "==="
}
# Ph0enixKM:master
$ ./target/release/amber $script
===
abd     xd
===
===
e
===
# akihiro17:split-multiline-string
$ ./target/release/amber $script
===
abd     xd
===
===
e
fgh:i
===

I understand what you want to achieve.

Next, what's the motivation behind this change in the test code?
Rather than modifying the existing test code, why not add some test code for split and words functions?

@akihiro17
Copy link
Contributor Author

I have added the test code for this change.

Copy link
Contributor

@arapower arapower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Ph0enixKM Ph0enixKM merged commit a2f6f07 into amber-lang:master Jun 17, 2024
1 check passed
@akihiro17 akihiro17 deleted the split-multiline-string branch June 18, 2024 04:03
Copy link

@Sec32fun32 Sec32fun32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sec7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants