Created
May 20, 2019 01:01
-
-
Save Adron/081a81173c271d5865cbf39ea38aa73b to your computer and use it in GitHub Desktop.
Learning about go runes and hacking together some examples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... the rest of the main.go file is here... | |
var runes []rune | |
for _, r := range "Language: 走" { | |
runes = append(runes, r) | |
} | |
fmt.Printf("%q \n", runes) | |
var x, y []int | |
for i := 0; i < 10; i++ { | |
y = appendInt(x, i) | |
fmt.Printf("%d cap=%d\t%v\n", i, cap(y), y) | |
x = y | |
} | |
} | |
func appendInt(x []int, i int) []int { | |
var z []int | |
zlen := len(x) + 1 | |
if zlen <= cap(x) { | |
z = x[:zlen] | |
} else { | |
zcap := zlen | |
if zcap < 2* len(x) { | |
zcap = 2 * len(x) | |
} | |
z = make([]int, zlen, zcap) | |
copy(z, x) | |
} | |
return z | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment