Documentation ¶
Overview ¶
Package gen contains common code for the various code generation tools in the text repository. Its usage ensures consistency between tools.
This package defines command line flags that are common to most generation tools. The flags allow for specifying specific Unicode and CLDR versions in the public Unicode data repository (http://www.unicode.org/Public).
A local Unicode data mirror can be set through the flag -local or the environment variable UNICODE_DIR. The former takes precedence. The local directory should follow the same structure as the public repository.
IANA data can also optionally be mirrored by putting it in the iana directory rooted at the top of the local mirror. Beware, though, that IANA data is not versioned. So it is up to the developer to use the right version.
Index ¶
- func CLDRVersion() string
- func Init()
- func IsLocal() bool
- func Open(urlRoot, subdir, path string) io.ReadCloser
- func OpenCLDRCoreZip() io.ReadCloser
- func OpenIANAFile(path string) io.ReadCloser
- func OpenUCDFile(file string) io.ReadCloser
- func OpenUnicodeFile(category, version, file string) io.ReadCloser
- func Repackage(inFile, outFile, pkg string)
- func UnicodeVersion() string
- func WriteCLDRVersion(w io.Writer)
- func WriteGo(w io.Writer, pkg, tags string, b []byte) (n int, err error)
- func WriteGoFile(filename, pkg string, b []byte)
- func WriteUnicodeVersion(w io.Writer)
- func WriteVersionedGoFile(filename, pkg string, b []byte)
- type CodeWriter
- func (w *CodeWriter) Write(p []byte) (n int, err error)
- func (w *CodeWriter) WriteArray(x interface{})
- func (w *CodeWriter) WriteComment(comment string, args ...interface{})
- func (w *CodeWriter) WriteConst(name string, x interface{})
- func (w *CodeWriter) WriteGo(out io.Writer, pkg, tags string) (n int, err error)
- func (w *CodeWriter) WriteGoFile(filename, pkg string)
- func (w *CodeWriter) WriteSlice(x interface{})
- func (w *CodeWriter) WriteString(s string)
- func (w *CodeWriter) WriteType(x interface{}) string
- func (w *CodeWriter) WriteVar(name string, x interface{})
- func (w *CodeWriter) WriteVersionedGoFile(filename, pkg string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init()
Init performs common initialization for a gen command. It parses the flags and sets up the standard logging parameters.
func Open ¶
func Open(urlRoot, subdir, path string) io.ReadCloser
Open opens subdir/path if a local directory is specified and the file exists, where subdir is a directory relative to the local root, or fetches it from urlRoot/path otherwise. It will call log.Fatal if there are any errors.
func OpenCLDRCoreZip ¶
func OpenCLDRCoreZip() io.ReadCloser
OpenCLDRCoreZip opens the CLDR core zip file. It will call log.Fatal if there are any errors.
func OpenIANAFile ¶
func OpenIANAFile(path string) io.ReadCloser
OpenIANAFile opens the requested IANA file. The file is specified relative to the IANA root, which is typically either http://www.iana.org or the iana directory in the local mirror. It will call log.Fatal if there are any errors.
func OpenUCDFile ¶
func OpenUCDFile(file string) io.ReadCloser
OpenUCDFile opens the requested UCD file. The file is specified relative to the public Unicode root directory. It will call log.Fatal if there are any errors.
func OpenUnicodeFile ¶
func OpenUnicodeFile(category, version, file string) io.ReadCloser
OpenUnicodeFile opens the requested file of the requested category from the root of the Unicode data archive. The file is specified relative to the public Unicode root directory. If version is "", it will use the default Unicode version. It will call log.Fatal if there are any errors.
func Repackage ¶
func Repackage(inFile, outFile, pkg string)
Repackage rewrites a Go file from belonging to package main to belonging to the given package.
func UnicodeVersion ¶
func UnicodeVersion() string
UnicodeVersion reports the requested Unicode version.
func WriteCLDRVersion ¶
WriteCLDRVersion writes a constant for the CLDR version from which the tables are generated.
func WriteGo ¶
WriteGo prepends a standard file comment and package statement to the given bytes, applies gofmt, and writes them to w.
func WriteGoFile ¶
WriteGoFile prepends a standard file comment and package statement to the given bytes, applies gofmt, and writes them to a file with the given name. It will call log.Fatal if there are any errors.
func WriteUnicodeVersion ¶
WriteUnicodeVersion writes a constant for the Unicode version from which the tables are generated.
func WriteVersionedGoFile ¶ added in v0.2.0
WriteVersionedGoFile prepends a standard file comment, adds build tags to version the file for the current Unicode version, and package statement to the given bytes, applies gofmt, and writes them to a file with the given name. It will call log.Fatal if there are any errors.
Types ¶
type CodeWriter ¶
type CodeWriter struct { Size int Hash hash.Hash32 // content hash // contains filtered or unexported fields }
CodeWriter is a utility for writing structured code. It computes the content hash and size of written content. It ensures there are newlines between written code blocks.
func (*CodeWriter) Write ¶
func (w *CodeWriter) Write(p []byte) (n int, err error)
func (*CodeWriter) WriteArray ¶
func (w *CodeWriter) WriteArray(x interface{})
WriteArray writes an array value.
func (*CodeWriter) WriteComment ¶
func (w *CodeWriter) WriteComment(comment string, args ...interface{})
WriteComment writes a comment block. All line starts are prefixed with "//". Initial empty lines are gobbled. The indentation for the first line is stripped from consecutive lines.
func (*CodeWriter) WriteConst ¶
func (w *CodeWriter) WriteConst(name string, x interface{})
WriteConst writes a constant of the given name and value.
func (*CodeWriter) WriteGo ¶
WriteGo appends the buffer with the total size of all created structures and writes it as a Go file to the the given writer with the given package name.
func (*CodeWriter) WriteGoFile ¶
func (w *CodeWriter) WriteGoFile(filename, pkg string)
WriteGoFile appends the buffer with the total size of all created structures and writes it as a Go file to the the given file with the given package name.
func (*CodeWriter) WriteSlice ¶
func (w *CodeWriter) WriteSlice(x interface{})
WriteSlice writes a slice value.
func (*CodeWriter) WriteString ¶
func (w *CodeWriter) WriteString(s string)
WriteString writes a string literal.
func (*CodeWriter) WriteType ¶
func (w *CodeWriter) WriteType(x interface{}) string
WriteType writes a definition of the type of the given value and returns the type name.
func (*CodeWriter) WriteVar ¶
func (w *CodeWriter) WriteVar(name string, x interface{})
WriteVar writes a variable of the given name and value.
func (*CodeWriter) WriteVersionedGoFile ¶ added in v0.2.0
func (w *CodeWriter) WriteVersionedGoFile(filename, pkg string)
WriteVersionedGoFile appends the buffer with the total size of all created structures and writes it as a Go file to the the given file with the given package name and build tags for the current Unicode version,