mirror of
https://github.com/golang/go
synced 2024-10-05 08:31:22 -06:00
6bf84214c1
Example: PACKAGE package utf8 import "unicode/utf8" Package utf8 implements functions and constants to support text encoded in UTF-8. This package calls a Unicode character a rune for brevity. CONSTANTS const ( RuneError = unicode.ReplacementChar // the "error" Rune or "replacement character". RuneSelf = 0x80 // characters below Runeself are represented as themselves in a single byte. UTFMax = 4 // maximum number of bytes of a UTF-8 encoded Unicode character. ) Numbers fundamental to the encoding. FUNCTIONS func DecodeLastRune(p []byte) (r rune, size int) DecodeLastRune unpacks the last UTF-8 encoding in p and returns the rune and its width in bytes. func DecodeLastRuneInString(s string) (r rune, size int) DecodeLastRuneInString is like DecodeLastRune but its input is a string. func DecodeRune(p []byte) (r rune, size int) DecodeRune unpacks the first UTF-8 encoding in p and returns the rune and its width in bytes. func DecodeRuneInString(s string) (r rune, size int) DecodeRuneInString is like DecodeRune but its input is a string. func EncodeRune(p []byte, r rune) int EncodeRune writes into p (which must be large enough) the UTF-8 encoding of the rune. It returns the number of bytes written. func FullRune(p []byte) bool FullRune reports whether the bytes in p begin with a full UTF-8 encoding of a rune. An invalid encoding is considered a full Rune since it will convert as a width-1 error rune. func FullRuneInString(s string) bool FullRuneInString is like FullRune but its input is a string. func RuneCount(p []byte) int RuneCount returns the number of runes in p. Erroneous and short encodings are treated as single runes of width 1 byte. func RuneCountInString(s string) (n int) RuneCountInString is like RuneCount but its input is a string. func RuneLen(r rune) int RuneLen returns the number of bytes required to encode the rune. func RuneStart(b byte) bool RuneStart reports whether the byte could be the first byte of an encoded rune. Second and subsequent bytes always have the top two bits set to 10. func Valid(p []byte) bool Valid reports whether p consists entirely of valid UTF-8-encoded runes. func ValidString(s string) bool ValidString reports whether s consists entirely of valid UTF-8-encoded runes. TYPES type String struct { // contains filtered or unexported fields } String wraps a regular string with a small structure that provides more efficient indexing by code point index, as opposed to byte index. Scanning incrementally forwards or backwards is O(1) per index operation (although not as fast a range clause going forwards). Random access is O(N) in the length of the string, but the overhead is less than always scanning from the beginning. If the string is ASCII, random access is O(1). Unlike the built-in string type, String has internal mutable state and is not thread-safe. func NewString(contents string) *String NewString returns a new UTF-8 string with the provided contents. func (s *String) At(i int) rune At returns the rune with index i in the String. The sequence of runes is the same as iterating over the contents with a "for range" clause. func (s *String) Init(contents string) *String Init initializes an existing String to hold the provided contents. It returns a pointer to the initialized String. func (s *String) IsASCII() bool IsASCII returns a boolean indicating whether the String contains only ASCII bytes. func (s *String) RuneCount() int RuneCount returns the number of runes (Unicode code points) in the String. func (s *String) Slice(i, j int) string Slice returns the string sliced at rune positions [i:j]. func (s *String) String() string String returns the contents of the String. This method also means the String is directly printable by fmt.Print. Fixes #2479. R=golang-dev, dsymonds, mattn.jp, r, gri, r CC=golang-dev https://golang.org/cl/5472051 |
||
---|---|---|
.. | ||
appinit.go | ||
codewalk.go | ||
dirtrees.go | ||
doc.go | ||
filesystem.go | ||
format.go | ||
godoc.go | ||
httpzip.go | ||
index.go | ||
main.go | ||
Makefile | ||
mapping.go | ||
parser.go | ||
README.godoc-app | ||
setup-godoc-app.bash | ||
snippet.go | ||
spec.go | ||
throttle.go | ||
utils.go | ||
zip.go |
Copyright 2011 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. godoc on appengine ------------------ Prerequisites ------------- * Go appengine SDK 1.5.5 - 2011-10-11 http://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Go * Go sources at tip under $GOROOT Directory structure ------------------- * Let $APPDIR be the directory containing the app engine files. (e.g., $APPDIR=$HOME/godoc-app) * $APPDIR contains the following entries (this may change depending on app-engine release and version of godoc): alt/ encoding/binary/ go/* index/suffixarray/ app.yaml godoc.zip godoc/ index.split.* * The app.yaml file is set up per app engine documentation. For instance: application: godoc-app version: 1-5-5 runtime: go api_version: 3 handlers: - url: /.* script: _go_app * The godoc/ directory contains a copy of the files under $GOROOT/src/cmd/godoc with modifications: - doc.go is excluded (it belongs to pseudo-package ÒdocumentationÓ) - main.go is excluded (appinit.go is taking its place) Additional manual modifications are required to refer to the alt/ packages where the app-engine library is not up-to-date with the godoc version. * The alt/ directory contains up-to-date copies of Go packages that a tip-based godoc is dependent on but which do not yet exist in the current app-engine SDK. At the time of this writing (10/14/2011) this is the entire go directory tree (for the missing FileSet serialization code in go/token) as well as the index/suffixarray package (for the missing suffix array serialization code). The latest (alt/)index/suffixarray package internally requires the latest version of encoding/binary, which is why it also needs to be present under alt/. Configuring and running godoc ----------------------------- To configure godoc, run bash setup-godoc-app.bash to create the godoc.zip, index.split.*, and godoc/appconfig.go files based on $GOROOT and $APPDIR. See the script for details on usage. To run godoc locally, using the app-engine emulator, run <path to google_appengine>/dev_appserver.py $APPDIR godoc should come up at http://localhost:8080 .