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.

429 lines
13 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>unicode - 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 unicode</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/encoding/unicode"</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-subdirectories">Subdirectories</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 unicode provides Unicode encodings such as UTF-16.
  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#pkg-variables">Variables</a></dd>
  82. <dd><a href="index.html#BOMOverride">func BOMOverride(fallback transform.Transformer) transform.Transformer</a></dd>
  83. <dd><a href="index.html#UTF16">func UTF16(e Endianness, b BOMPolicy) encoding.Encoding</a></dd>
  84. <dd><a href="index.html#BOMPolicy">type BOMPolicy</a></dd>
  85. <dd><a href="index.html#Endianness">type Endianness</a></dd>
  86. </dl>
  87. </div><!-- #manual-nav -->
  88. <h4>Package files</h4>
  89. <p>
  90. <span style="font-size:90%">
  91. <a href="http://localhost:6060/src/golang.org/x/text/encoding/unicode/override.go">override.go</a>
  92. <a href="http://localhost:6060/src/golang.org/x/text/encoding/unicode/unicode.go">unicode.go</a>
  93. </span>
  94. </p>
  95. </div><!-- .expanded -->
  96. </div><!-- #pkg-index -->
  97. <div id="pkg-callgraph" class="toggle" style="display: none">
  98. <div class="collapsed">
  99. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  100. </div> <!-- .expanded -->
  101. <div class="expanded">
  102. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  103. <p>
  104. In the call graph viewer below, each node
  105. is a function belonging to this package
  106. and its children are the functions it
  107. calls&mdash;perhaps dynamically.
  108. </p>
  109. <p>
  110. The root nodes are the entry points of the
  111. package: functions that may be called from
  112. outside the package.
  113. There may be non-exported or anonymous
  114. functions among them if they are called
  115. dynamically from another package.
  116. </p>
  117. <p>
  118. Click a node to visit that function's source code.
  119. From there you can visit its callers by
  120. clicking its declaring <code>func</code>
  121. token.
  122. </p>
  123. <p>
  124. Functions may be omitted if they were
  125. determined to be unreachable in the
  126. particular programs or tests that were
  127. analyzed.
  128. </p>
  129. <!-- Zero means show all package entry points. -->
  130. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  131. </div>
  132. </div> <!-- #pkg-callgraph -->
  133. <h2 id="pkg-variables">Variables</h2>
  134. <pre>var <span id="All">All</span> = []<a href="../index.html">encoding</a>.<a href="../index.html#Encoding">Encoding</a>{
  135. <a href="index.html#UTF8">UTF8</a>,
  136. <a href="index.html#UTF16">UTF16</a>(<a href="index.html#BigEndian">BigEndian</a>, <a href="index.html#UseBOM">UseBOM</a>),
  137. <a href="index.html#UTF16">UTF16</a>(<a href="index.html#BigEndian">BigEndian</a>, <a href="index.html#IgnoreBOM">IgnoreBOM</a>),
  138. <a href="index.html#UTF16">UTF16</a>(<a href="index.html#LittleEndian">LittleEndian</a>, <a href="index.html#IgnoreBOM">IgnoreBOM</a>),
  139. }</pre>
  140. <p>
  141. All lists a configuration for each IANA-defined UTF-16 variant.
  142. </p>
  143. <pre>var <span id="ErrMissingBOM">ErrMissingBOM</span> = <a href="../../../../../errors/index.html">errors</a>.<a href="../../../../../errors/index.html#New">New</a>(&#34;encoding: missing byte order mark&#34;)</pre>
  144. <p>
  145. ErrMissingBOM means that decoding UTF-16 input with ExpectBOM did not find a
  146. starting byte order mark.
  147. </p>
  148. <pre>var <span id="UTF8">UTF8</span> <a href="../index.html">encoding</a>.<a href="../index.html#Encoding">Encoding</a> = utf8enc</pre>
  149. <p>
  150. UTF8 is the UTF-8 encoding.
  151. </p>
  152. <h2 id="BOMOverride">func <a href="http://localhost:6060/src/golang.org/x/text/encoding/unicode/override.go?s=1109:1179#L17">BOMOverride</a></h2>
  153. <pre>func BOMOverride(fallback <a href="../../transform/index.html">transform</a>.<a href="../../transform/index.html#Transformer">Transformer</a>) <a href="../../transform/index.html">transform</a>.<a href="../../transform/index.html#Transformer">Transformer</a></pre>
  154. <p>
  155. BOMOverride returns a new decoder transformer that is identical to fallback,
  156. except that the presence of a Byte Order Mark at the start of the input
  157. causes it to switch to the corresponding Unicode decoding. It will only
  158. consider BOMs for UTF-8, UTF-16BE, and UTF-16LE.
  159. </p>
  160. <p>
  161. This differs from using ExpectBOM by allowing a BOM to switch to UTF-8, not
  162. just UTF-16 variants, and allowing falling back to any encoding scheme.
  163. </p>
  164. <p>
  165. This technique is recommended by the W3C for use in HTML 5: &#34;For
  166. compatibility with deployed content, the byte order mark (also known as BOM)
  167. is considered more authoritative than anything else.&#34;
  168. <a href="http://www.w3.org/TR/encoding/#specification-hooks">http://www.w3.org/TR/encoding/#specification-hooks</a>
  169. </p>
  170. <p>
  171. Using BOMOverride is mostly intended for use cases where the first characters
  172. of a fallback encoding are known to not be a BOM, for example, for valid HTML
  173. and most encodings.
  174. </p>
  175. <h2 id="UTF16">func <a href="http://localhost:6060/src/golang.org/x/text/encoding/unicode/unicode.go?s=5459:5514#L142">UTF16</a></h2>
  176. <pre>func UTF16(e <a href="index.html#Endianness">Endianness</a>, b <a href="index.html#BOMPolicy">BOMPolicy</a>) <a href="../index.html">encoding</a>.<a href="../index.html#Encoding">Encoding</a></pre>
  177. <p>
  178. UTF16 returns a UTF-16 Encoding for the given default endianness and byte
  179. order mark (BOM) policy.
  180. </p>
  181. <p>
  182. When decoding from UTF-16 to UTF-8, if the BOMPolicy is IgnoreBOM then
  183. neither BOMs U+FEFF nor noncharacters U+FFFE in the input stream will affect
  184. the endianness used for decoding, and will instead be output as their
  185. standard UTF-8 encodings: &#34;\xef\xbb\xbf&#34; and &#34;\xef\xbf\xbe&#34;. If the BOMPolicy
  186. is UseBOM or ExpectBOM a staring BOM is not written to the UTF-8 output.
  187. Instead, it overrides the default endianness e for the remainder of the
  188. transformation. Any subsequent BOMs U+FEFF or noncharacters U+FFFE will not
  189. affect the endianness used, and will instead be output as their standard
  190. UTF-8 encodings. For UseBOM, if there is no starting BOM, it will proceed
  191. with the default Endianness. For ExpectBOM, in that case, the transformation
  192. will return early with an ErrMissingBOM error.
  193. </p>
  194. <p>
  195. When encoding from UTF-8 to UTF-16, a BOM will be inserted at the start of
  196. the output if the BOMPolicy is UseBOM or ExpectBOM. Otherwise, a BOM will not
  197. be inserted. The UTF-8 input does not need to contain a BOM.
  198. </p>
  199. <p>
  200. There is no concept of a &#39;native&#39; endianness. If the UTF-16 data is produced
  201. and consumed in a greater context that implies a certain endianness, use
  202. IgnoreBOM. Otherwise, use ExpectBOM and always produce and consume a BOM.
  203. </p>
  204. <p>
  205. In the language of <a href="http://www.unicode.org/faq/utf_bom.html#bom10">http://www.unicode.org/faq/utf_bom.html#bom10</a>, IgnoreBOM
  206. corresponds to &#34;Where the precise type of the data stream is known... the
  207. BOM should not be used&#34; and ExpectBOM corresponds to &#34;A particular
  208. protocol... may require use of the BOM&#34;.
  209. </p>
  210. <h2 id="BOMPolicy">type <a href="http://localhost:6060/src/golang.org/x/text/encoding/unicode/unicode.go?s=6708:6728#L173">BOMPolicy</a></h2>
  211. <pre>type BOMPolicy <a href="../../../../../builtin/index.html#uint8">uint8</a></pre>
  212. <p>
  213. BOMPolicy is a UTF-16 encoding&#39;s byte order mark policy.
  214. </p>
  215. <pre>const (
  216. <span class="comment">// IgnoreBOM means to ignore any byte order marks.</span>
  217. <span id="IgnoreBOM">IgnoreBOM</span> <a href="index.html#BOMPolicy">BOMPolicy</a> = 0
  218. <span class="comment">// UseBOM means that the UTF-16 form may start with a byte order mark, which</span>
  219. <span class="comment">// will be used to override the default encoding.</span>
  220. <span id="UseBOM">UseBOM</span> <a href="index.html#BOMPolicy">BOMPolicy</a> = writeBOM | acceptBOM
  221. <span class="comment">// ExpectBOM means that the UTF-16 form must start with a byte order mark,</span>
  222. <span class="comment">// which will be used to override the default encoding.</span>
  223. <span id="ExpectBOM">ExpectBOM</span> <a href="index.html#BOMPolicy">BOMPolicy</a> = writeBOM | acceptBOM | requireBOM
  224. )</pre>
  225. <h2 id="Endianness">type <a href="http://localhost:6060/src/golang.org/x/text/encoding/unicode/unicode.go?s=8326:8346#L212">Endianness</a></h2>
  226. <pre>type Endianness <a href="../../../../../builtin/index.html#bool">bool</a></pre>
  227. <p>
  228. Endianness is a UTF-16 encoding&#39;s default endianness.
  229. </p>
  230. <pre>const (
  231. <span class="comment">// BigEndian is UTF-16BE.</span>
  232. <span id="BigEndian">BigEndian</span> <a href="index.html#Endianness">Endianness</a> = <a href="../../../../../builtin/index.html#false">false</a>
  233. <span class="comment">// LittleEndian is UTF-16LE.</span>
  234. <span id="LittleEndian">LittleEndian</span> <a href="index.html#Endianness">Endianness</a> = <a href="../../../../../builtin/index.html#true">true</a>
  235. )</pre>
  236. <h2 id="pkg-subdirectories">Subdirectories</h2>
  237. <div class="pkg-dir">
  238. <table>
  239. <tr>
  240. <th class="pkg-name">Name</th>
  241. <th class="pkg-synopsis">Synopsis</th>
  242. </tr>
  243. <tr>
  244. <td colspan="2"><a href="../index.html">..</a></td>
  245. </tr>
  246. <tr>
  247. <td class="pkg-name" style="padding-left: 0px;">
  248. <a href="utf32/index.html">utf32</a>
  249. </td>
  250. <td class="pkg-synopsis">
  251. Package utf32 provides the UTF-32 Unicode encoding.
  252. </td>
  253. </tr>
  254. </table>
  255. </div>
  256. <div id="footer">
  257. Build version go1.6.<br>
  258. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  259. the content of this page is licensed under the
  260. Creative Commons Attribution 3.0 License,
  261. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  262. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  263. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  264. </div>
  265. </div><!-- .container -->
  266. </div><!-- #page -->
  267. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  268. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.js"></script>
  269. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.treeview.js"></script>
  270. <script type="text/javascript" src="../../../../../../lib/godoc/jquery.treeview.edit.js"></script>
  271. <script type="text/javascript" src="../../../../../../lib/godoc/godocs.js"></script>
  272. </body>
  273. </html>