You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1733 lines
58 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>bytes - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package bytes</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "bytes"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. <dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
  58. </dl>
  59. </div>
  60. <!-- The package's Name is printed as title by the top-level template -->
  61. <div id="pkg-overview" class="toggleVisible">
  62. <div class="collapsed">
  63. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  64. </div>
  65. <div class="expanded">
  66. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  67. <p>
  68. Package bytes implements functions for the manipulation of byte slices.
  69. It is analogous to the facilities of the strings package.
  70. </p>
  71. </div>
  72. </div>
  73. <div id="pkg-index" class="toggleVisible">
  74. <div class="collapsed">
  75. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  76. </div>
  77. <div class="expanded">
  78. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  79. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  80. <div id="manual-nav">
  81. <dl>
  82. <dd><a href="index.html#pkg-constants">Constants</a></dd>
  83. <dd><a href="index.html#pkg-variables">Variables</a></dd>
  84. <dd><a href="index.html#Compare">func Compare(a, b []byte) int</a></dd>
  85. <dd><a href="index.html#Contains">func Contains(b, subslice []byte) bool</a></dd>
  86. <dd><a href="index.html#Count">func Count(s, sep []byte) int</a></dd>
  87. <dd><a href="index.html#Equal">func Equal(a, b []byte) bool</a></dd>
  88. <dd><a href="index.html#EqualFold">func EqualFold(s, t []byte) bool</a></dd>
  89. <dd><a href="index.html#Fields">func Fields(s []byte) [][]byte</a></dd>
  90. <dd><a href="index.html#FieldsFunc">func FieldsFunc(s []byte, f func(rune) bool) [][]byte</a></dd>
  91. <dd><a href="index.html#HasPrefix">func HasPrefix(s, prefix []byte) bool</a></dd>
  92. <dd><a href="index.html#HasSuffix">func HasSuffix(s, suffix []byte) bool</a></dd>
  93. <dd><a href="index.html#Index">func Index(s, sep []byte) int</a></dd>
  94. <dd><a href="index.html#IndexAny">func IndexAny(s []byte, chars string) int</a></dd>
  95. <dd><a href="index.html#IndexByte">func IndexByte(s []byte, c byte) int</a></dd>
  96. <dd><a href="index.html#IndexFunc">func IndexFunc(s []byte, f func(r rune) bool) int</a></dd>
  97. <dd><a href="index.html#IndexRune">func IndexRune(s []byte, r rune) int</a></dd>
  98. <dd><a href="index.html#Join">func Join(s [][]byte, sep []byte) []byte</a></dd>
  99. <dd><a href="index.html#LastIndex">func LastIndex(s, sep []byte) int</a></dd>
  100. <dd><a href="index.html#LastIndexAny">func LastIndexAny(s []byte, chars string) int</a></dd>
  101. <dd><a href="index.html#LastIndexByte">func LastIndexByte(s []byte, c byte) int</a></dd>
  102. <dd><a href="index.html#LastIndexFunc">func LastIndexFunc(s []byte, f func(r rune) bool) int</a></dd>
  103. <dd><a href="index.html#Map">func Map(mapping func(r rune) rune, s []byte) []byte</a></dd>
  104. <dd><a href="index.html#Repeat">func Repeat(b []byte, count int) []byte</a></dd>
  105. <dd><a href="index.html#Replace">func Replace(s, old, new []byte, n int) []byte</a></dd>
  106. <dd><a href="index.html#Runes">func Runes(s []byte) []rune</a></dd>
  107. <dd><a href="index.html#Split">func Split(s, sep []byte) [][]byte</a></dd>
  108. <dd><a href="index.html#SplitAfter">func SplitAfter(s, sep []byte) [][]byte</a></dd>
  109. <dd><a href="index.html#SplitAfterN">func SplitAfterN(s, sep []byte, n int) [][]byte</a></dd>
  110. <dd><a href="index.html#SplitN">func SplitN(s, sep []byte, n int) [][]byte</a></dd>
  111. <dd><a href="index.html#Title">func Title(s []byte) []byte</a></dd>
  112. <dd><a href="index.html#ToLower">func ToLower(s []byte) []byte</a></dd>
  113. <dd><a href="index.html#ToLowerSpecial">func ToLowerSpecial(_case unicode.SpecialCase, s []byte) []byte</a></dd>
  114. <dd><a href="index.html#ToTitle">func ToTitle(s []byte) []byte</a></dd>
  115. <dd><a href="index.html#ToTitleSpecial">func ToTitleSpecial(_case unicode.SpecialCase, s []byte) []byte</a></dd>
  116. <dd><a href="index.html#ToUpper">func ToUpper(s []byte) []byte</a></dd>
  117. <dd><a href="index.html#ToUpperSpecial">func ToUpperSpecial(_case unicode.SpecialCase, s []byte) []byte</a></dd>
  118. <dd><a href="index.html#Trim">func Trim(s []byte, cutset string) []byte</a></dd>
  119. <dd><a href="index.html#TrimFunc">func TrimFunc(s []byte, f func(r rune) bool) []byte</a></dd>
  120. <dd><a href="index.html#TrimLeft">func TrimLeft(s []byte, cutset string) []byte</a></dd>
  121. <dd><a href="index.html#TrimLeftFunc">func TrimLeftFunc(s []byte, f func(r rune) bool) []byte</a></dd>
  122. <dd><a href="index.html#TrimPrefix">func TrimPrefix(s, prefix []byte) []byte</a></dd>
  123. <dd><a href="index.html#TrimRight">func TrimRight(s []byte, cutset string) []byte</a></dd>
  124. <dd><a href="index.html#TrimRightFunc">func TrimRightFunc(s []byte, f func(r rune) bool) []byte</a></dd>
  125. <dd><a href="index.html#TrimSpace">func TrimSpace(s []byte) []byte</a></dd>
  126. <dd><a href="index.html#TrimSuffix">func TrimSuffix(s, suffix []byte) []byte</a></dd>
  127. <dd><a href="index.html#Buffer">type Buffer</a></dd>
  128. <dd>&nbsp; &nbsp; <a href="index.html#NewBuffer">func NewBuffer(buf []byte) *Buffer</a></dd>
  129. <dd>&nbsp; &nbsp; <a href="index.html#NewBufferString">func NewBufferString(s string) *Buffer</a></dd>
  130. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Bytes">func (b *Buffer) Bytes() []byte</a></dd>
  131. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Cap">func (b *Buffer) Cap() int</a></dd>
  132. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Grow">func (b *Buffer) Grow(n int)</a></dd>
  133. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Len">func (b *Buffer) Len() int</a></dd>
  134. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Next">func (b *Buffer) Next(n int) []byte</a></dd>
  135. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Read">func (b *Buffer) Read(p []byte) (n int, err error)</a></dd>
  136. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.ReadByte">func (b *Buffer) ReadByte() (c byte, err error)</a></dd>
  137. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.ReadBytes">func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)</a></dd>
  138. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.ReadFrom">func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)</a></dd>
  139. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.ReadRune">func (b *Buffer) ReadRune() (r rune, size int, err error)</a></dd>
  140. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.ReadString">func (b *Buffer) ReadString(delim byte) (line string, err error)</a></dd>
  141. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Reset">func (b *Buffer) Reset()</a></dd>
  142. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.String">func (b *Buffer) String() string</a></dd>
  143. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Truncate">func (b *Buffer) Truncate(n int)</a></dd>
  144. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.UnreadByte">func (b *Buffer) UnreadByte() error</a></dd>
  145. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.UnreadRune">func (b *Buffer) UnreadRune() error</a></dd>
  146. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.Write">func (b *Buffer) Write(p []byte) (n int, err error)</a></dd>
  147. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.WriteByte">func (b *Buffer) WriteByte(c byte) error</a></dd>
  148. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.WriteRune">func (b *Buffer) WriteRune(r rune) (n int, err error)</a></dd>
  149. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.WriteString">func (b *Buffer) WriteString(s string) (n int, err error)</a></dd>
  150. <dd>&nbsp; &nbsp; <a href="index.html#Buffer.WriteTo">func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)</a></dd>
  151. <dd><a href="index.html#Reader">type Reader</a></dd>
  152. <dd>&nbsp; &nbsp; <a href="index.html#NewReader">func NewReader(b []byte) *Reader</a></dd>
  153. <dd>&nbsp; &nbsp; <a href="index.html#Reader.Len">func (r *Reader) Len() int</a></dd>
  154. <dd>&nbsp; &nbsp; <a href="index.html#Reader.Read">func (r *Reader) Read(b []byte) (n int, err error)</a></dd>
  155. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadAt">func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)</a></dd>
  156. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadByte">func (r *Reader) ReadByte() (b byte, err error)</a></dd>
  157. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadRune">func (r *Reader) ReadRune() (ch rune, size int, err error)</a></dd>
  158. <dd>&nbsp; &nbsp; <a href="index.html#Reader.Seek">func (r *Reader) Seek(offset int64, whence int) (int64, error)</a></dd>
  159. <dd>&nbsp; &nbsp; <a href="index.html#Reader.Size">func (r *Reader) Size() int64</a></dd>
  160. <dd>&nbsp; &nbsp; <a href="index.html#Reader.UnreadByte">func (r *Reader) UnreadByte() error</a></dd>
  161. <dd>&nbsp; &nbsp; <a href="index.html#Reader.UnreadRune">func (r *Reader) UnreadRune() error</a></dd>
  162. <dd>&nbsp; &nbsp; <a href="index.html#Reader.WriteTo">func (r *Reader) WriteTo(w io.Writer) (n int64, err error)</a></dd>
  163. <dd><a href="index.html#pkg-note-BUG">Bugs</a></dd>
  164. </dl>
  165. </div><!-- #manual-nav -->
  166. <div id="pkg-examples">
  167. <h4>Examples</h4>
  168. <dl>
  169. <dd><a class="exampleLink" href="index.html#example_Buffer">Buffer</a></dd>
  170. <dd><a class="exampleLink" href="index.html#example_Buffer_reader">Buffer (Reader)</a></dd>
  171. <dd><a class="exampleLink" href="index.html#example_Compare">Compare</a></dd>
  172. <dd><a class="exampleLink" href="index.html#example_Compare_search">Compare (Search)</a></dd>
  173. <dd><a class="exampleLink" href="index.html#example_TrimPrefix">TrimPrefix</a></dd>
  174. <dd><a class="exampleLink" href="index.html#example_TrimSuffix">TrimSuffix</a></dd>
  175. </dl>
  176. </div>
  177. <h4>Package files</h4>
  178. <p>
  179. <span style="font-size:90%">
  180. <a href="http://localhost:6060/src/bytes/buffer.go">buffer.go</a>
  181. <a href="http://localhost:6060/src/bytes/bytes.go">bytes.go</a>
  182. <a href="http://localhost:6060/src/bytes/bytes_decl.go">bytes_decl.go</a>
  183. <a href="http://localhost:6060/src/bytes/reader.go">reader.go</a>
  184. </span>
  185. </p>
  186. </div><!-- .expanded -->
  187. </div><!-- #pkg-index -->
  188. <div id="pkg-callgraph" class="toggle" style="display: none">
  189. <div class="collapsed">
  190. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  191. </div> <!-- .expanded -->
  192. <div class="expanded">
  193. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  194. <p>
  195. In the call graph viewer below, each node
  196. is a function belonging to this package
  197. and its children are the functions it
  198. calls&mdash;perhaps dynamically.
  199. </p>
  200. <p>
  201. The root nodes are the entry points of the
  202. package: functions that may be called from
  203. outside the package.
  204. There may be non-exported or anonymous
  205. functions among them if they are called
  206. dynamically from another package.
  207. </p>
  208. <p>
  209. Click a node to visit that function's source code.
  210. From there you can visit its callers by
  211. clicking its declaring <code>func</code>
  212. token.
  213. </p>
  214. <p>
  215. Functions may be omitted if they were
  216. determined to be unreachable in the
  217. particular programs or tests that were
  218. analyzed.
  219. </p>
  220. <!-- Zero means show all package entry points. -->
  221. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  222. </div>
  223. </div> <!-- #pkg-callgraph -->
  224. <h2 id="pkg-constants">Constants</h2>
  225. <pre>const <span id="MinRead">MinRead</span> = 512</pre>
  226. <p>
  227. MinRead is the minimum slice size passed to a Read call by
  228. Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond
  229. what is required to hold the contents of r, ReadFrom will not grow the
  230. underlying buffer.
  231. </p>
  232. <h2 id="pkg-variables">Variables</h2>
  233. <pre>var <span id="ErrTooLarge">ErrTooLarge</span> = <a href="../errors/index.html">errors</a>.<a href="../errors/index.html#New">New</a>(&#34;bytes.Buffer: too large&#34;)</pre>
  234. <p>
  235. ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.
  236. </p>
  237. <h2 id="Compare">func <a href="http://localhost:6060/src/bytes/bytes_decl.go?s=785:814#L14">Compare</a></h2>
  238. <pre>func Compare(a, b []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#int">int</a></pre>
  239. <p>
  240. Compare returns an integer comparing two byte slices lexicographically.
  241. The result will be 0 if a==b, -1 if a &lt; b, and +1 if a &gt; b.
  242. A nil argument is equivalent to an empty slice.
  243. </p>
  244. <div id="example_Compare" class="toggle">
  245. <div class="collapsed">
  246. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  247. </div>
  248. <div class="expanded">
  249. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  250. <p>Code:</p>
  251. <pre class="code">
  252. <span class="comment">// Interpret Compare&#39;s result by comparing it to zero.</span>
  253. var a, b []byte
  254. if bytes.Compare(a, b) &lt; 0 {
  255. <span class="comment">// a less b</span>
  256. }
  257. if bytes.Compare(a, b) &lt;= 0 {
  258. <span class="comment">// a less or equal b</span>
  259. }
  260. if bytes.Compare(a, b) &gt; 0 {
  261. <span class="comment">// a greater b</span>
  262. }
  263. if bytes.Compare(a, b) &gt;= 0 {
  264. <span class="comment">// a greater or equal b</span>
  265. }
  266. <span class="comment">// Prefer Equal to Compare for equality comparisons.</span>
  267. if bytes.Equal(a, b) {
  268. <span class="comment">// a equal b</span>
  269. }
  270. if !bytes.Equal(a, b) {
  271. <span class="comment">// a not equal b</span>
  272. }
  273. </pre>
  274. </div>
  275. </div>
  276. <div id="example_Compare_search" class="toggle">
  277. <div class="collapsed">
  278. <p class="exampleHeading toggleButton"><span class="text">Example (Search)</span></p>
  279. </div>
  280. <div class="expanded">
  281. <p class="exampleHeading toggleButton"><span class="text">Example (Search)</span></p>
  282. <p>Code:</p>
  283. <pre class="code">
  284. <span class="comment">// Binary search to find a matching byte slice.</span>
  285. var needle []byte
  286. var haystack [][]byte <span class="comment">// Assume sorted</span>
  287. i := sort.Search(len(haystack), func(i int) bool {
  288. <span class="comment">// Return haystack[i] &gt;= needle.</span>
  289. return bytes.Compare(haystack[i], needle) &gt;= 0
  290. })
  291. if i &lt; len(haystack) &amp;&amp; bytes.Equal(haystack[i], needle) {
  292. <span class="comment">// Found it!</span>
  293. }
  294. </pre>
  295. </div>
  296. </div>
  297. <h2 id="Contains">func <a href="http://localhost:6060/src/bytes/bytes.go?s=1583:1621#L72">Contains</a></h2>
  298. <pre>func Contains(b, subslice []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  299. <p>
  300. Contains reports whether subslice is within b.
  301. </p>
  302. <h2 id="Count">func <a href="http://localhost:6060/src/bytes/bytes.go?s=1147:1176#L41">Count</a></h2>
  303. <pre>func Count(s, sep []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#int">int</a></pre>
  304. <p>
  305. Count counts the number of non-overlapping instances of sep in s.
  306. If sep is an empty slice, Count returns 1 + the number of Unicode code points in s.
  307. </p>
  308. <h2 id="Equal">func <a href="http://localhost:6060/src/bytes/bytes_decl.go?s=523:551#L7">Equal</a></h2>
  309. <pre>func Equal(a, b []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  310. <p>
  311. Equal returns a boolean reporting whether a and b
  312. are the same length and contain the same bytes.
  313. A nil argument is equivalent to an empty slice.
  314. </p>
  315. <h2 id="EqualFold">func <a href="http://localhost:6060/src/bytes/bytes.go?s=17532:17564#L653">EqualFold</a></h2>
  316. <pre>func EqualFold(s, t []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  317. <p>
  318. EqualFold reports whether s and t, interpreted as UTF-8 strings,
  319. are equal under Unicode case-folding.
  320. </p>
  321. <h2 id="Fields">func <a href="http://localhost:6060/src/bytes/bytes.go?s=6593:6623#L263">Fields</a></h2>
  322. <pre>func Fields(s []<a href="../builtin/index.html#byte">byte</a>) [][]<a href="../builtin/index.html#byte">byte</a></pre>
  323. <p>
  324. Fields splits the slice s around each instance of one or more consecutive white space
  325. characters, returning a slice of subslices of s or an empty list if s contains only white space.
  326. </p>
  327. <h2 id="FieldsFunc">func <a href="http://localhost:6060/src/bytes/bytes.go?s=7099:7152#L273">FieldsFunc</a></h2>
  328. <pre>func FieldsFunc(s []<a href="../builtin/index.html#byte">byte</a>, f func(<a href="../builtin/index.html#rune">rune</a>) <a href="../builtin/index.html#bool">bool</a>) [][]<a href="../builtin/index.html#byte">byte</a></pre>
  329. <p>
  330. FieldsFunc interprets s as a sequence of UTF-8-encoded Unicode code points.
  331. It splits the slice s at each run of code points c satisfying f(c) and
  332. returns a slice of subslices of s. If all code points in s satisfy f(c), or
  333. len(s) == 0, an empty slice is returned.
  334. FieldsFunc makes no guarantees about the order in which it calls f(c).
  335. If f does not return consistent results for a given c, FieldsFunc may crash.
  336. </p>
  337. <h2 id="HasPrefix">func <a href="http://localhost:6060/src/bytes/bytes.go?s=8302:8339#L334">HasPrefix</a></h2>
  338. <pre>func HasPrefix(s, prefix []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  339. <p>
  340. HasPrefix tests whether the byte slice s begins with prefix.
  341. </p>
  342. <h2 id="HasSuffix">func <a href="http://localhost:6060/src/bytes/bytes.go?s=8472:8509#L339">HasSuffix</a></h2>
  343. <pre>func HasSuffix(s, suffix []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  344. <p>
  345. HasSuffix tests whether the byte slice s ends with suffix.
  346. </p>
  347. <h2 id="Index">func <a href="http://localhost:6060/src/bytes/bytes.go?s=1756:1785#L77">Index</a></h2>
  348. <pre>func Index(s, sep []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#int">int</a></pre>
  349. <p>
  350. Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
  351. </p>
  352. <h2 id="IndexAny">func <a href="http://localhost:6060/src/bytes/bytes.go?s=3402:3443#L159">IndexAny</a></h2>
  353. <pre>func IndexAny(s []<a href="../builtin/index.html#byte">byte</a>, chars <a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#int">int</a></pre>
  354. <p>
  355. IndexAny interprets s as a sequence of UTF-8-encoded Unicode code points.
  356. It returns the byte index of the first occurrence in s of any of the Unicode
  357. code points in chars. It returns -1 if chars is empty or if there is no code
  358. point in common.
  359. </p>
  360. <h2 id="IndexByte">func <a href="http://localhost:6060/src/bytes/bytes_decl.go?s=287:323#L1">IndexByte</a></h2>
  361. <pre>func IndexByte(s []<a href="../builtin/index.html#byte">byte</a>, c <a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#int">int</a></pre>
  362. <p>
  363. IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
  364. </p>
  365. <h2 id="IndexFunc">func <a href="http://localhost:6060/src/bytes/bytes.go?s=14025:14074#L514">IndexFunc</a></h2>
  366. <pre>func IndexFunc(s []<a href="../builtin/index.html#byte">byte</a>, f func(r <a href="../builtin/index.html#rune">rune</a>) <a href="../builtin/index.html#bool">bool</a>) <a href="../builtin/index.html#int">int</a></pre>
  367. <p>
  368. IndexFunc interprets s as a sequence of UTF-8-encoded Unicode code points.
  369. It returns the byte index in s of the first Unicode
  370. code point satisfying f(c), or -1 if none do.
  371. </p>
  372. <h2 id="IndexRune">func <a href="http://localhost:6060/src/bytes/bytes.go?s=2981:3017#L144">IndexRune</a></h2>
  373. <pre>func IndexRune(s []<a href="../builtin/index.html#byte">byte</a>, r <a href="../builtin/index.html#rune">rune</a>) <a href="../builtin/index.html#int">int</a></pre>
  374. <p>
  375. IndexRune interprets s as a sequence of UTF-8-encoded Unicode code points.
  376. It returns the byte index of the first occurrence in s of the given rune.
  377. It returns -1 if rune is not present in s.
  378. </p>
  379. <h2 id="Join">func <a href="http://localhost:6060/src/bytes/bytes.go?s=7865:7905#L311">Join</a></h2>
  380. <pre>func Join(s [][]<a href="../builtin/index.html#byte">byte</a>, sep []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  381. <p>
  382. Join concatenates the elements of s to create a new byte slice. The separator
  383. sep is placed between elements in the resulting slice.
  384. </p>
  385. <h2 id="LastIndex">func <a href="http://localhost:6060/src/bytes/bytes.go?s=2334:2367#L117">LastIndex</a></h2>
  386. <pre>func LastIndex(s, sep []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#int">int</a></pre>
  387. <p>
  388. LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.
  389. </p>
  390. <h2 id="LastIndexAny">func <a href="http://localhost:6060/src/bytes/bytes.go?s=4003:4048#L184">LastIndexAny</a></h2>
  391. <pre>func LastIndexAny(s []<a href="../builtin/index.html#byte">byte</a>, chars <a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#int">int</a></pre>
  392. <p>
  393. LastIndexAny interprets s as a sequence of UTF-8-encoded Unicode code
  394. points. It returns the byte index of the last occurrence in s of any of
  395. the Unicode code points in chars. It returns -1 if chars is empty or if
  396. there is no code point in common.
  397. </p>
  398. <h2 id="LastIndexByte">func <a href="http://localhost:6060/src/bytes/bytes.go?s=2651:2691#L132">LastIndexByte</a></h2>
  399. <pre>func LastIndexByte(s []<a href="../builtin/index.html#byte">byte</a>, c <a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#int">int</a></pre>
  400. <p>
  401. LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
  402. </p>
  403. <h2 id="LastIndexFunc">func <a href="http://localhost:6060/src/bytes/bytes.go?s=14295:14348#L521">LastIndexFunc</a></h2>
  404. <pre>func LastIndexFunc(s []<a href="../builtin/index.html#byte">byte</a>, f func(r <a href="../builtin/index.html#rune">rune</a>) <a href="../builtin/index.html#bool">bool</a>) <a href="../builtin/index.html#int">int</a></pre>
  405. <p>
  406. LastIndexFunc interprets s as a sequence of UTF-8-encoded Unicode code points.
  407. It returns the byte index in s of the last Unicode
  408. code point satisfying f(c), or -1 if none do.
  409. </p>
  410. <h2 id="Map">func <a href="http://localhost:6060/src/bytes/bytes.go?s=8894:8946#L347">Map</a></h2>
  411. <pre>func Map(mapping func(r <a href="../builtin/index.html#rune">rune</a>) <a href="../builtin/index.html#rune">rune</a>, s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  412. <p>
  413. Map returns a copy of the byte slice s with all its characters modified
  414. according to the mapping function. If mapping returns a negative value, the character is
  415. dropped from the string with no replacement. The characters in s and the
  416. output are interpreted as UTF-8-encoded Unicode code points.
  417. </p>
  418. <h2 id="Repeat">func <a href="http://localhost:6060/src/bytes/bytes.go?s=9819:9858#L381">Repeat</a></h2>
  419. <pre>func Repeat(b []<a href="../builtin/index.html#byte">byte</a>, count <a href="../builtin/index.html#int">int</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  420. <p>
  421. Repeat returns a new byte slice consisting of count copies of b.
  422. </p>
  423. <h2 id="Replace">func <a href="http://localhost:6060/src/bytes/bytes.go?s=16775:16821#L615">Replace</a></h2>
  424. <pre>func Replace(s, old, new []<a href="../builtin/index.html#byte">byte</a>, n <a href="../builtin/index.html#int">int</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  425. <p>
  426. Replace returns a copy of the slice s with the first n
  427. non-overlapping instances of old replaced by new.
  428. If old is empty, it matches at the beginning of the slice
  429. and after each UTF-8 sequence, yielding up to k+1 replacements
  430. for a k-rune slice.
  431. If n &lt; 0, there is no limit on the number of replacements.
  432. </p>
  433. <h2 id="Runes">func <a href="http://localhost:6060/src/bytes/bytes.go?s=16284:16311#L597">Runes</a></h2>
  434. <pre>func Runes(s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#rune">rune</a></pre>
  435. <p>
  436. Runes returns a slice of runes (Unicode code points) equivalent to s.
  437. </p>
  438. <h2 id="Split">func <a href="http://localhost:6060/src/bytes/bytes.go?s=6017:6051#L251">Split</a></h2>
  439. <pre>func Split(s, sep []<a href="../builtin/index.html#byte">byte</a>) [][]<a href="../builtin/index.html#byte">byte</a></pre>
  440. <p>
  441. Split slices s into all subslices separated by sep and returns a slice of
  442. the subslices between those separators.
  443. If sep is empty, Split splits after each UTF-8 sequence.
  444. It is equivalent to SplitN with a count of -1.
  445. </p>
  446. <h2 id="SplitAfter">func <a href="http://localhost:6060/src/bytes/bytes.go?s=6320:6359#L257">SplitAfter</a></h2>
  447. <pre>func SplitAfter(s, sep []<a href="../builtin/index.html#byte">byte</a>) [][]<a href="../builtin/index.html#byte">byte</a></pre>
  448. <p>
  449. SplitAfter slices s into all subslices after each instance of sep and
  450. returns a slice of those subslices.
  451. If sep is empty, SplitAfter splits after each UTF-8 sequence.
  452. It is equivalent to SplitAfterN with a count of -1.
  453. </p>
  454. <h2 id="SplitAfterN">func <a href="http://localhost:6060/src/bytes/bytes.go?s=5696:5743#L243">SplitAfterN</a></h2>
  455. <pre>func SplitAfterN(s, sep []<a href="../builtin/index.html#byte">byte</a>, n <a href="../builtin/index.html#int">int</a>) [][]<a href="../builtin/index.html#byte">byte</a></pre>
  456. <p>
  457. SplitAfterN slices s into subslices after each instance of sep and
  458. returns a slice of those subslices.
  459. If sep is empty, SplitAfterN splits after each UTF-8 sequence.
  460. The count determines the number of subslices to return:
  461. </p>
  462. <pre>n &gt; 0: at most n subslices; the last subslice will be the unsplit remainder.
  463. n == 0: the result is nil (zero subslices)
  464. n &lt; 0: all subslices
  465. </pre>
  466. <h2 id="SplitN">func <a href="http://localhost:6060/src/bytes/bytes.go?s=5228:5270#L234">SplitN</a></h2>
  467. <pre>func SplitN(s, sep []<a href="../builtin/index.html#byte">byte</a>, n <a href="../builtin/index.html#int">int</a>) [][]<a href="../builtin/index.html#byte">byte</a></pre>
  468. <p>
  469. SplitN slices s into subslices separated by sep and returns a slice of
  470. the subslices between those separators.
  471. If sep is empty, SplitN splits after each UTF-8 sequence.
  472. The count determines the number of subslices to return:
  473. </p>
  474. <pre>n &gt; 0: at most n subslices; the last subslice will be the unsplit remainder.
  475. n == 0: the result is nil (zero subslices)
  476. n &lt; 0: all subslices
  477. </pre>
  478. <h2 id="Title">func <a href="http://localhost:6060/src/bytes/bytes.go?s=12190:12217#L447">Title</a></h2>
  479. <pre>func Title(s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  480. <p>
  481. Title returns a copy of s with all Unicode letters that begin words
  482. mapped to their title case.
  483. </p>
  484. <p>
  485. BUG(rsc): The rule Title uses for word boundaries does not handle Unicode punctuation properly.
  486. </p>
  487. <h2 id="ToLower">func <a href="http://localhost:6060/src/bytes/bytes.go?s=10250:10279#L395">ToLower</a></h2>
  488. <pre>func ToLower(s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  489. <p>
  490. ToLower returns a copy of the byte slice s with all Unicode letters mapped to their lower case.
  491. </p>
  492. <h2 id="ToLowerSpecial">func <a href="http://localhost:6060/src/bytes/bytes.go?s=10920:10983#L408">ToLowerSpecial</a></h2>
  493. <pre>func ToLowerSpecial(_case <a href="../unicode/index.html">unicode</a>.<a href="../unicode/index.html#SpecialCase">SpecialCase</a>, s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  494. <p>
  495. ToLowerSpecial returns a copy of the byte slice s with all Unicode letters mapped to their
  496. lower case, giving priority to the special casing rules.
  497. </p>
  498. <h2 id="ToTitle">func <a href="http://localhost:6060/src/bytes/bytes.go?s=10415:10444#L398">ToTitle</a></h2>
  499. <pre>func ToTitle(s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  500. <p>
  501. ToTitle returns a copy of the byte slice s with all Unicode letters mapped to their title case.
  502. </p>
  503. <h2 id="ToTitleSpecial">func <a href="http://localhost:6060/src/bytes/bytes.go?s=11205:11268#L414">ToTitleSpecial</a></h2>
  504. <pre>func ToTitleSpecial(_case <a href="../unicode/index.html">unicode</a>.<a href="../unicode/index.html#SpecialCase">SpecialCase</a>, s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  505. <p>
  506. ToTitleSpecial returns a copy of the byte slice s with all Unicode letters mapped to their
  507. title case, giving priority to the special casing rules.
  508. </p>
  509. <h2 id="ToUpper">func <a href="http://localhost:6060/src/bytes/bytes.go?s=10085:10114#L392">ToUpper</a></h2>
  510. <pre>func ToUpper(s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  511. <p>
  512. ToUpper returns a copy of the byte slice s with all Unicode letters mapped to their upper case.
  513. </p>
  514. <h2 id="ToUpperSpecial">func <a href="http://localhost:6060/src/bytes/bytes.go?s=10635:10698#L402">ToUpperSpecial</a></h2>
  515. <pre>func ToUpperSpecial(_case <a href="../unicode/index.html">unicode</a>.<a href="../unicode/index.html#SpecialCase">SpecialCase</a>, s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  516. <p>
  517. ToUpperSpecial returns a copy of the byte slice s with all Unicode letters mapped to their
  518. upper case, giving priority to the special casing rules.
  519. </p>
  520. <h2 id="Trim">func <a href="http://localhost:6060/src/bytes/bytes.go?s=15477:15518#L574">Trim</a></h2>
  521. <pre>func Trim(s []<a href="../builtin/index.html#byte">byte</a>, cutset <a href="../builtin/index.html#string">string</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  522. <p>
  523. Trim returns a subslice of s by slicing off all leading and
  524. trailing UTF-8-encoded Unicode code points contained in cutset.
  525. </p>
  526. <h2 id="TrimFunc">func <a href="http://localhost:6060/src/bytes/bytes.go?s=13257:13308#L489">TrimFunc</a></h2>
  527. <pre>func TrimFunc(s []<a href="../builtin/index.html#byte">byte</a>, f func(r <a href="../builtin/index.html#rune">rune</a>) <a href="../builtin/index.html#bool">bool</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  528. <p>
  529. TrimFunc returns a subslice of s by slicing off all leading and trailing
  530. UTF-8-encoded Unicode code points c that satisfy f(c).
  531. </p>
  532. <h2 id="TrimLeft">func <a href="http://localhost:6060/src/bytes/bytes.go?s=15689:15734#L580">TrimLeft</a></h2>
  533. <pre>func TrimLeft(s []<a href="../builtin/index.html#byte">byte</a>, cutset <a href="../builtin/index.html#string">string</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  534. <p>
  535. TrimLeft returns a subslice of s by slicing off all leading
  536. UTF-8-encoded Unicode code points contained in cutset.
  537. </p>
  538. <h2 id="TrimLeftFunc">func <a href="http://localhost:6060/src/bytes/bytes.go?s=12649:12704#L466">TrimLeftFunc</a></h2>
  539. <pre>func TrimLeftFunc(s []<a href="../builtin/index.html#byte">byte</a>, f func(r <a href="../builtin/index.html#rune">rune</a>) <a href="../builtin/index.html#bool">bool</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  540. <p>
  541. TrimLeftFunc returns a subslice of s by slicing off all leading UTF-8-encoded
  542. Unicode code points c that satisfy f(c).
  543. </p>
  544. <h2 id="TrimPrefix">func <a href="http://localhost:6060/src/bytes/bytes.go?s=13487:13527#L495">TrimPrefix</a></h2>
  545. <pre>func TrimPrefix(s, prefix []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  546. <p>
  547. TrimPrefix returns s without the provided leading prefix string.
  548. If s doesn&#39;t start with prefix, s is returned unchanged.
  549. </p>
  550. <div id="example_TrimPrefix" class="toggle">
  551. <div class="collapsed">
  552. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  553. </div>
  554. <div class="expanded">
  555. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  556. <p>Code:</p>
  557. <pre class="code">var b = []byte(&#34;Goodbye,, world!&#34;)
  558. b = bytes.TrimPrefix(b, []byte(&#34;Goodbye,&#34;))
  559. b = bytes.TrimPrefix(b, []byte(&#34;See ya,&#34;))
  560. fmt.Printf(&#34;Hello%s&#34;, b)
  561. <span class="comment"></pre>
  562. <p>Output:</p>
  563. <pre class="output">Hello, world!
  564. </pre>
  565. </div>
  566. </div>
  567. <h2 id="TrimRight">func <a href="http://localhost:6060/src/bytes/bytes.go?s=15920:15966#L586">TrimRight</a></h2>
  568. <pre>func TrimRight(s []<a href="../builtin/index.html#byte">byte</a>, cutset <a href="../builtin/index.html#string">string</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  569. <p>
  570. TrimRight returns a subslice of s by slicing off all trailing
  571. UTF-8-encoded Unicode code points that are contained in cutset.
  572. </p>
  573. <h2 id="TrimRightFunc">func <a href="http://localhost:6060/src/bytes/bytes.go?s=12910:12966#L476">TrimRightFunc</a></h2>
  574. <pre>func TrimRightFunc(s []<a href="../builtin/index.html#byte">byte</a>, f func(r <a href="../builtin/index.html#rune">rune</a>) <a href="../builtin/index.html#bool">bool</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  575. <p>
  576. TrimRightFunc returns a subslice of s by slicing off all trailing UTF-8
  577. encoded Unicode code points c that satisfy f(c).
  578. </p>
  579. <h2 id="TrimSpace">func <a href="http://localhost:6060/src/bytes/bytes.go?s=16137:16168#L592">TrimSpace</a></h2>
  580. <pre>func TrimSpace(s []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  581. <p>
  582. TrimSpace returns a subslice of s by slicing off all leading and
  583. trailing white space, as defined by Unicode.
  584. </p>
  585. <h2 id="TrimSuffix">func <a href="http://localhost:6060/src/bytes/bytes.go?s=13725:13765#L504">TrimSuffix</a></h2>
  586. <pre>func TrimSuffix(s, suffix []<a href="../builtin/index.html#byte">byte</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  587. <p>
  588. TrimSuffix returns s without the provided trailing suffix string.
  589. If s doesn&#39;t end with suffix, s is returned unchanged.
  590. </p>
  591. <div id="example_TrimSuffix" class="toggle">
  592. <div class="collapsed">
  593. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  594. </div>
  595. <div class="expanded">
  596. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  597. <p>Code:</p>
  598. <pre class="code">var b = []byte(&#34;Hello, goodbye, etc!&#34;)
  599. b = bytes.TrimSuffix(b, []byte(&#34;goodbye, etc!&#34;))
  600. b = bytes.TrimSuffix(b, []byte(&#34;gopher&#34;))
  601. b = append(b, bytes.TrimSuffix([]byte(&#34;world!&#34;), []byte(&#34;x!&#34;))...)
  602. os.Stdout.Write(b)
  603. <span class="comment"></pre>
  604. <p>Output:</p>
  605. <pre class="output">Hello, world!
  606. </pre>
  607. </div>
  608. </div>
  609. <h2 id="Buffer">type <a href="http://localhost:6060/src/bytes/buffer.go?s=402:854#L7">Buffer</a></h2>
  610. <pre>type Buffer struct {
  611. <span class="comment">// contains filtered or unexported fields</span>
  612. }</pre>
  613. <p>
  614. A Buffer is a variable-sized buffer of bytes with Read and Write methods.
  615. The zero value for Buffer is an empty buffer ready to use.
  616. </p>
  617. <div id="example_Buffer" class="toggle">
  618. <div class="collapsed">
  619. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  620. </div>
  621. <div class="expanded">
  622. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  623. <p>Code:</p>
  624. <pre class="code">var b bytes.Buffer <span class="comment">// A Buffer needs no initialization.</span>
  625. b.Write([]byte(&#34;Hello &#34;))
  626. fmt.Fprintf(&amp;b, &#34;world!&#34;)
  627. b.WriteTo(os.Stdout)
  628. <span class="comment"></pre>
  629. <p>Output:</p>
  630. <pre class="output">Hello world!
  631. </pre>
  632. </div>
  633. </div>
  634. <div id="example_Buffer_reader" class="toggle">
  635. <div class="collapsed">
  636. <p class="exampleHeading toggleButton"><span class="text">Example (Reader)</span></p>
  637. </div>
  638. <div class="expanded">
  639. <p class="exampleHeading toggleButton"><span class="text">Example (Reader)</span></p>
  640. <p>Code:</p>
  641. <pre class="code"><span class="comment">// A Buffer can turn a string or a []byte into an io.Reader.</span>
  642. buf := bytes.NewBufferString(&#34;R29waGVycyBydWxlIQ==&#34;)
  643. dec := base64.NewDecoder(base64.StdEncoding, buf)
  644. io.Copy(os.Stdout, dec)
  645. <span class="comment"></pre>
  646. <p>Output:</p>
  647. <pre class="output">Gophers rule!
  648. </pre>
  649. </div>
  650. </div>
  651. <h3 id="NewBuffer">func <a href="http://localhost:6060/src/bytes/buffer.go?s=13137:13171#L399">NewBuffer</a></h3>
  652. <pre>func NewBuffer(buf []<a href="../builtin/index.html#byte">byte</a>) *<a href="index.html#Buffer">Buffer</a></pre>
  653. <p>
  654. NewBuffer creates and initializes a new Buffer using buf as its initial
  655. contents. It is intended to prepare a Buffer to read existing data. It
  656. can also be used to size the internal buffer for writing. To do that,
  657. buf should have the desired capacity but a length of zero.
  658. </p>
  659. <p>
  660. In most cases, new(Buffer) (or just declaring a Buffer variable) is
  661. sufficient to initialize a Buffer.
  662. </p>
  663. <h3 id="NewBufferString">func <a href="http://localhost:6060/src/bytes/buffer.go?s=13479:13517#L407">NewBufferString</a></h3>
  664. <pre>func NewBufferString(s <a href="../builtin/index.html#string">string</a>) *<a href="index.html#Buffer">Buffer</a></pre>
  665. <p>
  666. NewBufferString creates and initializes a new Buffer using string s as its
  667. initial contents. It is intended to prepare a buffer to read an existing
  668. string.
  669. </p>
  670. <p>
  671. In most cases, new(Buffer) (or just declaring a Buffer variable) is
  672. sufficient to initialize a Buffer.
  673. </p>
  674. <h3 id="Buffer.Bytes">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=1725:1756#L34">Bytes</a></h3>
  675. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Bytes() []<a href="../builtin/index.html#byte">byte</a></pre>
  676. <p>
  677. Bytes returns a slice of length b.Len() holding the unread portion of the buffer.
  678. The slice is valid for use only until the next buffer modification (that is,
  679. only until the next call to a method like Read, Write, Reset, or Truncate).
  680. The slice aliases the buffer content at least until the next buffer modification,
  681. so immediate changes to the slice will affect the result of future reads.
  682. </p>
  683. <h3 id="Buffer.Cap">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=2350:2376#L52">Cap</a></h3>
  684. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Cap() <a href="../builtin/index.html#int">int</a></pre>
  685. <p>
  686. Cap returns the capacity of the buffer&#39;s underlying byte slice, that is, the
  687. total space allocated for the buffer&#39;s data.
  688. </p>
  689. <h3 id="Buffer.Grow">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=4226:4254#L111">Grow</a></h3>
  690. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Grow(n <a href="../builtin/index.html#int">int</a>)</pre>
  691. <p>
  692. Grow grows the buffer&#39;s capacity, if necessary, to guarantee space for
  693. another n bytes. After Grow(n), at least n bytes can be written to the
  694. buffer without another allocation.
  695. If n is negative, Grow will panic.
  696. If the buffer can&#39;t grow it will panic with ErrTooLarge.
  697. </p>
  698. <h3 id="Buffer.Len">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=2164:2190#L48">Len</a></h3>
  699. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Len() <a href="../builtin/index.html#int">int</a></pre>
  700. <p>
  701. Len returns the number of bytes of the unread portion of the buffer;
  702. b.Len() == len(b.Bytes()).
  703. </p>
  704. <h3 id="Buffer.Next">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=9122:9157#L270">Next</a></h3>
  705. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Next(n <a href="../builtin/index.html#int">int</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  706. <p>
  707. Next returns a slice containing the next n bytes from the buffer,
  708. advancing the buffer as if the bytes had been returned by Read.
  709. If there are fewer than n bytes in the buffer, Next returns the entire buffer.
  710. The slice is only valid until the next call to a read or write method.
  711. </p>
  712. <h3 id="Buffer.Read">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=8522:8572#L248">Read</a></h3>
  713. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Read(p []<a href="../builtin/index.html#byte">byte</a>) (n <a href="../builtin/index.html#int">int</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  714. <p>
  715. Read reads the next len(p) bytes from the buffer or until the buffer
  716. is drained. The return value n is the number of bytes read. If the
  717. buffer has no data to return, err is io.EOF (unless len(p) is zero);
  718. otherwise it is nil.
  719. </p>
  720. <h3 id="Buffer.ReadByte">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=9432:9479#L286">ReadByte</a></h3>
  721. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) ReadByte() (c <a href="../builtin/index.html#byte">byte</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  722. <p>
  723. ReadByte reads and returns the next byte from the buffer.
  724. If no byte is available, it returns error io.EOF.
  725. </p>
  726. <h3 id="Buffer.ReadBytes">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=11651:11714#L359">ReadBytes</a></h3>
  727. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) ReadBytes(delim <a href="../builtin/index.html#byte">byte</a>) (line []<a href="../builtin/index.html#byte">byte</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  728. <p>
  729. ReadBytes reads until the first occurrence of delim in the input,
  730. returning a slice containing the data up to and including the delimiter.
  731. If ReadBytes encounters an error before finding a delimiter,
  732. it returns the data read before the error and the error itself (often io.EOF).
  733. ReadBytes returns err != nil if and only if the returned data does not end in
  734. delim.
  735. </p>
  736. <h3 id="Buffer.ReadFrom">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=5620:5679#L147">ReadFrom</a></h3>
  737. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) ReadFrom(r <a href="../io/index.html">io</a>.<a href="../io/index.html#Reader">Reader</a>) (n <a href="../builtin/index.html#int64">int64</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  738. <p>
  739. ReadFrom reads data from r until EOF and appends it to the buffer, growing
  740. the buffer as needed. The return value n is the number of bytes read. Any
  741. error except io.EOF encountered during the read is also returned. If the
  742. buffer becomes too large, ReadFrom will panic with ErrTooLarge.
  743. </p>
  744. <h3 id="Buffer.ReadRune">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=9930:9987#L304">ReadRune</a></h3>
  745. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) ReadRune() (r <a href="../builtin/index.html#rune">rune</a>, size <a href="../builtin/index.html#int">int</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  746. <p>
  747. ReadRune reads and returns the next UTF-8-encoded
  748. Unicode code point from the buffer.
  749. If no bytes are available, the error returned is io.EOF.
  750. If the bytes are an erroneous UTF-8 encoding, it
  751. consumes one byte and returns U+FFFD, 1.
  752. </p>
  753. <h3 id="Buffer.ReadString">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=12608:12672#L387">ReadString</a></h3>
  754. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) ReadString(delim <a href="../builtin/index.html#byte">byte</a>) (line <a href="../builtin/index.html#string">string</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  755. <p>
  756. ReadString reads until the first occurrence of delim in the input,
  757. returning a string containing the data up to and including the delimiter.
  758. If ReadString encounters an error before finding a delimiter,
  759. it returns the data read before the error and the error itself (often io.EOF).
  760. ReadString returns err != nil if and only if the returned data does not end
  761. in delim.
  762. </p>
  763. <h3 id="Buffer.Reset">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=2969:2993#L72">Reset</a></h3>
  764. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Reset()</pre>
  765. <p>
  766. Reset resets the buffer to be empty,
  767. but it retains the underlying storage for use by future writes.
  768. Reset is the same as Truncate(0).
  769. </p>
  770. <h3 id="Buffer.String">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=1919:1951#L38">String</a></h3>
  771. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) String() <a href="../builtin/index.html#string">string</a></pre>
  772. <p>
  773. String returns the contents of the unread portion of the buffer
  774. as a string. If the Buffer is a nil pointer, it returns &#34;&lt;nil&gt;&#34;.
  775. </p>
  776. <h3 id="Buffer.Truncate">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=2594:2626#L57">Truncate</a></h3>
  777. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Truncate(n <a href="../builtin/index.html#int">int</a>)</pre>
  778. <p>
  779. Truncate discards all but the first n unread bytes from the buffer
  780. but continues to use the same allocated storage.
  781. It panics if n is negative or greater than the length of the buffer.
  782. </p>
  783. <h3 id="Buffer.UnreadByte">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=11022:11057#L342">UnreadByte</a></h3>
  784. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) UnreadByte() <a href="../builtin/index.html#error">error</a></pre>
  785. <p>
  786. UnreadByte unreads the last byte returned by the most recent
  787. read operation. If write has happened since the last read, UnreadByte
  788. returns an error.
  789. </p>
  790. <h3 id="Buffer.UnreadRune">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=10589:10624#L327">UnreadRune</a></h3>
  791. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) UnreadRune() <a href="../builtin/index.html#error">error</a></pre>
  792. <p>
  793. UnreadRune unreads the last rune returned by ReadRune.
  794. If the most recent read or write operation on the buffer was
  795. not a ReadRune, UnreadRune returns an error. (In this regard
  796. it is stricter than UnreadByte, which will unread the last byte
  797. from any read operation.)
  798. </p>
  799. <h3 id="Buffer.Write">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=4568:4619#L122">Write</a></h3>
  800. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) Write(p []<a href="../builtin/index.html#byte">byte</a>) (n <a href="../builtin/index.html#int">int</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  801. <p>
  802. Write appends the contents of p to the buffer, growing the buffer as
  803. needed. The return value n is the length of p; err is always nil. If the
  804. buffer becomes too large, Write will panic with ErrTooLarge.
  805. </p>
  806. <h3 id="Buffer.WriteByte">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=7673:7713#L223">WriteByte</a></h3>
  807. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) WriteByte(c <a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#error">error</a></pre>
  808. <p>
  809. WriteByte appends the byte c to the buffer, growing the buffer as needed.
  810. The returned error is always nil, but is included to match bufio.Writer&#39;s
  811. WriteByte. If the buffer becomes too large, WriteByte will panic with
  812. ErrTooLarge.
  813. </p>
  814. <h3 id="Buffer.WriteRune">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=8074:8127#L234">WriteRune</a></h3>
  815. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) WriteRune(r <a href="../builtin/index.html#rune">rune</a>) (n <a href="../builtin/index.html#int">int</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  816. <p>
  817. WriteRune appends the UTF-8 encoding of Unicode code point r to the
  818. buffer, returning its length and an error, which is always nil but is
  819. included to match bufio.Writer&#39;s WriteRune. The buffer is grown as needed;
  820. if it becomes too large, WriteRune will panic with ErrTooLarge.
  821. </p>
  822. <h3 id="Buffer.WriteString">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=4926:4983#L131">WriteString</a></h3>
  823. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) WriteString(s <a href="../builtin/index.html#string">string</a>) (n <a href="../builtin/index.html#int">int</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  824. <p>
  825. WriteString appends the contents of s to the buffer, growing the buffer as
  826. needed. The return value n is the length of s; err is always nil. If the
  827. buffer becomes too large, WriteString will panic with ErrTooLarge.
  828. </p>
  829. <h3 id="Buffer.WriteTo">func (*Buffer) <a href="http://localhost:6060/src/bytes/buffer.go?s=6925:6983#L195">WriteTo</a></h3>
  830. <pre>func (b *<a href="index.html#Buffer">Buffer</a>) WriteTo(w <a href="../io/index.html">io</a>.<a href="../io/index.html#Writer">Writer</a>) (n <a href="../builtin/index.html#int64">int64</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  831. <p>
  832. WriteTo writes data to w until the buffer is drained or an error occurs.
  833. The return value n is the number of bytes written; it always fits into an
  834. int, but it is int64 to match the io.WriterTo interface. Any error
  835. encountered during the write is also returned.
  836. </p>
  837. <h2 id="Reader">type <a href="http://localhost:6060/src/bytes/reader.go?s=440:570#L7">Reader</a></h2>
  838. <pre>type Reader struct {
  839. <span class="comment">// contains filtered or unexported fields</span>
  840. }</pre>
  841. <p>
  842. A Reader implements the io.Reader, io.ReaderAt, io.WriterTo, io.Seeker,
  843. io.ByteScanner, and io.RuneScanner interfaces by reading from
  844. a byte slice.
  845. Unlike a Buffer, a Reader is read-only and supports seeking.
  846. </p>
  847. <h3 id="NewReader">func <a href="http://localhost:6060/src/bytes/reader.go?s=3260:3292#L140">NewReader</a></h3>
  848. <pre>func NewReader(b []<a href="../builtin/index.html#byte">byte</a>) *<a href="index.html#Reader">Reader</a></pre>
  849. <p>
  850. NewReader returns a new Reader reading from b.
  851. </p>
  852. <h3 id="Reader.Len">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=646:672#L15">Len</a></h3>
  853. <pre>func (r *<a href="index.html#Reader">Reader</a>) Len() <a href="../builtin/index.html#int">int</a></pre>
  854. <p>
  855. Len returns the number of bytes of the unread portion of the
  856. slice.
  857. </p>
  858. <h3 id="Reader.Read">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=1039:1089#L28">Read</a></h3>
  859. <pre>func (r *<a href="index.html#Reader">Reader</a>) Read(b []<a href="../builtin/index.html#byte">byte</a>) (n <a href="../builtin/index.html#int">int</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  860. <h3 id="Reader.ReadAt">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=1249:1312#L41">ReadAt</a></h3>
  861. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadAt(b []<a href="../builtin/index.html#byte">byte</a>, off <a href="../builtin/index.html#int64">int64</a>) (n <a href="../builtin/index.html#int">int</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  862. <h3 id="Reader.ReadByte">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=1558:1605#L56">ReadByte</a></h3>
  863. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadByte() (b <a href="../builtin/index.html#byte">byte</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  864. <h3 id="Reader.ReadRune">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=1873:1931#L75">ReadRune</a></h3>
  865. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadRune() (ch <a href="../builtin/index.html#rune">rune</a>, size <a href="../builtin/index.html#int">int</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  866. <h3 id="Reader.Seek">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=2421:2483#L100">Seek</a></h3>
  867. <pre>func (r *<a href="index.html#Reader">Reader</a>) Seek(offset <a href="../builtin/index.html#int64">int64</a>, whence <a href="../builtin/index.html#int">int</a>) (<a href="../builtin/index.html#int64">int64</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  868. <p>
  869. Seek implements the io.Seeker interface.
  870. </p>
  871. <h3 id="Reader.Size">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=981:1010#L26">Size</a></h3>
  872. <pre>func (r *<a href="index.html#Reader">Reader</a>) Size() <a href="../builtin/index.html#int64">int64</a></pre>
  873. <p>
  874. Size returns the original length of the underlying byte slice.
  875. Size is the number of bytes available for reading via ReadAt.
  876. The returned value is always the same and is not affected by calls
  877. to any other method.
  878. </p>
  879. <h3 id="Reader.UnreadByte">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=1708:1743#L66">UnreadByte</a></h3>
  880. <pre>func (r *<a href="index.html#Reader">Reader</a>) UnreadByte() <a href="../builtin/index.html#error">error</a></pre>
  881. <h3 id="Reader.UnreadRune">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=2174:2209#L90">UnreadRune</a></h3>
  882. <pre>func (r *<a href="index.html#Reader">Reader</a>) UnreadRune() <a href="../builtin/index.html#error">error</a></pre>
  883. <h3 id="Reader.WriteTo">func (*Reader) <a href="http://localhost:6060/src/bytes/reader.go?s=2871:2929#L121">WriteTo</a></h3>
  884. <pre>func (r *<a href="index.html#Reader">Reader</a>) WriteTo(w <a href="../io/index.html">io</a>.<a href="../io/index.html#Writer">Writer</a>) (n <a href="../builtin/index.html#int64">int64</a>, err <a href="../builtin/index.html#error">error</a>)</pre>
  885. <p>
  886. WriteTo implements the io.WriterTo interface.
  887. </p>
  888. <h2 id="pkg-note-BUG">Bugs</h2>
  889. <ul style="list-style: none; padding: 0;">
  890. <li><a href="http://localhost:6060/src/bytes/bytes.go?s=12091:12189#L446">&#x261e;</a> The rule Title uses for word boundaries does not handle Unicode punctuation properly.
  891. </li>
  892. </ul>
  893. <div id="footer">
  894. Build version go1.6.<br>
  895. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  896. the content of this page is licensed under the
  897. Creative Commons Attribution 3.0 License,
  898. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  899. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  900. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  901. </div>
  902. </div><!-- .container -->
  903. </div><!-- #page -->
  904. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  905. <script type="text/javascript" src="../../lib/godoc/jquery.js"></script>
  906. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.js"></script>
  907. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.edit.js"></script>
  908. <script type="text/javascript" src="../../lib/godoc/godocs.js"></script>
  909. </body>
  910. </html>