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

Pipeline supports slice syntax #129

Merged
merged 1 commit into from
Jan 8, 2025
Merged

Pipeline supports slice syntax #129

merged 1 commit into from
Jan 8, 2025

Conversation

vircoys
Copy link
Contributor

@vircoys vircoys commented Dec 11, 2024

引用 GuanceCloud/platypus#54 (comment)

添加切片操作的语法 a[start:end:step]支持字符串或数组切片,功能包括正向切片、反向切片、嵌套切片、负数索引等。
1.语法解释:
a :要进行切片操作的数组或字符串;
start:切片的起始索引(包含)。如果省略并且step>0,默认为 0;如果step<0,默认为字符串或数组的长度-1。
end:切片的结束索引(不包含)。如果省略并且step>0,默认为字符串或数组的长度,如果step<0,默认为数组或字符串的起始位置。
step:切片的步长。如果省略,默认为 1。
2.特殊处理:
①负数索引:允许从数组的末尾开始计数,索引从 -1 开始;
②允许索引超出范围,当切片的起始/结束位置超出列表的长度时,自动设置为字符串或数组的第一个元素/最后一个元素。
例如数组a=[]int{1,2,3,4,5}
a[-10:10]处理为a[0:5],a[10:-10:-1]处理为a[4::-1]

@guance-review-bot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: coanor, vircoys

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coanor coanor merged commit c6706f7 into main Jan 8, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants