Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
3a69f29d
wa
项目概览
wa-lang
/
wa
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
3a69f29d
编写于
8月 02, 2023
作者:
chai2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
标准库添加 archive/txtar 包, 还不能用
上级
37636969
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
183 addition
and
0 deletion
+183
-0
waroot/src/archive/txtar/archive.wa
waroot/src/archive/txtar/archive.wa
+142
-0
waroot/src/bytes/buf.wa
waroot/src/bytes/buf.wa
+15
-0
waroot/src/bytes/bytes.wa
waroot/src/bytes/bytes.wa
+16
-0
waroot/src/os/os.wa
waroot/src/os/os.wa
+4
-0
waroot/src/strings/keep.wa
waroot/src/strings/keep.wa
+5
-0
waroot/waroot.go
waroot/waroot.go
+1
-0
未找到文件。
waroot/src/archive/txtar/archive.wa
0 → 100644
浏览文件 @
3a69f29d
// 版权 @2023 凹语言 作者。保留所有权利。
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package txtar implements a trivial text-based file archive format.
//
// The goals for the format are:
//
// - be trivial enough to create and edit by hand.
// - be able to store trees of text files describing go command test cases.
// - diff nicely in git history and code reviews.
//
// Non-goals include being a completely general archive format,
// storing binary data, storing file modes, storing special files like
// symbolic links, and so on.
//
// Txtar format
//
// A txtar archive is zero or more comment lines and then a sequence of file entries.
// Each file entry begins with a file marker line of the form "-- FILENAME --"
// and is followed by zero or more file content lines making up the file data.
// The comment or file content ends at the next file marker line.
// The file marker line must begin with the three-byte sequence "-- "
// and end with the three-byte sequence " --", but the enclosed
// file name can be surrounding by additional white space,
// all of which is stripped.
//
// If the txtar file is missing a trailing newline on the final line,
// parsers should consider a final newline to be present anyway.
//
// There are no possible syntax errors in a txtar archive.
import (
"bytes"
"os"
"strings"
)
// An Archive is a collection of files.
type Archive struct {
Comment: []byte
Files: []File
}
// A File is a single file in an archive.
type File struct {
Name: string // name of file ("foo/bar.txt")
Data: []byte // text content of file
}
// Format returns the serialized form of an Archive.
// It is assumed that the Archive data structure is well-formed:
// a.Comment and all a.File[i].Data contain no file marker lines,
// and all a.File[i].Name is non-empty.
func Format(a: *Archive) => []byte {
buf: bytes.Buffer
buf.Write(fixNL(a.Comment))
for _, f := range a.Files {
buf.WriteString("-- ")
buf.WriteString(f.Name)
buf.WriteString(" --\n")
buf.Write(fixNL(f.Data))
}
return buf.Bytes()
}
// ParseFile parses the named file as an archive.
func ParseFile(file: string) => (*Archive, error) {
data, err := os.ReadFile(file)
if err != nil {
return nil, err
}
return Parse(data), nil
}
// Parse parses the serialized form of an Archive.
// The returned Archive holds slices of data.
func Parse(data: []byte) => *Archive {
a := new(Archive)
name: string
a.Comment, name, data = findFileMarker(data)
for name != "" {
f := File{name, nil}
f.Data, name, data = findFileMarker(data)
a.Files = append(a.Files, f)
}
return a
}
global (
newlineMarker = []byte("\n-- ")
marker = []byte("-- ")
markerEnd = []byte(" --")
)
// findFileMarker finds the next file marker in data,
// extracts the file name, and returns the data before the marker,
// the file name, and the data after the marker.
// If there is no next marker, findFileMarker returns before = fixNL(data), name = "", after = nil.
func findFileMarker(data: []byte) => (before: []byte, name: string, after: []byte) {
i: int
for {
if name, after = isMarker(data[i:]); name != "" {
return data[:i], name, after
}
j := bytes.Index(data[i:], newlineMarker)
if j < 0 {
return fixNL(data), "", nil
}
i += j + 1 // positioned at start of new possible marker
}
}
// isMarker checks whether data begins with a file marker line.
// If so, it returns the name from the line and the data after the line.
// Otherwise it returns name == "" with an unspecified after.
func isMarker(data: []byte) => (name: string, after: []byte) {
if !bytes.HasPrefix(data, marker) {
return "", nil
}
if i := bytes.IndexByte(data, '\n'); i >= 0 {
data, after = data[:i], data[i+1:]
}
if !(bytes.HasSuffix(data, markerEnd) && len(data) >= len(marker)+len(markerEnd)) {
return "", nil
}
return strings.TrimSpace(string(data[len(marker) : len(data)-len(markerEnd)])), after
}
// If data is empty or ends in \n, fixNL returns data.
// Otherwise fixNL returns a new slice consisting of data with a final \n added.
func fixNL(data: []byte) => []byte {
if len(data) == 0 || data[len(data)-1] == '\n' {
return data
}
d := make([]byte, len(data)+1)
copy(d, data)
d[len(data)] = '\n'
return d
}
waroot/src/bytes/buf.wa
0 → 100644
浏览文件 @
3a69f29d
// 版权 @2023 凹语言 作者。保留所有权利。
type Buffer struct {}
func Buffer.Write(p: []byte) => (n: int, err: error) {
return
}
func Buffer.WriteString(s: string) => (n: int, err: error) {
return
}
func Buffer.Bytes => []byte {
return nil
}
\ No newline at end of file
waroot/src/bytes/bytes.wa
浏览文件 @
3a69f29d
...
...
@@ -24,6 +24,22 @@ func EqualFold(s, t: []byte) => bool {
return true
}
func IndexByte(d: []byte, x: rune) => int {
return 0
}
func Index(d: []byte, x: []byte) => int {
return 0
}
func HasPrefix(d, prefix: []byte) => bool {
return false
}
func HasSuffix(d, suffix: []byte) => bool {
return false
}
func toupper(c: byte) => byte {
if c >= 'a' && c <= 'z' {
return c - 32
...
...
waroot/src/os/os.wa
浏览文件 @
3a69f29d
...
...
@@ -18,3 +18,7 @@ func init {
func Environ() => []string {
return os_get_environs()
}
func ReadFile(name: string) => ([]byte, error) {
return nil, nil
}
\ No newline at end of file
waroot/src/strings/keep.wa
浏览文件 @
3a69f29d
// 版权 @2023 凹语言 作者。保留所有权利。
func TrimSpace(s: string) => string {
return s
}
\ No newline at end of file
waroot/waroot.go
浏览文件 @
3a69f29d
...
...
@@ -105,6 +105,7 @@ func GetStdPkgList() []string {
var
stdPkgs
=
[]
string
{
"apple"
,
"archive/txtar"
,
"binary"
,
"bytes"
,
"errors"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录