毕业设计一周一记06
string 包
func TrimSpace
去除字符串的所有前导和尾随空格
net/url包
type URL
type URL struct { Scheme string
Opaque string // encoded opaque data
User *Userinfo // username and password information
Host string // host or host:port
Path string
RawQuery string // encoded query values, without '?'
Fragment string // fragment for references, without '#'
}
fmt.println的打印原理
// Println 使用其操作数的默认格式进行格式化并写入到标准输出。
// 其操作数之间总是添加空格,且总在最后追加一个换行符。
// 它返回写入的字节数以及任何遇到的错误。
func Println(a ...interface{}) (n int, err error) {
return Fprintln(os.Stdout, a...)
}
var (
Stdin = NewFile(uintptr(syscall.Stdin), "/dev/stdin")
Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout")
Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr")
)
type uintptr uintptr
uintptr 为整数类型,其大小足以容纳任何指针的位模式
syscall包中
var (
Stdin = 0
Stdout = 1
Stderr = 2
)
// NewFile returns a new File with the given file descriptor and name.
func NewFile(fd uintptr, name string) *File {
fdi := int(fd)
if fdi < 0 {
return nil
}
f := &File{&file{fd: fdi, name: name}}
runtime.SetFinalizer(f.file, (*file).close)
return f
}
// Fprintln 使用其操作数的默认格式进行格式化并写入到 w。
// 其操作数之间总是添加空格,且总在最后追加一个换行符。
// 它返回写入的字节数以及任何遇到的错误。
func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
p := newPrinter()
p.doPrint(a, true, true)
n, err = w.Write(p.buf)
p.free()
return
}
// newPrinter 分配一个新的,或抓取一个已缓存的 pp 结构体。
func newPrinter() *pp {
p := ppFree.Get().(*pp)
p.panicking = false
p.erroring = false
p.fmt.init(&p.buf)
return p
}
type pp struct {
n int
panicking bool
erroring bool // printing an error condition // 打印错误条件
buf buffer
// arg holds the current item, as an interface{}.
// arg 将当前条目作为 interface{} 类型的值保存。
arg interface{}
// value holds the current item, as a reflect.Value, and will be
// the zero Value if the item has not been reflected.
// value 将当前条目作为 reflect.Value 类型的值保存;若该条目未被反射,则为
// Value 类型的零值。
value reflect.Value
// reordered records whether the format string used argument reordering.
// reordered 记录该格式字符串是否用实参来重新排序。
reordered bool
// goodArgNum records whether the most recent reordering directive was valid.
// goodArgNum 记录最近重新排序的指令是否有效。
goodArgNum bool
runeBuf [utf8.UTFMax]byte
fmt fmt
}
func (p *pp) doPrint(a []interface{}, addspace, addnewline bool) {
prevString := false
for argNum := 0; argNum < len(a); argNum++ {
p.fmt.clearflags()
// always add spaces if we're doing Println
// 若我们执行 Println 就总是添加空格
arg := a[argNum]
if argNum > 0 {
isString := arg != nil && reflect.TypeOf(arg).Kind() == reflect.String
if addspace || !isString && !prevString {
p.buf.WriteByte(' ')
}
}
prevString = p.printArg(arg, 'v', 0)
}
if addnewline {
p.buf.WriteByte('\n')
}
}
func (p *pp) doPrintf(format string, a []interface{}) {
}// Println 使用其操作数的默认格式进行格式化并写入到标准输出。
// 其操作数之间总是添加空格,且总在最后追加一个换行符。
// 它返回写入的字节数以及任何遇到的错误。
func Println(a ...interface{}) (n int, err error) {
return Fprintln(os.Stdout, a...)
}
var (
Stdin = NewFile(uintptr(syscall.Stdin), "/dev/stdin")
Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout")
Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr")
)
type uintptr uintptr
uintptr 为整数类型,其大小足以容纳任何指针的位模式
syscall包中
var (
Stdin = 0
Stdout = 1
Stderr = 2
)
// NewFile returns a new File with the given file descriptor and name.
func NewFile(fd uintptr, name string) *File {
fdi := int(fd)
if fdi < 0 {
return nil
}
f := &File{&file{fd: fdi, name: name}}
runtime.SetFinalizer(f.file, (*file).close)
return f
}
// Fprintln 使用其操作数的默认格式进行格式化并写入到 w。
// 其操作数之间总是添加空格,且总在最后追加一个换行符。
// 它返回写入的字节数以及任何遇到的错误。
func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
p := newPrinter()
p.doPrint(a, true, true)
n, err = w.Write(p.buf)
p.free()
return
}
// newPrinter 分配一个新的,或抓取一个已缓存的 pp 结构体。
func newPrinter() *pp {
p := ppFree.Get().(*pp)
p.panicking = false
p.erroring = false
p.fmt.init(&p.buf)
return p
}
type pp struct {
n int
panicking bool
erroring bool // printing an error condition // 打印错误条件
buf buffer
// arg holds the current item, as an interface{}.
// arg 将当前条目作为 interface{} 类型的值保存。
arg interface{}
// value holds the current item, as a reflect.Value, and will be
// the zero Value if the item has not been reflected.
// value 将当前条目作为 reflect.Value 类型的值保存;若该条目未被反射,则为
// Value 类型的零值。
value reflect.Value
// reordered records whether the format string used argument reordering.
// reordered 记录该格式字符串是否用实参来重新排序。
reordered bool
// goodArgNum records whether the most recent reordering directive was valid.
// goodArgNum 记录最近重新排序的指令是否有效。
goodArgNum bool
runeBuf [utf8.UTFMax]byte
fmt fmt
}
func (p *pp) doPrintf(format string, a []interface{}) {
end := len(format)
argNum := 0 // we process one argument per non-trivial format // 我们为每个非平凡格式都处理一个实参。
afterIndex := false // previous item in format was an index like [3]. // 格式中的前一项是否为类似于 [3] 的下标。
p.reordered = false
for i := 0; i < end; {
p.goodArgNum = true
lasti := i
for i < end && format[i] != '%' {
i++
}
if i > lasti {
p.buf.WriteString(format[lasti:i])
}
if i >= end {
// done processing format string // 处理格式字符串完成
break
}
// Process one verb // 处理个占位符
i++
// Do we have flags? // 是否有标记?
p.fmt.clearflags()
F:
for ; i < end; i++ {
switch format[i] {
case '#':
p.fmt.sharp = true
case '0':
p.fmt.zero = true
case '+':
p.fmt.plus = true
case '-':
p.fmt.minus = true
case ' ':
p.fmt.space = true
default:
break F
}
}
// Do we have an explicit argument index?
// 有显式的实参下标么?
argNum, i, afterIndex = p.argNumber(argNum, format, i, len(a))
// Do we have width?
// 有宽度不?
if i < end && format[i] == '*' {
i++
p.fmt.wid, p.fmt.widPresent, argNum = intFromArg(a, argNum)
if !p.fmt.widPresent {
p.buf.Write(badWidthBytes)
}
afterIndex = false
} else {
p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end)
if afterIndex && p.fmt.widPresent { // "%[3]2d"
p.goodArgNum = false
}
}
// Do we have precision?
// 有精度不?
if i+1 < end && format[i] == '.' {
i++
if afterIndex { // "%[3].2d"
p.goodArgNum = false
}
argNum, i, afterIndex = p.argNumber(argNum, format, i, len(a))
if i < end && format[i] == '*' {
i++
p.fmt.prec, p.fmt.precPresent, argNum = intFromArg(a, argNum)
if !p.fmt.precPresent {
p.buf.Write(badPrecBytes)
}
afterIndex = false
} else {
p.fmt.prec, p.fmt.precPresent, i = parsenum(format, i, end)
if !p.fmt.precPresent {
p.fmt.prec = 0
p.fmt.precPresent = true
}
}
}
if !afterIndex {
argNum, i, afterIndex = p.argNumber(argNum, format, i, len(a))
}
if i >= end {
p.buf.Write(noVerbBytes)
continue
}
c, w := utf8.DecodeRuneInString(format[i:])
i += w
// percent is special - absorbs no operand
// 百分号是特殊的 —— 它不接受操作数
if c == '%' {
p.buf.WriteByte('%') // We ignore width and prec. // 我们忽略宽度和精度。
continue
}
if !p.goodArgNum {
p.buf.Write(percentBangBytes)
p.add(c)
p.buf.Write(badIndexBytes)
continue
} else if argNum >= len(a) { // out of operands // 超过操作数
p.buf.Write(percentBangBytes)
p.add(c)
p.buf.Write(missingBytes)
continue
}
arg := a[argNum]
argNum++
if c == 'v' {
if p.fmt.sharp {
// Go syntax. Set the flag in the fmt and clear the sharp flag.
p.fmt.sharp = false
p.fmt.sharpV = true
}
if p.fmt.plus {
// Struct-field syntax. Set the flag in the fmt and clear the plus flag.
p.fmt.plus = false
p.fmt.plusV = true
}
}
p.printArg(arg, c, 0)
}
// Check for extra arguments unless the call accessed the arguments
// out of order, in which case it's too expensive to detect if they've all
// been used and arguably OK if they're not.
if !p.reordered && argNum < len(a) {
p.buf.Write(extraBytes)
for ; argNum < len(a); argNum++ {
arg := a[argNum]
if arg != nil {
p.buf.WriteString(reflect.TypeOf(arg).String())
p.buf.WriteByte('=')
}
p.printArg(arg, 'v', 0)
if argNum+1 < len(a) {
p.buf.Write(commaSpaceBytes)
}
}
p.buf.WriteByte(')')
}
}
转载于:https://www.cnblogs.com/amiee/p/7986368.html
毕业设计一周一记06相关推荐
- 毕业设计一周一记02
本周任务: 1.后台数据库设计 2.业务流程设计 3.前台排版设计 任务完成情况和开发经历: 实践经验一: 模板的使用: 将公用的部分编写成.tpl文件 {{define "hander&q ...
- 毕业设计一周一记04
本周任务: 完成购物车相关功能的实现. 知识点一: beego表关系设置 数据表之间的关系: 一:一对一关系 RelOneToOne 设置方法:需要在字段后设置`orm:"rel(one ...
- 毕业设计第二周学习心得
卷积神经网络 一.绪论 1.卷积神经网络的应用 无处不在的卷积神经网路 分割.检测.分类.人脸识别.人脸表情识别.图像生成.图像风格转化.自动驾驶 2.传统神经网络vs卷积神经网络 深度学习三部曲 S ...
- python代码根据时间获取周数(week of the year)
python代码根据时间获取周数(week of the year) # 使用python获取当前是当年的第多少周 import time import datetime # 获取今天是第几周 pri ...
- 华清远见嵌入式培训_第六周回顾与反思
目录 前言 周二 IO简介和标准IO 一.IO简介 1.1 什么是IO 1.2 IO的分类 1.3 什么是系统调用和和库函数 1.4 什么是IO接口 二.标准IO 2.1 fopen/fclose函数 ...
- js知道年月日怎么获取到是周几,和几月几号
你可以使用 JavaScript 的内置对象 Date 来获取年月日.周几以及几月几号的信息. 下面是一些示例代码: // 获取当前日期 const today = new Date();// 获取年 ...
- JavaScript获取具体是周几
js获取具体是周几主要通过new Date()获取当前的时间对象 然后 里面有一个 getDay函数 他会返回一个数字 就是今天是周几 0-6 0代表周日 这个是外国的或者说统一的计算方式 每周是从周 ...
- linux基础命令介绍十四:定时任务
在计算机的使用过程中,经常会有一些计划中的任务需要在将来的某个时间执行,linux中提供了一些方法来设定定时任务. 1.at 命令at从文件或标准输入中读取命令并在将来的一个时间执行,只执行一次.at ...
- Linux系统设置定时任务
如题,最近想到自己在电脑上自定义的设置实在太多,想到以后万一换电脑,或者电脑出意外了怎么办,数据实在是太重要了.有什么办法呢?而且不需要经常的提醒自己去手动备份. 我的解决方案是:运行定时脚本 + 坚 ...
最新文章
- 彻底搞懂视觉-惯性SLAM:基于VINS-Fusion(正式开课)
- Xamarin Essentials教程剪贴板Clipboard
- Spring Data JPA 从入门到精通~查询结果的处理
- 语音合成技术与资源 - 资源篇
- C# 运行控制台程序中文乱码
- 写给大一大二大三还在迷惘中的学生
- egret 白鹭引擎学习笔记-写在前面的话
- 【数据结构与算法】详解什么是哈希表,并用代码手动实现一个哈希表
- linux u盘格式化失败怎么办,u盘无法完成格式化怎么办
- Android9.0 HAL 层开发
- 腾讯2019秋招--小q爬塔(dp)
- 滚动轴承故障检测与诊断(一)
- 制作IOS企业版APP网页下载
- 音乐 美术 劳技 计算机教研组工作总结,劳技教研组工作总结
- [益智]:3个女儿的年龄
- Specialty Coffee Evaluation 精品手冲咖啡评测
- GitHub 新手详细教程
- Outlook启动时提示“找不到文件Outlook.pst文件”解决办法
- vue之路由与无痕浏览
- 第十六章——保存、加载数据和应用程序状态
热门文章
- ubuntu永久修改主机名
- 斐波那契数列的非递归实现
- java webservice 客户端_Java Webservice客户端(最佳方法)
- 被尘封的故事技能点bug_王者荣耀体验服更新,多名英雄技能优化,瑶妹玩家却坐不住了...
- c++future 配合httplib post 高级技巧
- sdl2和ffmpeg显示摄像头数据
- html改变占位字符的颜色,使用CSS更改HTML5输入的占位符颜色
- 【java】java AsyncHttpClient使用
- 【elasticsearch】block.ClusterBlockException: blocked by: SERVICE_UNAVAILA
- 【HttpClient】httpclient之post 方法(参数为Map类型)