Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
91ecd0c2
wa
项目概览
wa-lang
/
wa
10 个月 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
91ecd0c2
编写于
8月 21, 2023
作者:
chai2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bytes 包补充测试
上级
69aaa0d6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
21 deletion
+24
-21
waroot/src/bytes/bytes.wa
waroot/src/bytes/bytes.wa
+21
-17
waroot/src/bytes/bytes_test.wa
waroot/src/bytes/bytes_test.wa
+3
-4
未找到文件。
waroot/src/bytes/bytes.wa
浏览文件 @
91ecd0c2
// 版权 @2023 凹语言 作者。保留所有权利。
import (
//"unicode" => _
"unicode/utf8"
)
...
...
@@ -339,16 +338,31 @@ func genSplit(s, sep: []byte, sepSave, n: int) => [][]byte {
global asciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1}
const (
unicode_MaxRune = '\U0010FFFF' // Maximum valid Unicode code point.
unicode_ReplacementChar = '\uFFFD' // Represents invalid code points.
unicode_MaxASCII = '\u007F' // maximum ASCII value.
unicode_MaxLatin1 = '\u00FF' // maximum Latin-1 value.
)
// 简化版本, 不支持 unicode 空白
func unicode_IsSpace(r: rune) => bool {
// This property isn't the same as Z; special-case it.
if u32(r) <= unicode_MaxLatin1 {
switch r {
case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0:
return true
}
return false
}
return false
}
// Fields interprets s as a sequence of UTF-8-encoded code points.
// It splits the slice s around each instance of one or more consecutive white space
// characters, as defined by unicode.IsSpace, returning a slice of subslices of s or an
// empty slice if s contains only white space.
func Fields(s: []byte) => [][]byte {
if true {
return nil
}
/*
// First count the fields.
// This is an exact count if s is ASCII, otherwise it is an approximation.
n := 0
...
...
@@ -365,7 +379,7 @@ func Fields(s: []byte) => [][]byte {
if setBits >= utf8.RuneSelf {
// Some runes in the input slice are not ASCII.
return FieldsFunc(s, unicode
.
IsSpace)
return FieldsFunc(s, unicode
_
IsSpace)
}
// ASCII fast path
...
...
@@ -396,9 +410,6 @@ func Fields(s: []byte) => [][]byte {
a[na] = s[fieldStart:len(s):len(s)]
}
return a
*/
return nil
}
...
...
@@ -410,10 +421,6 @@ func Fields(s: []byte) => [][]byte {
// FieldsFunc makes no guarantees about the order in which it calls f(c)
// and assumes that f always returns the same value for a given c.
func FieldsFunc(s: []byte, f: func(rune) => bool) => [][]byte {
if true {
return nil
}
/*
// A span is used to record a slice of s of the form s[start:end].
// The start index is inclusive and the end index is exclusive.
type span struct {
...
...
@@ -458,9 +465,6 @@ func FieldsFunc(s: []byte, f: func(rune) => bool) => [][]byte {
}
return a
*/
return nil
}
// explode splits s into a slice of UTF-8 sequences, one per Unicode code point (still slices of bytes),
...
...
waroot/src/bytes/bytes_test.wa
浏览文件 @
91ecd0c2
...
...
@@ -550,13 +550,13 @@ global fieldstests = []FieldsTest{
{"1 2 3 4", []string{"1", "2", "3", "4"}},
{"1 2 3 4", []string{"1", "2", "3", "4"}},
{"1\t\t2\t\t3\t4", []string{"1", "2", "3", "4"}},
{"1\u20002\u20013\u20024", []string{"1", "2", "3", "4"}},
{"\u2000\u2001\u2002", []string{}},
//
{"1\u20002\u20013\u20024", []string{"1", "2", "3", "4"}},
//
{"\u2000\u2001\u2002", []string{}},
{"\n™\t™\n", []string{"™", "™"}},
{faces, []string{faces}},
}
func
_
TestFields {
func TestFields {
for _, tt := range fieldstests {
b := []byte(tt.s)
a := Fields(b)
...
...
@@ -578,7 +578,6 @@ func _TestFields {
//t.Errorf("slice changed to %s; want %s", string(b), tt.s)
}
if len(tt.a) > 0 {
assert(false)
if want := tt.a[len(tt.a)-1] + "z"; string(x) != want {
assert(false)
// t.Errorf("last appended result was %s; want %s", x, want)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录