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.

549 lines
17 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>runes - 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 runes</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 "golang.org/x/text/runes"</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 runes provide transforms for UTF-8 encoded text.
  69. </p>
  70. </div>
  71. </div>
  72. <div id="pkg-index" class="toggleVisible">
  73. <div class="collapsed">
  74. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  75. </div>
  76. <div class="expanded">
  77. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  78. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  79. <div id="manual-nav">
  80. <dl>
  81. <dd><a href="index.html#Set">type Set</a></dd>
  82. <dd>&nbsp; &nbsp; <a href="index.html#In">func In(rt *unicode.RangeTable) Set</a></dd>
  83. <dd>&nbsp; &nbsp; <a href="index.html#NotIn">func NotIn(rt *unicode.RangeTable) Set</a></dd>
  84. <dd>&nbsp; &nbsp; <a href="index.html#Predicate">func Predicate(f func(rune) bool) Set</a></dd>
  85. <dd><a href="index.html#Transformer">type Transformer</a></dd>
  86. <dd>&nbsp; &nbsp; <a href="index.html#If">func If(s Set, tIn, tNotIn transform.Transformer) Transformer</a></dd>
  87. <dd>&nbsp; &nbsp; <a href="index.html#Map">func Map(mapping func(rune) rune) Transformer</a></dd>
  88. <dd>&nbsp; &nbsp; <a href="index.html#Remove">func Remove(s Set) Transformer</a></dd>
  89. <dd>&nbsp; &nbsp; <a href="index.html#ReplaceIllFormed">func ReplaceIllFormed() Transformer</a></dd>
  90. <dd>&nbsp; &nbsp; <a href="index.html#Transformer.Bytes">func (t Transformer) Bytes(b []byte) []byte</a></dd>
  91. <dd>&nbsp; &nbsp; <a href="index.html#Transformer.Reset">func (t Transformer) Reset()</a></dd>
  92. <dd>&nbsp; &nbsp; <a href="index.html#Transformer.Span">func (t Transformer) Span(b []byte, atEOF bool) (n int, err error)</a></dd>
  93. <dd>&nbsp; &nbsp; <a href="index.html#Transformer.String">func (t Transformer) String(s string) string</a></dd>
  94. <dd>&nbsp; &nbsp; <a href="index.html#Transformer.Transform">func (t Transformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)</a></dd>
  95. </dl>
  96. </div><!-- #manual-nav -->
  97. <div id="pkg-examples">
  98. <h4>Examples</h4>
  99. <dl>
  100. <dd><a class="exampleLink" href="index.html#example_If">If</a></dd>
  101. <dd><a class="exampleLink" href="index.html#example_In">In</a></dd>
  102. <dd><a class="exampleLink" href="index.html#example_Map">Map</a></dd>
  103. <dd><a class="exampleLink" href="index.html#example_Remove">Remove</a></dd>
  104. </dl>
  105. </div>
  106. <h4>Package files</h4>
  107. <p>
  108. <span style="font-size:90%">
  109. <a href="http://localhost:6060/src/golang.org/x/text/runes/cond.go">cond.go</a>
  110. <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go">runes.go</a>
  111. </span>
  112. </p>
  113. </div><!-- .expanded -->
  114. </div><!-- #pkg-index -->
  115. <div id="pkg-callgraph" class="toggle" style="display: none">
  116. <div class="collapsed">
  117. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  118. </div> <!-- .expanded -->
  119. <div class="expanded">
  120. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  121. <p>
  122. In the call graph viewer below, each node
  123. is a function belonging to this package
  124. and its children are the functions it
  125. calls&mdash;perhaps dynamically.
  126. </p>
  127. <p>
  128. The root nodes are the entry points of the
  129. package: functions that may be called from
  130. outside the package.
  131. There may be non-exported or anonymous
  132. functions among them if they are called
  133. dynamically from another package.
  134. </p>
  135. <p>
  136. Click a node to visit that function's source code.
  137. From there you can visit its callers by
  138. clicking its declaring <code>func</code>
  139. token.
  140. </p>
  141. <p>
  142. Functions may be omitted if they were
  143. determined to be unreachable in the
  144. particular programs or tests that were
  145. analyzed.
  146. </p>
  147. <!-- Zero means show all package entry points. -->
  148. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  149. </div>
  150. </div> <!-- #pkg-callgraph -->
  151. <h2 id="Set">type <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=377:478#L6">Set</a></h2>
  152. <pre>type Set interface {
  153. <span class="comment">// Contains returns true if r is contained in the set.</span>
  154. Contains(r <a href="../../../../builtin/index.html#rune">rune</a>) <a href="../../../../builtin/index.html#bool">bool</a>
  155. }</pre>
  156. <p>
  157. A Set is a collection of runes.
  158. </p>
  159. <h3 id="In">func <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=777:812#L22">In</a></h3>
  160. <pre>func In(rt *<a href="../../../../unicode/index.html">unicode</a>.<a href="../../../../unicode/index.html#RangeTable">RangeTable</a>) <a href="index.html#Set">Set</a></pre>
  161. <p>
  162. In creates a Set with a Contains method that returns true for all runes in
  163. the given RangeTable.
  164. </p>
  165. <div id="example_In" class="toggle">
  166. <div class="collapsed">
  167. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  168. </div>
  169. <div class="expanded">
  170. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  171. <p>Code:</p>
  172. <pre class="code"><span class="comment">// Convert Latin characters to their canonical form, while keeping other</span>
  173. <span class="comment">// width distinctions.</span>
  174. t := runes.If(runes.In(unicode.Latin), width.Fold, nil)
  175. s, _, _ := transform.String(t, &#34;アルアノリウ tech / アルアノリウ tech&#34;)
  176. fmt.Println(s)
  177. <span class="comment"></pre>
  178. <p>Output:</p>
  179. <pre class="output">アルアノリウ tech / アルアノリウ tech
  180. </pre>
  181. </div>
  182. </div>
  183. <h3 id="NotIn">func <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=989:1027#L28">NotIn</a></h3>
  184. <pre>func NotIn(rt *<a href="../../../../unicode/index.html">unicode</a>.<a href="../../../../unicode/index.html#RangeTable">RangeTable</a>) <a href="index.html#Set">Set</a></pre>
  185. <p>
  186. In creates a Set with a Contains method that returns true for all runes not
  187. in the given RangeTable.
  188. </p>
  189. <h3 id="Predicate">func <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=1167:1204#L33">Predicate</a></h3>
  190. <pre>func Predicate(f func(<a href="../../../../builtin/index.html#rune">rune</a>) <a href="../../../../builtin/index.html#bool">bool</a>) <a href="index.html#Set">Set</a></pre>
  191. <p>
  192. Predicate creates a Set with a Contains method that returns f(r).
  193. </p>
  194. <h2 id="Transformer">type <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=1292:1352#L38">Transformer</a></h2>
  195. <pre>type Transformer struct {
  196. <span class="comment">// contains filtered or unexported fields</span>
  197. }</pre>
  198. <p>
  199. Transformer implements the transform.Transformer interface.
  200. </p>
  201. <h3 id="If">func <a href="http://localhost:6060/src/golang.org/x/text/runes/cond.go?s=1583:1644#L24">If</a></h3>
  202. <pre>func If(s <a href="index.html#Set">Set</a>, tIn, tNotIn <a href="../transform/index.html">transform</a>.<a href="../transform/index.html#Transformer">Transformer</a>) <a href="index.html#Transformer">Transformer</a></pre>
  203. <p>
  204. If returns a transformer that applies tIn to consecutive runes for which
  205. s.Contains(r) and tNotIn to consecutive runes for which !s.Contains(r). Reset
  206. is called on tIn and tNotIn at the start of each run. A Nop transformer will
  207. substitute a nil value passed to tIn or tNotIn. Invalid UTF-8 is translated
  208. to RuneError to determine which transformer to apply, but is passed as is to
  209. the respective transformer.
  210. </p>
  211. <div id="example_If" class="toggle">
  212. <div class="collapsed">
  213. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  214. </div>
  215. <div class="expanded">
  216. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  217. <p>Code:</p>
  218. <pre class="code"><span class="comment">// Widen everything but ASCII.</span>
  219. isASCII := func(r rune) bool { return r &lt;= unicode.MaxASCII }
  220. t := runes.If(runes.Predicate(isASCII), nil, width.Widen)
  221. s, _, _ := transform.String(t, &#34;アルアノリウ tech / 中國 / 5₩&#34;)
  222. fmt.Println(s)
  223. <span class="comment"></pre>
  224. <p>Output:</p>
  225. <pre class="output">アルアノリウ tech / 中國 / 5₩
  226. </pre>
  227. </div>
  228. </div>
  229. <h3 id="Map">func <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=4875:4920#L170">Map</a></h3>
  230. <pre>func Map(mapping func(<a href="../../../../builtin/index.html#rune">rune</a>) <a href="../../../../builtin/index.html#rune">rune</a>) <a href="index.html#Transformer">Transformer</a></pre>
  231. <p>
  232. Map returns a Transformer that maps the runes in the input using the given
  233. mapping. Illegal bytes in the input are converted to utf8.RuneError before
  234. being passed to the mapping func.
  235. </p>
  236. <div id="example_Map" class="toggle">
  237. <div class="collapsed">
  238. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  239. </div>
  240. <div class="expanded">
  241. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  242. <p>Code:</p>
  243. <pre class="code">replaceHyphens := runes.Map(func(r rune) rune {
  244. if unicode.Is(unicode.Hyphen, r) {
  245. return &#39;|&#39;
  246. }
  247. return r
  248. })
  249. s, _, _ := transform.String(replaceHyphens, &#34;a-b‐c⸗d﹣e&#34;)
  250. fmt.Println(s)
  251. <span class="comment"></pre>
  252. <p>Output:</p>
  253. <pre class="output">a|b|c|d|e
  254. </pre>
  255. </div>
  256. </div>
  257. <h3 id="Remove">func <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=2644:2674#L83">Remove</a></h3>
  258. <pre>func Remove(s <a href="index.html#Set">Set</a>) <a href="index.html#Transformer">Transformer</a></pre>
  259. <p>
  260. Remove returns a Transformer that removes runes r for which s.Contains(r).
  261. Illegal input bytes are replaced by RuneError before being passed to f.
  262. </p>
  263. <div id="example_Remove" class="toggle">
  264. <div class="collapsed">
  265. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  266. </div>
  267. <div class="expanded">
  268. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  269. <p>Code:</p>
  270. <pre class="code">t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
  271. s, _, _ := transform.String(t, &#34;résumé&#34;)
  272. fmt.Println(s)
  273. <span class="comment"></pre>
  274. <p>Output:</p>
  275. <pre class="output">resume
  276. </pre>
  277. </div>
  278. </div>
  279. <h3 id="ReplaceIllFormed">func <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=7081:7116#L267">ReplaceIllFormed</a></h3>
  280. <pre>func ReplaceIllFormed() <a href="index.html#Transformer">Transformer</a></pre>
  281. <p>
  282. ReplaceIllFormed returns a transformer that replaces all input bytes that are
  283. not part of a well-formed UTF-8 code sequence with utf8.RuneError.
  284. </p>
  285. <h3 id="Transformer.Bytes">func (Transformer) <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=1845:1888#L55">Bytes</a></h3>
  286. <pre>func (t <a href="index.html#Transformer">Transformer</a>) Bytes(b []<a href="../../../../builtin/index.html#byte">byte</a>) []<a href="../../../../builtin/index.html#byte">byte</a></pre>
  287. <p>
  288. Bytes returns a new byte slice with the result of converting b using t. It
  289. calls Reset on t. It returns nil if any error was found. This can only happen
  290. if an error-producing Transformer is passed to If.
  291. </p>
  292. <h3 id="Transformer.Reset">func (Transformer) <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=1585:1613#L50">Reset</a></h3>
  293. <pre>func (t <a href="index.html#Transformer">Transformer</a>) Reset()</pre>
  294. <h3 id="Transformer.Span">func (Transformer) <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=1486:1552#L46">Span</a></h3>
  295. <pre>func (t <a href="index.html#Transformer">Transformer</a>) Span(b []<a href="../../../../builtin/index.html#byte">byte</a>, atEOF <a href="../../../../builtin/index.html#bool">bool</a>) (n <a href="../../../../builtin/index.html#int">int</a>, err <a href="../../../../builtin/index.html#error">error</a>)</pre>
  296. <h3 id="Transformer.String">func (Transformer) <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=2192:2236#L66">String</a></h3>
  297. <pre>func (t <a href="index.html#Transformer">Transformer</a>) String(s <a href="../../../../builtin/index.html#string">string</a>) <a href="../../../../builtin/index.html#string">string</a></pre>
  298. <p>
  299. String returns a string with the result of converting s using t. It calls
  300. Reset on t. It returns the empty string if any error was found. This can only
  301. happen if an error-producing Transformer is passed to If.
  302. </p>
  303. <h3 id="Transformer.Transform">func (Transformer) <a href="http://localhost:6060/src/golang.org/x/text/runes/runes.go?s=1354:1441#L42">Transform</a></h3>
  304. <pre>func (t <a href="index.html#Transformer">Transformer</a>) Transform(dst, src []<a href="../../../../builtin/index.html#byte">byte</a>, atEOF <a href="../../../../builtin/index.html#bool">bool</a>) (nDst, nSrc <a href="../../../../builtin/index.html#int">int</a>, err <a href="../../../../builtin/index.html#error">error</a>)</pre>
  305. <div id="footer">
  306. Build version go1.6.<br>
  307. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  308. the content of this page is licensed under the
  309. Creative Commons Attribution 3.0 License,
  310. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  311. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  312. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  313. </div>
  314. </div><!-- .container -->
  315. </div><!-- #page -->
  316. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  317. <script type="text/javascript" src="../../../../../lib/godoc/jquery.js"></script>
  318. <script type="text/javascript" src="../../../../../lib/godoc/jquery.treeview.js"></script>
  319. <script type="text/javascript" src="../../../../../lib/godoc/jquery.treeview.edit.js"></script>
  320. <script type="text/javascript" src="../../../../../lib/godoc/godocs.js"></script>
  321. </body>
  322. </html>