Skip to content

Instantly share code, notes, and snippets.

@lysu
Created February 3, 2016 10:02
Show Gist options
  • Save lysu/0d8f403e1731c9f75429 to your computer and use it in GitHub Desktop.
Save lysu/0d8f403e1731c9f75429 to your computer and use it in GitHub Desktop.
func concatstrings(a []string) string {
idx := 0
l := 0
count := 0
for i, x := range a {
n := len(x)
if n == 0 {
continue
}
if l+n < l {
gothrow("string concatenation too long")
}
l += n
count++
idx = i
}
if count == 0 {
return ""
}
if count == 1 {
return a[idx]
}
s, b := rawstring(l)
l = 0
for _, x := range a {
copy(b[l:], x)
l += len(x)
}
return s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment