├── README.md
├── config.json
├── gateway
├── cache.go
├── client.go
├── cmdline.go
├── config.go
├── httpserver.go
├── models.go
├── utils.go
└── utils_test.go
├── index.html
├── list_message.html
├── list_mo.html
├── main.go
├── ne1.png
├── pages
└── pages.go
└── vendor
└── github.com
├── bigwhite
└── gocmpp
│ ├── .gitignore
│ ├── .travis.yml
│ ├── LICENSE
│ ├── Makefile
│ ├── README.md
│ ├── activetest.go
│ ├── activetest_test.go
│ ├── client.go
│ ├── conn.go
│ ├── conn_test.go
│ ├── connect.go
│ ├── connect_test.go
│ ├── deliver.go
│ ├── deliver_test.go
│ ├── examples
│ ├── client
│ │ └── client.go
│ ├── cmdlineclient
│ │ └── client.go
│ └── server
│ │ └── server.go
│ ├── fuzztest
│ ├── fwd
│ │ ├── corpus
│ │ │ └── 0
│ │ ├── fuzz.go
│ │ └── gen
│ │ │ └── main.go
│ └── submit
│ │ ├── corpus
│ │ ├── 0
│ │ ├── 413e7948416c5f6399d032f9aad69356c58428ab-1
│ │ ├── 69a155acb4ae42e3cc8691b376d4a3a822fcf916-1
│ │ ├── 983f5232a24d1d3e195b9ad1bc02060ca59efbcd-1
│ │ ├── a10909c2cdcaf5adb7e6b092a4faba558b62bd96-1
│ │ ├── a34cb30c810e427518386c86199cdf6b1a6275ea-1
│ │ ├── b9d74ec2b9f27fd6ac12402606c56ac1fd39bdd2-1
│ │ ├── da39a3ee5e6b4b0d3255bfef95601890afd80709-1
│ │ └── e7f8e0514e4bc345f73c136dbaf17aabdffeb78d-1
│ │ ├── fuzz.go
│ │ └── gen
│ │ └── main.go
│ ├── fwd.go
│ ├── fwd_test.go
│ ├── packet.go
│ ├── packet_test.go
│ ├── receipt.go
│ ├── receipt_test.go
│ ├── server.go
│ ├── submit.go
│ ├── submit_test.go
│ ├── terminate.go
│ ├── terminate_test.go
│ ├── utils
│ ├── pdu.go
│ ├── utils.go
│ ├── utils_amd64_test.go
│ └── utils_test.go
│ └── vendor
│ └── golang.org
│ └── x
│ └── text
│ ├── AUTHORS
│ ├── CONTRIBUTING.md
│ ├── CONTRIBUTORS
│ ├── LICENSE
│ ├── PATENTS
│ ├── README
│ ├── bidi
│ ├── bidi.go
│ ├── gen.go
│ ├── gen_ranges.go
│ ├── gen_trieval.go
│ ├── ranges_test.go
│ ├── tables.go
│ ├── tables_test.go
│ └── trieval.go
│ ├── cases
│ ├── cases.go
│ ├── context.go
│ ├── context_test.go
│ ├── example_test.go
│ ├── gen.go
│ ├── gen_trieval.go
│ ├── map.go
│ ├── map_test.go
│ ├── tables.go
│ ├── tables_test.go
│ └── trieval.go
│ ├── codereview.cfg
│ ├── collate
│ ├── collate.go
│ ├── collate_test.go
│ ├── colltab
│ │ ├── collate_test.go
│ │ ├── collelem.go
│ │ ├── collelem_test.go
│ │ ├── colltab.go
│ │ ├── colltab_test.go
│ │ ├── contract.go
│ │ ├── contract_test.go
│ │ ├── export.go
│ │ ├── numeric.go
│ │ ├── numeric_test.go
│ │ ├── table.go
│ │ ├── trie.go
│ │ └── trie_test.go
│ ├── export_test.go
│ ├── index.go
│ ├── maketables.go
│ ├── option.go
│ ├── option_test.go
│ ├── reg_test.go
│ ├── sort.go
│ ├── sort_test.go
│ ├── table_test.go
│ ├── tables.go
│ └── tools
│ │ └── colcmp
│ │ ├── Makefile
│ │ ├── chars.go
│ │ ├── col.go
│ │ ├── colcmp.go
│ │ ├── darwin.go
│ │ ├── gen.go
│ │ └── icu.go
│ ├── currency
│ ├── common.go
│ ├── currency.go
│ ├── currency_test.go
│ ├── format.go
│ ├── format_test.go
│ ├── gen.go
│ ├── gen_common.go
│ ├── tables.go
│ └── tables_test.go
│ ├── display
│ ├── dict.go
│ ├── dict_test.go
│ ├── display.go
│ ├── display_test.go
│ ├── lookup.go
│ ├── maketables.go
│ └── tables.go
│ ├── doc.go
│ ├── encoding
│ ├── charmap
│ │ ├── charmap.go
│ │ ├── maketables.go
│ │ └── tables.go
│ ├── encoding.go
│ ├── encoding_test.go
│ ├── example_test.go
│ ├── htmlindex
│ │ ├── gen.go
│ │ ├── htmlindex.go
│ │ ├── htmlindex_test.go
│ │ ├── map.go
│ │ └── tables.go
│ ├── ianaindex
│ │ ├── example_test.go
│ │ └── ianaindex.go
│ ├── internal
│ │ ├── identifier
│ │ │ ├── gen.go
│ │ │ ├── identifier.go
│ │ │ └── mib.go
│ │ └── internal.go
│ ├── japanese
│ │ ├── all.go
│ │ ├── eucjp.go
│ │ ├── iso2022jp.go
│ │ ├── maketables.go
│ │ ├── shiftjis.go
│ │ └── tables.go
│ ├── korean
│ │ ├── euckr.go
│ │ ├── maketables.go
│ │ └── tables.go
│ ├── simplifiedchinese
│ │ ├── all.go
│ │ ├── gbk.go
│ │ ├── hzgb2312.go
│ │ ├── maketables.go
│ │ └── tables.go
│ ├── testdata
│ │ ├── candide-gb18030.txt
│ │ ├── candide-utf-16le.txt
│ │ ├── candide-utf-8.txt
│ │ ├── candide-windows-1252.txt
│ │ ├── rashomon-euc-jp.txt
│ │ ├── rashomon-iso-2022-jp.txt
│ │ ├── rashomon-shift-jis.txt
│ │ ├── rashomon-utf-8.txt
│ │ ├── sunzi-bingfa-gb-levels-1-and-2-hz-gb2312.txt
│ │ ├── sunzi-bingfa-gb-levels-1-and-2-utf-8.txt
│ │ ├── sunzi-bingfa-simplified-gbk.txt
│ │ ├── sunzi-bingfa-simplified-utf-8.txt
│ │ ├── sunzi-bingfa-traditional-big5.txt
│ │ ├── sunzi-bingfa-traditional-utf-8.txt
│ │ ├── unsu-joh-eun-nal-euc-kr.txt
│ │ └── unsu-joh-eun-nal-utf-8.txt
│ ├── traditionalchinese
│ │ ├── big5.go
│ │ ├── maketables.go
│ │ └── tables.go
│ └── unicode
│ │ ├── override.go
│ │ └── unicode.go
│ ├── gen.go
│ ├── internal
│ ├── colltab
│ │ ├── colltab.go
│ │ ├── colltab_test.go
│ │ ├── contract.go
│ │ ├── contract_test.go
│ │ ├── iter.go
│ │ └── iter_test.go
│ ├── format
│ │ └── format.go
│ ├── gen.go
│ ├── gen
│ │ ├── code.go
│ │ └── gen.go
│ ├── gen_test.go
│ ├── internal.go
│ ├── internal_test.go
│ ├── match.go
│ ├── match_test.go
│ ├── tables.go
│ ├── tag
│ │ ├── tag.go
│ │ └── tag_test.go
│ ├── testtext
│ │ ├── codesize.go
│ │ └── text.go
│ ├── triegen
│ │ ├── compact.go
│ │ ├── data_test.go
│ │ ├── example_compact_test.go
│ │ ├── example_test.go
│ │ ├── gen_test.go
│ │ ├── print.go
│ │ └── triegen.go
│ └── ucd
│ │ ├── example_test.go
│ │ ├── ucd.go
│ │ └── ucd_test.go
│ ├── language
│ ├── Makefile
│ ├── common.go
│ ├── coverage.go
│ ├── coverage_test.go
│ ├── data_test.go
│ ├── display
│ │ ├── dict.go
│ │ ├── dict_test.go
│ │ ├── display.go
│ │ ├── display_test.go
│ │ ├── examples_test.go
│ │ ├── lookup.go
│ │ ├── maketables.go
│ │ └── tables.go
│ ├── examples_test.go
│ ├── gen_common.go
│ ├── gen_index.go
│ ├── go1_1.go
│ ├── go1_2.go
│ ├── index.go
│ ├── language.go
│ ├── language_test.go
│ ├── lookup.go
│ ├── lookup_test.go
│ ├── maketables.go
│ ├── match.go
│ ├── match_test.go
│ ├── parse.go
│ ├── parse_test.go
│ ├── tables.go
│ └── tags.go
│ ├── message
│ ├── catalog.go
│ ├── catalog_test.go
│ ├── message.go
│ └── message_test.go
│ ├── runes
│ ├── cond.go
│ ├── cond_test.go
│ ├── example_test.go
│ ├── runes.go
│ └── runes_test.go
│ ├── search
│ ├── index.go
│ ├── pattern.go
│ ├── pattern_test.go
│ ├── search.go
│ └── tables.go
│ ├── transform
│ ├── examples_test.go
│ ├── transform.go
│ └── transform_test.go
│ ├── unicode
│ ├── cldr
│ │ ├── base.go
│ │ ├── cldr.go
│ │ ├── cldr_test.go
│ │ ├── collate.go
│ │ ├── collate_test.go
│ │ ├── data_test.go
│ │ ├── decode.go
│ │ ├── examples_test.go
│ │ ├── makexml.go
│ │ ├── resolve.go
│ │ ├── resolve_test.go
│ │ ├── slice.go
│ │ ├── slice_test.go
│ │ └── xml.go
│ ├── doc.go
│ ├── norm
│ │ ├── composition.go
│ │ ├── composition_test.go
│ │ ├── example_iter_test.go
│ │ ├── forminfo.go
│ │ ├── forminfo_test.go
│ │ ├── input.go
│ │ ├── iter.go
│ │ ├── iter_test.go
│ │ ├── maketables.go
│ │ ├── norm_test.go
│ │ ├── normalize.go
│ │ ├── normalize_test.go
│ │ ├── readwriter.go
│ │ ├── readwriter_test.go
│ │ ├── tables.go
│ │ ├── transform.go
│ │ ├── transform_test.go
│ │ ├── trie.go
│ │ ├── triegen.go
│ │ └── ucd_test.go
│ └── rangetable
│ │ ├── gen.go
│ │ ├── merge.go
│ │ ├── merge_test.go
│ │ ├── rangetable.go
│ │ ├── rangetable_test.go
│ │ └── tables.go
│ └── width
│ ├── common_test.go
│ ├── example_test.go
│ ├── gen.go
│ ├── gen_common.go
│ ├── gen_trieval.go
│ ├── kind_string.go
│ ├── runes_test.go
│ ├── tables.go
│ ├── tables_test.go
│ ├── transform.go
│ ├── transform_test.go
│ ├── trieval.go
│ └── width.go
└── garyburd
└── redigo
├── .travis.yml
├── LICENSE
├── README.markdown
├── internal
├── commandinfo.go
├── commandinfo_test.go
└── redistest
│ └── testdb.go
├── redis
├── conn.go
├── conn_test.go
├── doc.go
├── log.go
├── pool.go
├── pool_test.go
├── pubsub.go
├── pubsub_test.go
├── redis.go
├── reply.go
├── reply_test.go
├── scan.go
├── scan_test.go
├── script.go
├── script_test.go
├── test_test.go
└── zpop_example_test.go
└── redisx
├── connmux.go
├── connmux_test.go
└── doc.go
/README.md:
--------------------------------------------------------------------------------
1 | HTTP网关---CMPP3.0
2 | -------
3 |
4 | ## 目标
5 | 将复杂的cmpp3.0的协议转成http的发送接口,给web程序提供一个易用的短信发送、接收接口
6 | ##安装配置
7 |
8 | ### 依赖说明
9 | - 服务依赖
10 | Redis -- 作为发送记录存储
11 | CMPP网关 -- 移动提供
12 | 确保以上服务已经启动之后再启动本服务。
13 | - 代码依赖
14 | github.com/bigwhite/gocmpp
15 | github.com/garyburd/redigo/redis
16 | 已经在vendor目录下,不需要额外的go get
17 | ### 安装redis
18 | 下载redis最新版本,即可
19 |
20 | > 建议使用3.0版本
21 |
22 | linux版本安装,请参考[官网](http://redis.io/)
23 | windows参考 [windows的Redis版本](https://github.com/MSOpenTech/redis/releases),建议安装成windows的服务, 参考 [这里](https://raw.githubusercontent.com/MSOpenTech/redis/3.0/Windows%20Service%20Documentation.md)
24 |
25 | for instance
26 | redis-server --service-install redis.windows.conf --loglevel verbose
27 | ### 安装程序
28 | 直接拷贝即可,安装文件见这里(cmpp目录)
29 | 链接: [http://pan.baidu.com/s/1skNVkNr](http://pan.baidu.com/s/1skNVkNr) 密码: yafb
30 |
31 | ### 配置文件说明
32 | 配置文件config.json
33 |
34 | {
35 | "user": "204221", //用于登陆网关的帐户名称
36 | "password": "052932", //登陆网关密码
37 | "sms_accessno": "1064899104221", //接入码 会作为发送方显示在终端上
38 | "service_id": "JSASXW", //网关分配的业务标识
39 | "http_host": "0.0.0.0", //http服务绑定的ip,0.0.0.0指的是绑定本机所有的网卡ip
40 | "http_port": "8000", //http服务绑定的端口
41 | "cmpp_host": "127.0.0.1", //cmpp网关的ip
42 | "cmpp_port": "7891", //cmpp网关的端口
43 | "debug": true, //debug为true,会打印一些调试信息
44 | "redis_host": "127.0.0.1", //redis的ip
45 | "redis_port": "6379" //redis的端口
46 | }
47 |
48 | ### 启动
49 |
50 | - Linux
51 | sh ./cmpp-gateway
52 |
53 | - Windows
54 | 双击执行cmpp-gateway.exe
55 |
56 |
57 | ## For Developer
58 | ### 安装CMPP3.0网关模拟器
59 |
60 |
61 | gocmpp自带一个模拟器 bigwhite/gocmpp/examples/server/server.go
62 | 不过该模拟器仅供简单测试。
63 | 建议下载一个比较完整的模拟器,我使用的是[CMPP模拟器](https://sites.google.com/site/cimpleteam/gateway/cmppsimulator)
64 | 另外一个下载链接,不需要翻墙 [点这里](http://www.simpleteam.com/doku.php?id=message:cmpp_simulator)
65 | 记得下载后,修改config.xml中的server.transceiver,将其中的
66 |
67 |
68 |
69 | message和passive改为-1,避免心跳的超时影响测试
70 |
71 | > 注:
72 | > 模拟器运行需要使用JVM,请自行下载
73 | > 仅在调试测试需要安装,正式使用请直接连接移动网关
74 |
75 | ### 编译代码
76 | git clone https://github.com/JoeCao/cmpp-gateway.git
77 | 设置GOPATH环境变量
78 | 生成linux 64bit
79 |
80 | GOOS=linux GOARCH=amd64 go build
81 |
82 | 生成windows 64bit
83 |
84 | GOOS=windows GOARCH=amd64 go build
85 |
86 |
87 | ### 流程说明
88 | CMPP的规范中,希望使用TCP全双工的能力,通过异步的方式交换数据。
89 | 从实际的场景,移动对CMPP的连接数也是有限制的。
90 | 所以本着尽量复用链接的目标,我们设计了三个goroutine,在一个链接上分别异步工作。如下图(图很丑,见谅)
91 | 
92 |
93 | Submit/Submit Resp 为异步传输,发送时填写了序列号"SEQID",但是"MSGID"这个重要标识字段需要网关生成并返回。
94 | 而在异步Resp消息体中,规范中要求“SP根据请求和应答消息的Sequence_Id一致性就可得到CMPP_Submit消息的Msg_Id”
95 | 这说明要在提交(submit)短信,和短信提交结果(submitresponse)之间需要关联一个ID。CMPP协议中,规定了SEQID作为来回应答的标识。
96 | 所以在submit后,我们将SEQID保存到KV存储中,然后在返回的消息中通过SEQID查找对应的消息。
97 |
98 | 同理Submit Response和Delivery Report之间通过MSGID关联,也需要保存对应的KV。不过本次因为对Delivery Report没有特殊保存要求,所以就不实现了。
99 |
100 | ## 感谢
101 | 感谢 @bigwhite 提供了坚实可靠的CMPP协议基础
102 | https://github.com/bigwhite/gocmpp.git
103 |
--------------------------------------------------------------------------------
/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "user": "104221",
3 | "password": "051992",
4 | "sms_accessno": "1064899104221",
5 | "service_id": "JSASXW",
6 | "http_host": "0.0.0.0",
7 | "http_port": "8000",
8 | "cmpp_host": "127.0.0.1",
9 | "cmpp_port": "7891",
10 | "debug": true,
11 | "redis_host": "127.0.0.1",
12 | "redis_port": "6379"
13 | }
--------------------------------------------------------------------------------
/gateway/cache.go:
--------------------------------------------------------------------------------
1 | package gateway
2 |
3 | import (
4 | "encoding/json"
5 | "errors"
6 | "fmt"
7 | "github.com/garyburd/redigo/redis"
8 | "log"
9 | "strconv"
10 | )
11 |
12 | type Cache struct {
13 | conn redis.Conn
14 | }
15 |
16 | var SCache Cache = Cache{}
17 |
18 | func StartCache(config *Config) {
19 | conn, err := redis.Dial("tcp", config.RedisHost+":"+config.RedisPort)
20 | if err != nil {
21 | log.Fatalf("连接Redis出错出错[%v]", err)
22 | } else {
23 | SCache.conn = conn
24 | log.Printf("连接Redis %s 成功", config.RedisHost+":"+config.RedisPort)
25 | }
26 | }
27 |
28 | func StopCache() {
29 | SCache.conn.Close()
30 | }
31 |
32 | //将发送的记录转为json放到redis中保存下来,为异步返回的submit reponse做准备
33 | func (c *Cache) SetWaitCache(key uint32, message SmsMes) {
34 | data, _ := json.Marshal(message)
35 | c.conn.Do("HSET", "waitseqcache", strconv.FormatUint(uint64(key), 10), data)
36 | }
37 |
38 | func (c *Cache) GetWaitCache(key uint32) (SmsMes, error) {
39 | seq_id := strconv.FormatUint(uint64(key), 10)
40 | ret, _ := redis.String(c.conn.Do("HGET", "waitseqcache", seq_id))
41 | mes := SmsMes{}
42 | if ret != "" {
43 | //从json还原为对象
44 | json.Unmarshal([]byte(ret), &mes)
45 | c.conn.Do("HDEL", "waitseqcache", seq_id)
46 | return mes, nil
47 | } else {
48 | return mes, errors.New("no key in cache")
49 | }
50 |
51 | }
52 |
53 | func (c *Cache) AddSubmits(mes *SmsMes) {
54 | //将submit结果提交到redis的队列存放
55 | data, _ := json.Marshal(mes)
56 | //新的记录加在头部,自然就倒序排列了
57 | c.conn.Do("LPUSH", "list_message", data)
58 | //只保留最近五十条
59 | //c.conn.Do("LTRIM", "submitlist", "0", "49")
60 | }
61 |
62 | func (c *Cache) AddMoList(mes *SmsMes) {
63 | //将submit结果提交到redis的队列存放
64 | data, _ := json.Marshal(mes)
65 | //新的记录加在头部,自然就倒序排列了
66 | c.conn.Do("LPUSH", "list_mo", data)
67 | //只保留最近五十条
68 | //c.conn.Do("LTRIM", "molist", "0", "49")
69 | }
70 |
71 | func (c *Cache) Length(listName string) int {
72 | if listName == "" {
73 | return 0
74 | }
75 | size, _ := redis.Int(c.conn.Do("LLEN", listName))
76 | return size
77 | }
78 |
79 | func (c *Cache) GetList(listName string, start, end int) *[]SmsMes {
80 | values, err := redis.Strings(c.conn.Do("LRANGE", listName, start, end))
81 | if err != nil {
82 | fmt.Println(err)
83 | //返回空对象
84 | return &[]SmsMes{}
85 | }
86 | v := make([]SmsMes, 0, len(values))
87 | for _, s := range values {
88 | mes := SmsMes{}
89 | json.Unmarshal([]byte(s), &mes)
90 | v = append(v, mes)
91 | }
92 | return &v
93 | }
94 |
--------------------------------------------------------------------------------
/gateway/cmdline.go:
--------------------------------------------------------------------------------
1 | package gateway
2 |
3 | import (
4 | "bufio"
5 | "log"
6 | "os"
7 | )
8 |
9 | func StartCmdLine() {
10 | log.Println("Please input sms context, press return to send and input 'stop' to quit")
11 | reader := bufio.NewReader(os.Stdin)
12 | for isRunning() {
13 | data, _, _ := reader.ReadLine()
14 | command := string(data)
15 | mes := SmsMes{Content: command, Src: "104221", Dest: "13900001111"}
16 |
17 | Messages <- mes
18 | if command == "stop" {
19 | close(Abort)
20 | break
21 | }
22 | log.Println("command", command)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/gateway/config.go:
--------------------------------------------------------------------------------
1 | package gateway
2 |
3 | import (
4 | "encoding/json"
5 | "io/ioutil"
6 | "log"
7 | "os"
8 | )
9 |
10 | type Config struct {
11 | User string `json:"user"`
12 |
13 | Password string `json:"password"`
14 | //短信接入码
15 | SmsAccessNo string `json:"sms_accessno"`
16 | //业务代码
17 | ServiceId string `json:"service_id"`
18 |
19 | HttpHost string `json:"http_host"`
20 | HttpPort string `json:"http_port"`
21 |
22 | CMPPHost string `json:"cmpp_host"`
23 | CMPPPort string `json:"cmpp_port"`
24 | Debug bool `json:"debug"`
25 | RedisHost string `json:"redis_host"`
26 | RedisPort string `json:"redis_port"`
27 | }
28 |
29 | func (c *Config) LoadFile(path string) {
30 | file, err := os.Open(path)
31 | if err != nil {
32 | log.Fatalf("读取配置文件[%s]出错[%v]", path, err)
33 | } else {
34 | fileData, err := ioutil.ReadAll(file)
35 | if err != nil {
36 | log.Fatalf("读取配置文件内容[%s]出错[%v]", path, err)
37 | } else {
38 | if err := json.Unmarshal(fileData, c); err != nil {
39 | log.Fatal("读取失败 => ", err)
40 | } else {
41 | log.Println("读取成功 => ", c)
42 | }
43 | }
44 | }
45 | }
46 |
47 | func (s *Config) Log(arg ...interface{}) {
48 | if s.Debug {
49 | log.Println(arg...)
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/gateway/httpserver.go:
--------------------------------------------------------------------------------
1 | package gateway
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "github.com/JoeCao/cmpp-gateway/pages"
7 | "html/template"
8 | "log"
9 | "net/http"
10 | "strconv"
11 | )
12 |
13 | var pageSize = 5
14 |
15 | // handler echoes the HTTP request.
16 | func handler(w http.ResponseWriter, r *http.Request) {
17 | if err := r.ParseForm(); err != nil {
18 | log.Print(err)
19 | }
20 | src := r.Form.Get("src")
21 | content := r.Form.Get("cont")
22 | dest := r.Form.Get("dest")
23 | w.Header().Set("Content-Type", "application/json; charset=UTF-8")
24 | if src == "" || content == "" || dest == "" {
25 | result, _ := json.Marshal(
26 | map[string]interface{}{"result": -1, "error": "请输入 参数'src' 'dest' 'const' 缺一不可"})
27 | fmt.Fprintf(w, string(result))
28 | return
29 | }
30 | mes := SmsMes{Src: src, Content: content, Dest: dest}
31 | Messages <- mes
32 | result, _ := json.Marshal(
33 | map[string]interface{}{"error": "", "result": 0})
34 | fmt.Fprintf(w, string(result))
35 | }
36 |
37 | func index(w http.ResponseWriter, r *http.Request) {
38 | findTemplate(w, r, "index.html")
39 |
40 | }
41 |
42 | func findTemplate(w http.ResponseWriter, r *http.Request, tpl string) {
43 | t, error := template.New(tpl).ParseFiles(tpl)
44 | if error != nil {
45 | fmt.Fprintf(w, "template error %v", error)
46 | return
47 | }
48 |
49 | err := t.Execute(w, struct{}{})
50 | if err != nil {
51 | fmt.Fprintf(w, "error %v", err)
52 | return
53 | }
54 | }
55 |
56 | func listMessage(w http.ResponseWriter, r *http.Request, listName string) {
57 | r.ParseForm()
58 | parameter := r.Form.Get("page")
59 | var c_page int
60 | if parameter == "" {
61 | c_page = 1
62 | } else {
63 | c_page, _ = strconv.Atoi(parameter)
64 | }
65 | count := SCache.Length(listName)
66 | page := pages.NewPage(c_page, pageSize, count)
67 | t, err := template.New(listName + ".html").ParseFiles(listName + ".html")
68 | if err != nil {
69 | fmt.Fprintf(w, "template error %v", err)
70 | return
71 | }
72 | v := SCache.GetList(listName, page.StartRow, page.EndRow)
73 | ret := map[string]interface{}{
74 | "data": v,
75 | "page": page,
76 | }
77 | err = t.Execute(w, ret)
78 | if err != nil {
79 | fmt.Fprintf(w, "error %v", err)
80 | return
81 | }
82 | }
83 |
84 | func listSubmits(w http.ResponseWriter, r *http.Request) {
85 | listMessage(w, r, "list_message")
86 | }
87 |
88 | func listMo(w http.ResponseWriter, r *http.Request) {
89 | listMessage(w, r, "list_mo")
90 | }
91 |
92 | func Serve(config *Config) {
93 | http.HandleFunc("/send", handler)
94 | http.HandleFunc("/", index)
95 | http.HandleFunc("/list_message", listSubmits)
96 | http.HandleFunc("/list_mo", listMo)
97 | log.Fatal(http.ListenAndServe(config.HttpHost+":"+config.HttpPort, nil))
98 | }
99 |
--------------------------------------------------------------------------------
/gateway/models.go:
--------------------------------------------------------------------------------
1 | package gateway
2 |
3 | import "time"
4 |
5 | type SmsMes struct {
6 | Src string
7 | Dest string
8 | Content string
9 | MsgId string
10 | Created time.Time
11 | SubmitResult uint32
12 | DelivleryResult uint32
13 | }
14 |
15 | type MesSlice []SmsMes
16 |
17 | func (c MesSlice) Len() int {
18 | return len(c)
19 | }
20 |
21 | func (c MesSlice) Swap(i, j int) {
22 | c[i], c[j] = c[j], c[i]
23 | }
24 |
25 | func (c MesSlice) Less(i, j int) bool {
26 | return c[i].Created.Before(c[j].Created)
27 | }
28 |
--------------------------------------------------------------------------------
/gateway/utils_test.go:
--------------------------------------------------------------------------------
1 | package gateway
2 |
3 | import (
4 | "fmt"
5 | //"strconv"
6 | "testing"
7 | )
8 |
9 | func TestInsert(t *testing.T) {
10 | list := New()
11 | list.PushFront("1")
12 | list.PushFront("2")
13 | list.PushFront("3")
14 | list.PushFront("4")
15 |
16 | fmt.Println(list.Front())
17 | fmt.Println("first next :", list.Front())
18 | fmt.Println("first prev :", list.Back())
19 |
20 | //fmt.Println(list.head)
21 | //fmt.Println(list.last.prev)
22 | //for i, value := range list {
23 | // fmt.Println(strconv.FormatUint(i, 10) + ":" + value)
24 | //}
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/list_message.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | 消息列表
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
22 |
23 |
44 |
45 |
历史记录
46 |
当前第{{.page.CurrentPage}}页, 一共{{.page.TotalPage}}页
47 |
48 |
49 |
50 |
51 | 接收号码 |
52 | 内容 |
53 | 时间 |
54 | 消息ID |
55 | 状态 |
56 |
57 |
58 |
59 |
60 | {{range .data}}
61 |
62 | {{.Dest}} |
63 | {{.Content}} |
64 | {{.Created}} |
65 | {{.MsgId}} |
66 | {{.SubmitResult}} |
67 |
68 | {{end}}
69 |
70 |
71 |
72 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/list_mo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | 上行短信
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
22 |
23 |
44 |
45 |
历史记录
46 |
当前第{{.page.CurrentPage}}页, 一共{{.page.TotalPage}}页
47 |
48 |
49 |
50 | 发送号码 |
51 | 接收号码 |
52 | 内容 |
53 | 时间 |
54 | 消息ID |
55 |
56 |
57 |
58 |
59 | {{range .data}}
60 |
61 | {{.Src}} |
62 | {{.Dest}} |
63 | {{.Content}} |
64 | {{.Created}} |
65 | {{.MsgId}} |
66 |
67 | {{end}}
68 |
69 |
70 |
71 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/json"
5 | "flag"
6 | "github.com/JoeCao/cmpp-gateway/gateway"
7 | "io/ioutil"
8 | "log"
9 | "os"
10 | )
11 |
12 | func main() {
13 | //
14 | var configPath string
15 | var config = &gateway.Config{}
16 |
17 | //
18 | flag.StringVar(&configPath, "c", "", "配置文件路径")
19 | flag.Parse()
20 | if configPath == "" {
21 | configPath = "./config.json"
22 | }
23 | //
24 | err := LoadJsonFile(configPath, config)
25 | if err == nil {
26 | log.Println("加载成功 => ", config)
27 | } else {
28 | log.Fatal("加载失败 ", configPath, " => ", err)
29 | }
30 | go gateway.StartClient(config)
31 | go gateway.StartCmdLine()
32 |
33 | go gateway.StartCache(config)
34 | defer gateway.StopCache()
35 | go gateway.Serve(config)
36 |
37 | <-gateway.Abort
38 | }
39 |
40 | func LoadJsonFile(filePath string, obj interface{}) error {
41 | data, err := ReadBytes(filePath)
42 | if err != nil {
43 | return err
44 | }
45 | err = json.Unmarshal(data, obj)
46 | if err != nil {
47 | return err
48 | }
49 | return nil
50 | }
51 |
52 | func ReadBytes(filePath string) ([]byte, error) {
53 | file, err := os.Open(filePath)
54 | if err != nil {
55 | return nil, err
56 | }
57 | defer file.Close()
58 | data, err := ioutil.ReadAll(file)
59 | if err != nil {
60 | return nil, err
61 | }
62 | return data, nil
63 | }
64 |
--------------------------------------------------------------------------------
/ne1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/ne1.png
--------------------------------------------------------------------------------
/pages/pages.go:
--------------------------------------------------------------------------------
1 | package pages
2 |
3 | import "math"
4 |
5 | type Page struct {
6 | CurrentPage int
7 | LastPage int
8 | NextPage int
9 | TotalPage int
10 | StartRow int
11 | EndRow int
12 | IsEnd bool
13 | IsFirst bool
14 | PageSize int
15 | }
16 |
17 | func NewPage(current, size, length int) Page {
18 | page := Page{CurrentPage: current, PageSize: size}
19 | page.calPages(length)
20 | return page
21 | }
22 |
23 | func (p *Page) calPages(length int) {
24 | d := float64(length) / float64(p.PageSize)
25 | p.TotalPage = int(math.Ceil(d))
26 | if p.CurrentPage == 1 {
27 | p.LastPage = 1
28 | p.IsFirst = true
29 | } else {
30 | p.LastPage = p.CurrentPage - 1
31 | p.IsFirst = false
32 | }
33 | p.StartRow = p.CurrentPage*p.PageSize - p.PageSize
34 | if p.CurrentPage >= p.TotalPage {
35 | p.NextPage = p.TotalPage
36 | p.IsEnd = true
37 | } else {
38 | p.NextPage = p.CurrentPage + 1
39 | p.IsEnd = false
40 | }
41 | p.EndRow = p.CurrentPage*p.PageSize - 1
42 | }
43 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 | *.a
4 | *.so
5 |
6 | # Folders
7 | _obj
8 | _test
9 |
10 | # Architecture specific extensions/prefixes
11 | *.[568vq]
12 | [568vq].out
13 |
14 | *.cgo1.go
15 | *.cgo2.c
16 | _cgo_defun.c
17 | _cgo_gotypes.go
18 | _cgo_export.*
19 |
20 | _testmain.go
21 |
22 | *.exe
23 | *.test
24 | *.prof
25 |
26 | *.swp
27 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | go:
4 | - 1.5.1
5 | - tip
6 | os:
7 | - linux
8 | - osx
9 | - windows
10 |
11 | env:
12 | - GO15VENDOREXPERIMENT="1"
13 |
14 | script:
15 | - make
16 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/Makefile:
--------------------------------------------------------------------------------
1 | all: examples build test
2 |
3 | build:
4 | go build
5 | go build ./utils
6 |
7 | test:
8 | go test
9 | go test ./utils
10 |
11 | examples: ./examples/server/server ./examples/client/client
12 |
13 | ./examples/server/server: ./examples/server/server.go
14 | go build -o $@ $^
15 |
16 | ./examples/client/client: ./examples/client/client.go
17 | go build -o $@ $^
18 |
19 |
20 | clean:
21 | go clean ./...
22 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/activetest.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmpp
15 |
16 | import "encoding/binary"
17 |
18 | // Packet length const for cmpp active test request and response packets.
19 | const (
20 | CmppActiveTestReqPktLen uint32 = 12 //12d, 0xc
21 | CmppActiveTestRspPktLen uint32 = 12 + 1 //13d, 0xd
22 | )
23 |
24 | type CmppActiveTestReqPkt struct {
25 | // session info
26 | SeqId uint32
27 | }
28 | type CmppActiveTestRspPkt struct {
29 | Reserved uint8
30 | // session info
31 | SeqId uint32
32 | }
33 |
34 | // Pack packs the CmppActiveTestReqPkt to bytes stream for client side.
35 | func (p *CmppActiveTestReqPkt) Pack(seqId uint32) ([]byte, error) {
36 | var pktLen = CmppActiveTestReqPktLen
37 |
38 | var w = newPacketWriter(pktLen)
39 |
40 | // Pack header
41 | w.WriteInt(binary.BigEndian, pktLen)
42 | w.WriteInt(binary.BigEndian, CMPP_ACTIVE_TEST)
43 | w.WriteInt(binary.BigEndian, seqId)
44 | p.SeqId = seqId
45 |
46 | return w.Bytes()
47 | }
48 |
49 | // Unpack unpack the binary byte stream to a CmppActiveTestReqPkt variable.
50 | // After unpack, you will get all value of fields in
51 | // CmppActiveTestReqPkt struct.
52 | func (p *CmppActiveTestReqPkt) Unpack(data []byte) error {
53 | var r = newPacketReader(data)
54 |
55 | // Sequence Id
56 | r.ReadInt(binary.BigEndian, &p.SeqId)
57 | return r.Error()
58 | }
59 |
60 | // Pack packs the CmppActiveTestRspPkt to bytes stream for client side.
61 | func (p *CmppActiveTestRspPkt) Pack(seqId uint32) ([]byte, error) {
62 | var pktLen = CmppActiveTestRspPktLen
63 |
64 | var w = newPacketWriter(pktLen)
65 |
66 | // Pack header
67 | w.WriteInt(binary.BigEndian, pktLen)
68 | w.WriteInt(binary.BigEndian, CMPP_ACTIVE_TEST_RESP)
69 | w.WriteInt(binary.BigEndian, seqId)
70 | w.WriteByte(p.Reserved)
71 | p.SeqId = seqId
72 |
73 | return w.Bytes()
74 | }
75 |
76 | // Unpack unpack the binary byte stream to a CmppActiveTestRspPkt variable.
77 | // After unpack, you will get all value of fields in
78 | // CmppActiveTestRspPkt struct.
79 | func (p *CmppActiveTestRspPkt) Unpack(data []byte) error {
80 | var r = newPacketReader(data)
81 |
82 | // Sequence Id
83 | r.ReadInt(binary.BigEndian, &p.SeqId)
84 | p.Reserved = r.ReadByte()
85 | return r.Error()
86 | }
87 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/conn_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmpp_test
15 |
16 | import (
17 | "bytes"
18 | "io"
19 | "net"
20 | "testing"
21 |
22 | "github.com/bigwhite/gocmpp"
23 | )
24 |
25 | var data = []byte{
26 | 0x00, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00,
27 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00,
28 | 0x00, 0x00, 0x02, 0x31, 0x33, 0x35, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x00, 0x00,
29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x39, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x32, 0x31,
31 | 0x30, 0x00, 0x00, 0x00, 0x00, 0x31, 0x35, 0x31, 0x31, 0x30, 0x35, 0x31, 0x33, 0x31, 0x35, 0x35,
32 | 0x35, 0x31, 0x30, 0x31, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x30, 0x30, 0x30, 0x30, 0x31, 0x00, 0x00, 0x00,
34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x31, 0x33, 0x35,
35 | 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x6d,
37 | 0x4b, 0x8b, 0xd5, 0x00, 0x67, 0x00, 0x6f, 0x00, 0x63, 0x00, 0x6d, 0x00, 0x70, 0x00, 0x70, 0x00,
38 | 0x20, 0x00, 0x73, 0x00, 0x75, 0x00, 0x62, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x74, 0x00, 0x00, 0x00,
39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 | 0x00,
41 | }
42 |
43 | type fakeConn struct {
44 | net.Conn
45 | reader *bytes.Buffer
46 | }
47 |
48 | func (c *fakeConn) Read(b []byte) (n int, err error) {
49 | n, err = c.reader.Read(b)
50 | if err == io.EOF {
51 | c.reader = bytes.NewBuffer(data)
52 | n, err = c.reader.Read(b)
53 | }
54 | return
55 | }
56 |
57 | func BenchmarkRecvAndUnpackPkt(b *testing.B) {
58 | c := &cmpp.Conn{
59 | Conn: &fakeConn{
60 | reader: bytes.NewBuffer(data),
61 | },
62 | State: cmpp.CONN_AUTHOK,
63 | Typ: cmpp.V30,
64 | }
65 |
66 | for i := 0; i < b.N; i++ {
67 | c.RecvAndUnpackPkt(0)
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/examples/server/server.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "crypto/md5"
6 | "log"
7 | "time"
8 |
9 | "github.com/bigwhite/gocmpp"
10 | "github.com/bigwhite/gocmpp/utils"
11 | )
12 |
13 | const (
14 | userS string = "900001"
15 | passwordS string = "888888"
16 | )
17 |
18 | func handleLogin(r *cmpp.Response, p *cmpp.Packet, l *log.Logger) (bool, error) {
19 | req, ok := p.Packer.(*cmpp.CmppConnReqPkt)
20 | if !ok {
21 | // not a connect request, ignore it,
22 | // go on to next handler
23 | return true, nil
24 | }
25 |
26 | resp := r.Packer.(*cmpp.Cmpp3ConnRspPkt)
27 |
28 | // validate the user and password
29 | // set the status in the connect response.
30 | resp.Version = 0x30
31 | addr := req.SrcAddr
32 | if addr != userS {
33 | l.Println("handleLogin error:", cmpp.ConnRspStatusErrMap[cmpp.ErrnoConnInvalidSrcAddr])
34 | resp.Status = uint32(cmpp.ErrnoConnInvalidSrcAddr)
35 | return false, cmpp.ConnRspStatusErrMap[cmpp.ErrnoConnInvalidSrcAddr]
36 | }
37 |
38 | tm := req.Timestamp
39 | authSrc := md5.Sum(bytes.Join([][]byte{[]byte(userS),
40 | make([]byte, 9),
41 | []byte(passwordS),
42 | []byte(cmpputils.TimeStamp2Str(tm))},
43 | nil))
44 |
45 | if req.AuthSrc != string(authSrc[:]) {
46 | l.Println("handleLogin error: ", cmpp.ConnRspStatusErrMap[cmpp.ErrnoConnAuthFailed])
47 | resp.Status = uint32(cmpp.ErrnoConnAuthFailed)
48 | return false, cmpp.ConnRspStatusErrMap[cmpp.ErrnoConnAuthFailed]
49 | }
50 |
51 | authIsmg := md5.Sum(bytes.Join([][]byte{[]byte{byte(resp.Status)},
52 | authSrc[:],
53 | []byte(passwordS)},
54 | nil))
55 | resp.AuthIsmg = string(authIsmg[:])
56 | l.Printf("handleLogin: %s login ok\n", addr)
57 |
58 | return false, nil
59 | }
60 |
61 | func handleSubmit(r *cmpp.Response, p *cmpp.Packet, l *log.Logger) (bool, error) {
62 | req, ok := p.Packer.(*cmpp.Cmpp3SubmitReqPkt)
63 | if !ok {
64 | return true, nil // go on to next handler
65 | }
66 |
67 | resp := r.Packer.(*cmpp.Cmpp3SubmitRspPkt)
68 | resp.MsgId = 12878564852733378560 //0xb2, 0xb9, 0xda, 0x80, 0x00, 0x01, 0x00, 0x00
69 | for i, d := range req.DestTerminalId {
70 | l.Printf("handleSubmit: handle submit from %s ok! msgid[%d], srcId[%s], destTerminalId[%s]\n",
71 | req.MsgSrc, resp.MsgId+uint64(i), req.SrcId, d)
72 | content, _ := cmpputils.Ucs2ToUtf8(req.MsgContent)
73 | l.Printf("sms content is %s", content)
74 | }
75 | return true, nil
76 | }
77 |
78 | func main() {
79 | var handlers = []cmpp.Handler{
80 | cmpp.HandlerFunc(handleLogin),
81 | cmpp.HandlerFunc(handleSubmit),
82 | }
83 |
84 | err := cmpp.ListenAndServe(":8888",
85 | cmpp.V30,
86 | 5*time.Second,
87 | 3,
88 | nil,
89 | handlers...,
90 | )
91 | if err != nil {
92 | log.Println("cmpp ListenAndServ error:", err)
93 | }
94 | return
95 | }
96 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/fwd/corpus/0:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/fuzztest/fwd/corpus/0
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/fwd/fuzz.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // httpg//www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | // +build gofuzz
15 |
16 | package cmppfuzz
17 |
18 | import (
19 | "github.com/bigwhite/gocmpp"
20 | )
21 |
22 | func Fuzz(data []byte) int {
23 | p := &cmpp.Cmpp2FwdReqPkt{}
24 | if err := p.Unpack(data); err != nil {
25 | return 0
26 | }
27 | return 1
28 | }
29 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/fwd/gen/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package main
15 |
16 | import (
17 | "github.com/dvyukov/go-fuzz/gen"
18 | )
19 |
20 | func main() {
21 | data := []byte{
22 | 0x00, 0x00, 0x00, 0x17, 0x31, 0x30, 0x30, 0x32,
23 | 0x30, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24 | 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 | 0x02, 0x31, 0x33, 0x35, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x00, 0x00, 0x00, 0x00,
26 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x33, 0x32, 0x31, 0x33, 0x32, 0x31, 0x30,
27 | 0x32, 0x31, 0x30, 0x00, 0x00, 0x00, 0x00, 0x31, 0x35, 0x31, 0x31, 0x31, 0x35, 0x31, 0x33, 0x31,
28 | 0x35, 0x35, 0x35, 0x31, 0x30, 0x31, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x39, 0x39, 0x39, 0x38, 0x38, 0x38,
30 | 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x31,
31 | 0x33, 0x35, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 | 0x00, 0x00, 0x00, 0x00, 0x18, 0x6d, 0x4b, 0x8b, 0xd5, 0x00, 0x67, 0x00, 0x6f, 0x00, 0x63, 0x00,
33 | 0x6d, 0x00, 0x70, 0x00, 0x70, 0x00, 0x20, 0x00, 0x66, 0x00, 0x77, 0x00, 0x64, 0x00, 0x00, 0x00,
34 | 0x00, 0x00, 0x00, 0x00, 0x00,
35 | }
36 | gen.Emit(data, nil, true)
37 | }
38 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/0:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/0
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/413e7948416c5f6399d032f9aad69356c58428ab-1:
--------------------------------------------------------------------------------
1 | test 689
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/69a155acb4ae42e3cc8691b376d4a3a822fcf916-1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/69a155acb4ae42e3cc8691b376d4a3a822fcf916-1
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/983f5232a24d1d3e195b9ad1bc02060ca59efbcd-1:
--------------------------------------------------------------------------------
1 | i t
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/a10909c2cdcaf5adb7e6b092a4faba558b62bd96-1:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/a34cb30c810e427518386c86199cdf6b1a6275ea-1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/a34cb30c810e427518386c86199cdf6b1a6275ea-1
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/b9d74ec2b9f27fd6ac12402606c56ac1fd39bdd2-1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/b9d74ec2b9f27fd6ac12402606c56ac1fd39bdd2-1
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/da39a3ee5e6b4b0d3255bfef95601890afd80709-1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/da39a3ee5e6b4b0d3255bfef95601890afd80709-1
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/e7f8e0514e4bc345f73c136dbaf17aabdffeb78d-1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/corpus/e7f8e0514e4bc345f73c136dbaf17aabdffeb78d-1
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/fuzz.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // httpg//www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | // +build gofuzz
15 |
16 | package cmppfuzz
17 |
18 | import (
19 | "github.com/bigwhite/gocmpp"
20 | )
21 |
22 | func Fuzz(data []byte) int {
23 | p := &cmpp.Cmpp2SubmitReqPkt{}
24 | if err := p.Unpack(data); err != nil {
25 | return 0
26 | }
27 | return 1
28 | }
29 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/fuzztest/submit/gen/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package main
15 |
16 | import (
17 | "github.com/dvyukov/go-fuzz/gen"
18 | )
19 |
20 | func main() {
21 | data := []byte{
22 | 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00,
23 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00,
24 | 0x00, 0x00, 0x02, 0x31, 0x33, 0x35, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x00, 0x00,
25 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x39, 0x30, 0x30, 0x30, 0x30,
26 | 0x31, 0x30, 0x32, 0x31, 0x30, 0x00, 0x00, 0x00, 0x00, 0x31, 0x35, 0x31, 0x31, 0x30, 0x35, 0x31,
27 | 0x33, 0x31, 0x35, 0x35, 0x35, 0x31, 0x30, 0x31, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x30, 0x30, 0x30, 0x30,
29 | 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 | 0x01, 0x31, 0x33, 0x35, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x00, 0x00, 0x00, 0x00,
31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x6d, 0x4b, 0x8b, 0xd5, 0x00, 0x67, 0x00, 0x6f, 0x00,
32 | 0x63, 0x00, 0x6d, 0x00, 0x70, 0x00, 0x70, 0x00, 0x20, 0x00, 0x73, 0x00, 0x75, 0x00, 0x62, 0x00,
33 | 0x6d, 0x00, 0x69, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 | }
35 |
36 | gen.Emit(data, nil, true)
37 | }
38 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/receipt.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmpp
15 |
16 | import "encoding/binary"
17 |
18 | // Packet length const for cmpp receipt packet.
19 | const (
20 | CmppReceiptPktLen uint32 = 60 //60d, 0x3c
21 | )
22 |
23 | type CmppReceiptPkt struct {
24 | MsgId uint64
25 | Stat string
26 | SubmitTime string // YYMMDDHHMM
27 | DoneTime string // YYMMDDHHMM
28 | DestTerminalId string
29 | SmscSequence uint32
30 | }
31 |
32 | // Pack packs the CmppReceiptPkt to bytes stream for client side.
33 | func (p *CmppReceiptPkt) Pack() ([]byte, error) {
34 | var pktLen uint32 = CmppReceiptPktLen
35 |
36 | var w = newPacketWriter(pktLen)
37 |
38 | w.WriteInt(binary.BigEndian, p.MsgId)
39 | w.WriteFixedSizeString(p.Stat, 7)
40 | w.WriteFixedSizeString(p.SubmitTime, 10)
41 | w.WriteFixedSizeString(p.DoneTime, 10)
42 | w.WriteFixedSizeString(p.DestTerminalId, 21)
43 | w.WriteInt(binary.BigEndian, p.SmscSequence)
44 |
45 | return w.Bytes()
46 | }
47 |
48 | // Unpack unpack the binary byte stream to a CmppReceiptPkt variable.
49 | // After unpack, you will get all value of fields in
50 | // CmppReceiptPkt struct.
51 | func (p *CmppReceiptPkt) Unpack(data []byte) error {
52 | var r = newPacketReader(data)
53 |
54 | r.ReadInt(binary.BigEndian, &p.MsgId)
55 |
56 | stat := r.ReadCString(7)
57 | p.Stat = string(stat)
58 |
59 | submitTime := r.ReadCString(10)
60 | p.SubmitTime = string(submitTime)
61 |
62 | doneTime := r.ReadCString(10)
63 | p.DoneTime = string(doneTime)
64 |
65 | destTerminalId := r.ReadCString(21)
66 | p.DestTerminalId = string(destTerminalId)
67 |
68 | r.ReadInt(binary.BigEndian, &p.SmscSequence)
69 | return r.Error()
70 | }
71 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/receipt_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmpp_test
15 |
16 | import (
17 | "testing"
18 |
19 | "github.com/bigwhite/gocmpp"
20 | )
21 |
22 | func TestCmppReceiptPktPack(t *testing.T) {
23 | p := &cmpp.CmppReceiptPkt{
24 | MsgId: 13025908756704198656,
25 | Stat: "DELIVRD",
26 | SubmitTime: "1511120955",
27 | DoneTime: "1511120957",
28 | DestTerminalId: "13412340000",
29 | SmscSequence: 0x12345678,
30 | }
31 |
32 | data, err := p.Pack()
33 | if err != nil {
34 | t.Fatal("CmppReceiptPkt pack error:", err)
35 | }
36 |
37 | dataExpected := []byte{
38 | 0xb4, 0xc5, 0x53, 0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x45, 0x4c, 0x49, 0x56, 0x52, 0x44, 0x31,
39 | 0x35, 0x31, 0x31, 0x31, 0x32, 0x30, 0x39, 0x35, 0x35, 0x31, 0x35, 0x31, 0x31, 0x31, 0x32, 0x30,
40 | 0x39, 0x35, 0x37, 0x31, 0x33, 0x34, 0x31, 0x32, 0x33, 0x34, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00,
41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78,
42 | }
43 |
44 | l1 := len(data)
45 | l2 := len(dataExpected)
46 | if l1 != l2 {
47 | t.Fatalf("After pack, data length is %d, not equal to length expected: %d\n", l1, l2)
48 | }
49 |
50 | for i := 0; i < l1; i++ {
51 | if data[i] != dataExpected[i] {
52 | t.Fatalf("After pack, data[%d] is %x, not equal to dataExpected[%d]: %x\n", i, data[i], i, dataExpected[i])
53 | }
54 | }
55 | }
56 |
57 | func TestCmppReceiptPktUnpack(t *testing.T) {
58 | data := []byte{
59 | 0xb4, 0xc5, 0x53, 0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x45, 0x4c, 0x49, 0x56, 0x52, 0x44, 0x31,
60 | 0x35, 0x31, 0x31, 0x31, 0x32, 0x30, 0x39, 0x35, 0x35, 0x31, 0x35, 0x31, 0x31, 0x31, 0x32, 0x30,
61 | 0x39, 0x35, 0x37, 0x31, 0x33, 0x34, 0x31, 0x32, 0x33, 0x34, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00,
62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78,
63 | }
64 |
65 | p := &cmpp.CmppReceiptPkt{}
66 | err := p.Unpack(data)
67 | if err != nil {
68 | t.Fatal("CmppReceiptPkt unpack error:", err)
69 | }
70 |
71 | var resultSet = []struct {
72 | name string
73 | value interface{}
74 | expectedValue interface{}
75 | }{
76 | {"MsgId", p.MsgId, uint64(13025908756704198656)},
77 | {"Stat", p.Stat, "DELIVRD"},
78 | {"SubmitTime", p.SubmitTime, "1511120955"},
79 | {"DoneTime", p.DoneTime, "1511120957"},
80 | {"DestTerminalId", p.DestTerminalId, "13412340000"},
81 | {"SmscSequence", p.SmscSequence, uint32(0x12345678)},
82 | }
83 |
84 | for _, r := range resultSet {
85 | if r.value != r.expectedValue {
86 | t.Fatalf("After unpack, %s in packet is %#v, not equal to the expected value: %#v\n", r.name, r.value, r.expectedValue)
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/terminate.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmpp
15 |
16 | import "encoding/binary"
17 |
18 | // Packet length const for cmpp terminate request and response packets.
19 | const (
20 | CmppTerminateReqPktLen uint32 = 12 //12d, 0xc
21 | CmppTerminateRspPktLen uint32 = 12 //12d, 0xc
22 | )
23 |
24 | type CmppTerminateReqPkt struct {
25 | // session info
26 | SeqId uint32
27 | }
28 | type CmppTerminateRspPkt struct {
29 | // session info
30 | SeqId uint32
31 | }
32 |
33 | // Pack packs the CmppTerminateReqPkt to bytes stream for client side.
34 | func (p *CmppTerminateReqPkt) Pack(seqId uint32) ([]byte, error) {
35 | var pktLen = CmppTerminateReqPktLen
36 |
37 | var w = newPacketWriter(pktLen)
38 |
39 | // Pack header
40 | w.WriteInt(binary.BigEndian, pktLen)
41 | w.WriteInt(binary.BigEndian, CMPP_TERMINATE)
42 | w.WriteInt(binary.BigEndian, seqId)
43 | p.SeqId = seqId
44 |
45 | return w.Bytes()
46 | }
47 |
48 | // Unpack unpack the binary byte stream to a CmppTerminateReqPkt variable.
49 | // After unpack, you will get all value of fields in
50 | // CmppTerminateReqPkt struct.
51 | func (p *CmppTerminateReqPkt) Unpack(data []byte) error {
52 | var r = newPacketReader(data)
53 |
54 | // Sequence Id
55 | r.ReadInt(binary.BigEndian, &p.SeqId)
56 | return r.Error()
57 | }
58 |
59 | // Pack packs the CmppTerminateRspPkt to bytes stream for client side.
60 | func (p *CmppTerminateRspPkt) Pack(seqId uint32) ([]byte, error) {
61 | var pktLen = CmppTerminateRspPktLen
62 |
63 | var w = newPacketWriter(pktLen)
64 |
65 | // Pack header
66 | w.WriteInt(binary.BigEndian, pktLen)
67 | w.WriteInt(binary.BigEndian, CMPP_TERMINATE_RESP)
68 | w.WriteInt(binary.BigEndian, seqId)
69 | p.SeqId = seqId
70 |
71 | return w.Bytes()
72 | }
73 |
74 | // Unpack unpack the binary byte stream to a CmppTerminateRspPkt variable.
75 | // After unpack, you will get all value of fields in
76 | // CmppTerminateRspPkt struct.
77 | func (p *CmppTerminateRspPkt) Unpack(data []byte) error {
78 | var r = newPacketReader(data)
79 |
80 | // Sequence Id
81 | r.ReadInt(binary.BigEndian, &p.SeqId)
82 | return r.Error()
83 | }
84 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/utils/utils.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmpputils
15 |
16 | import (
17 | "bytes"
18 | "errors"
19 | "fmt"
20 | "io/ioutil"
21 | "unicode/utf8"
22 | "unsafe"
23 |
24 | "golang.org/x/text/encoding/simplifiedchinese"
25 | "golang.org/x/text/encoding/unicode"
26 | "golang.org/x/text/transform"
27 | )
28 |
29 | var ErrInvalidUtf8Rune = errors.New("Not Invalid Utf8 runes")
30 |
31 | func IsBigEndian() bool {
32 | var i uint16 = 0x1234
33 | var p *[2]byte = (*[2]byte)(unsafe.Pointer(&i))
34 | if (*p)[0] == 0x12 {
35 | return true
36 | }
37 | return false
38 | }
39 |
40 | // TimeStamp2Str converts a timestamp(MMDDHHMMSS) int to a string(10 bytes).
41 | func TimeStamp2Str(t uint32) string {
42 | return fmt.Sprintf("%010d", t)
43 | }
44 |
45 | func Utf8ToUcs2(in string) (string, error) {
46 | if !utf8.ValidString(in) {
47 | return "", ErrInvalidUtf8Rune
48 | }
49 |
50 | r := bytes.NewReader([]byte(in))
51 | t := transform.NewReader(r, unicode.All[1].NewEncoder()) //UTF-16 bigendian, no-bom
52 | out, err := ioutil.ReadAll(t)
53 | if err != nil {
54 | return "", err
55 | }
56 | return string(out), nil
57 | }
58 |
59 | func Ucs2ToUtf8(in string) (string, error) {
60 | r := bytes.NewReader([]byte(in))
61 | t := transform.NewReader(r, unicode.All[1].NewDecoder()) //UTF-16 bigendian, no-bom
62 | out, err := ioutil.ReadAll(t)
63 | if err != nil {
64 | return "", err
65 | }
66 | return string(out), nil
67 | }
68 |
69 | func Utf8ToGB18030(in string) (string, error) {
70 | if !utf8.ValidString(in) {
71 | return "", ErrInvalidUtf8Rune
72 | }
73 |
74 | r := bytes.NewReader([]byte(in))
75 | t := transform.NewReader(r, simplifiedchinese.GB18030.NewEncoder())
76 | out, err := ioutil.ReadAll(t)
77 | if err != nil {
78 | return "", err
79 | }
80 | return string(out), nil
81 | }
82 |
83 | func GB18030ToUtf8(in string) (string, error) {
84 | r := bytes.NewReader([]byte(in))
85 | t := transform.NewReader(r, simplifiedchinese.GB18030.NewDecoder())
86 | out, err := ioutil.ReadAll(t)
87 | if err != nil {
88 | return "", err
89 | }
90 | return string(out), nil
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/utils/utils_amd64_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Tony Bai.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package cmpputils_test
15 |
16 | import (
17 | "testing"
18 |
19 | "github.com/bigwhite/gocmpp/utils"
20 | )
21 |
22 | func TestIsBigEndian(t *testing.T) {
23 | b := cmpputils.IsBigEndian()
24 | if b {
25 | t.Errorf("The result of IsBigEndian is %v on Amd64 arch\n", b)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at http://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Go
2 |
3 | Go is an open source project.
4 |
5 | It is the work of hundreds of contributors. We appreciate your help!
6 |
7 |
8 | ## Filing issues
9 |
10 | When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
11 |
12 | 1. What version of Go are you using (`go version`)?
13 | 2. What operating system and processor architecture are you using?
14 | 3. What did you do?
15 | 4. What did you expect to see?
16 | 5. What did you see instead?
17 |
18 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
19 | The gophers there will answer or ask you to file an issue if you've tripped over a bug.
20 |
21 | ## Contributing code
22 |
23 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
24 | before sending patches.
25 |
26 | **We do not accept GitHub pull requests**
27 | (we use [Gerrit](https://code.google.com/p/gerrit/) instead for code review).
28 |
29 | Unless otherwise noted, the Go source files are distributed under
30 | the BSD-style license found in the LICENSE file.
31 |
32 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at http://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the Go project.
5 |
6 | Google hereby grants to You a perpetual, worldwide, non-exclusive,
7 | no-charge, royalty-free, irrevocable (except as stated in this section)
8 | patent license to make, have made, use, offer to sell, sell, import,
9 | transfer and otherwise run, modify and propagate the contents of this
10 | implementation of Go, where such license applies only to those patent
11 | claims, both currently owned or controlled by Google and acquired in
12 | the future, licensable by Google that are necessarily infringed by this
13 | implementation of Go. This grant does not include claims that would be
14 | infringed only as a consequence of further modification of this
15 | implementation. If you or your agent or exclusive licensee institute or
16 | order or agree to the institution of patent litigation against any
17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging
18 | that this implementation of Go or any code incorporated within this
19 | implementation of Go constitutes direct or contributory patent
20 | infringement, or inducement of patent infringement, then any patent
21 | rights granted to you under this License for this implementation of Go
22 | shall terminate as of the date such litigation is filed.
23 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/README:
--------------------------------------------------------------------------------
1 | This repository holds supplementary Go libraries for text processing, many involving Unicode.
2 |
3 | To submit changes to this repository, see http://golang.org/doc/contribute.html.
4 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/bidi/bidi.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:generate go run gen.go gen_trieval.go gen_ranges.go
6 |
7 | // Package bidi contains functionality for bidirectional text support.
8 | //
9 | // See http://www.unicode.org/reports/tr9.
10 | //
11 | // NOTE: Under construction.
12 | package bidi
13 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/bidi/gen_ranges.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build ignore
6 |
7 | package main
8 |
9 | import (
10 | "unicode"
11 |
12 | "golang.org/x/text/internal/gen"
13 | "golang.org/x/text/internal/ucd"
14 | "golang.org/x/text/unicode/rangetable"
15 | )
16 |
17 | // These tables are hand-extracted from:
18 | // http://www.unicode.org/Public/8.0.0/ucd/extracted/DerivedBidiClass.txt
19 | func visitDefaults(fn func(r rune, c class)) {
20 | // first write default values for ranges listed above.
21 | visitRunes(fn, _AL, []rune{
22 | 0x0600, 0x07BF, // Arabic
23 | 0x08A0, 0x08FF, // Arabic Extended-A
24 | 0xFB50, 0xFDCF, // Arabic Presentation Forms
25 | 0xFDF0, 0xFDFF,
26 | 0xFE70, 0xFEFF,
27 | 0x0001EE00, 0x0001EEFF, // Arabic Mathematical Alpha Symbols
28 | })
29 | visitRunes(fn, _R, []rune{
30 | 0x0590, 0x05FF, // Hebrew
31 | 0x07C0, 0x089F, // Nko et al.
32 | 0xFB1D, 0xFB4F,
33 | 0x00010800, 0x00010FFF, // Cypriot Syllabary et. al.
34 | 0x0001E800, 0x0001EDFF,
35 | 0x0001EF00, 0x0001EFFF,
36 | })
37 | visitRunes(fn, _ET, []rune{ // European Terminator
38 | 0x20A0, 0x20Cf, // Currency symbols
39 | })
40 | rangetable.Visit(unicode.Noncharacter_Code_Point, func(r rune) {
41 | fn(r, _BN) // Boundary Neutral
42 | })
43 | ucd.Parse(gen.OpenUCDFile("DerivedCoreProperties.txt"), func(p *ucd.Parser) {
44 | if p.String(1) == "Default_Ignorable_Code_Point" {
45 | fn(p.Rune(0), _BN) // Boundary Neutral
46 | }
47 | })
48 | }
49 |
50 | func visitRunes(fn func(r rune, c class), c class, runes []rune) {
51 | for i := 0; i < len(runes); i += 2 {
52 | lo, hi := runes[i], runes[i+1]
53 | for j := lo; j <= hi; j++ {
54 | fn(j, c)
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/bidi/gen_trieval.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build ignore
6 |
7 | package main
8 |
9 | type class int
10 |
11 | const (
12 | _L class = iota // LeftToRight
13 | _R // RightToLeft
14 | _EN // EuropeanNumber
15 | _ES // EuropeanSeparator
16 | _ET // EuropeanTerminator
17 | _AN // ArabicNumber
18 | _CS // CommonSeparator
19 | _B // ParagraphSeparator
20 | _S // SegmentSeparator
21 | _WS // WhiteSpace
22 | _ON // OtherNeutral
23 | _BN // BoundaryNeutral
24 | _NSM // NonspacingMark
25 | _AL // ArabicLetter
26 | classControl // Control LRO - PDI
27 |
28 | numClass
29 |
30 | _LRO // LeftToRightOverride
31 | _RLO // RightToLeftOverride
32 | _LRE // LeftToRightEmbedding
33 | _RLE // RightToLeftEmbedding
34 | _PDF // PopDirectionalFormat
35 | _LRI // LeftToRightIsolate
36 | _RLI // RightToLeftIsolate
37 | _FSI // FirstStrongIsolate
38 | _PDI // PopDirectionalIsolate
39 | )
40 |
41 | var controlToClass = map[rune]class{
42 | 0x202D: _LRO, // LeftToRightOverride,
43 | 0x202E: _RLO, // RightToLeftOverride,
44 | 0x202A: _LRE, // LeftToRightEmbedding,
45 | 0x202B: _RLE, // RightToLeftEmbedding,
46 | 0x202C: _PDF, // PopDirectionalFormat,
47 | 0x2066: _LRI, // LeftToRightIsolate,
48 | 0x2067: _RLI, // RightToLeftIsolate,
49 | 0x2068: _FSI, // FirstStrongIsolate,
50 | 0x2069: _PDI, // PopDirectionalIsolate,
51 | }
52 |
53 | // A trie entry has the following bits:
54 | // 7..5 XOR mask for brackets
55 | // 4 1: Bracket open, 0: Bracket close
56 | // 3..0 class type
57 | type entry uint8
58 |
59 | const (
60 | openMask = 0x10
61 | xorMaskShift = 5
62 | )
63 |
64 | func (e entry) isBracket() bool { return e&0xF0 != 0 }
65 | func (e entry) isOpen() bool { return e&openMask != 0 }
66 | func (e entry) reverseBracket(r rune) rune { return xorMasks[e>>xorMaskShift] ^ r }
67 | func (e entry) class(r rune) class {
68 | c := class(e & 0x0F)
69 | if c == classControl {
70 | return controlToClass[r]
71 | }
72 | return c
73 | }
74 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/bidi/ranges_test.go:
--------------------------------------------------------------------------------
1 | // This file was generated by go generate; DO NOT EDIT
2 |
3 | package bidi
4 |
5 | import (
6 | "unicode"
7 |
8 | "golang.org/x/text/internal/gen"
9 | "golang.org/x/text/internal/ucd"
10 | "golang.org/x/text/unicode/rangetable"
11 | )
12 |
13 | // These tables are hand-extracted from:
14 | // http://www.unicode.org/Public/8.0.0/ucd/extracted/DerivedBidiClass.txt
15 | func visitDefaults(fn func(r rune, c class)) {
16 | // first write default values for ranges listed above.
17 | visitRunes(fn, _AL, []rune{
18 | 0x0600, 0x07BF, // Arabic
19 | 0x08A0, 0x08FF, // Arabic Extended-A
20 | 0xFB50, 0xFDCF, // Arabic Presentation Forms
21 | 0xFDF0, 0xFDFF,
22 | 0xFE70, 0xFEFF,
23 | 0x0001EE00, 0x0001EEFF, // Arabic Mathematical Alpha Symbols
24 | })
25 | visitRunes(fn, _R, []rune{
26 | 0x0590, 0x05FF, // Hebrew
27 | 0x07C0, 0x089F, // Nko et al.
28 | 0xFB1D, 0xFB4F,
29 | 0x00010800, 0x00010FFF, // Cypriot Syllabary et. al.
30 | 0x0001E800, 0x0001EDFF,
31 | 0x0001EF00, 0x0001EFFF,
32 | })
33 | visitRunes(fn, _ET, []rune{ // European Terminator
34 | 0x20A0, 0x20Cf, // Currency symbols
35 | })
36 | rangetable.Visit(unicode.Noncharacter_Code_Point, func(r rune) {
37 | fn(r, _BN) // Boundary Neutral
38 | })
39 | ucd.Parse(gen.OpenUCDFile("DerivedCoreProperties.txt"), func(p *ucd.Parser) {
40 | if p.String(1) == "Default_Ignorable_Code_Point" {
41 | fn(p.Rune(0), _BN) // Boundary Neutral
42 | }
43 | })
44 | }
45 |
46 | func visitRunes(fn func(r rune, c class), c class, runes []rune) {
47 | for i := 0; i < len(runes); i += 2 {
48 | lo, hi := runes[i], runes[i+1]
49 | for j := lo; j <= hi; j++ {
50 | fn(j, c)
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/bidi/tables_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package bidi
6 |
7 | import (
8 | "flag"
9 | "testing"
10 |
11 | "golang.org/x/text/internal/gen"
12 | "golang.org/x/text/internal/ucd"
13 | )
14 |
15 | var long = flag.Bool("long", false,
16 | "run time-consuming tests, such as tests that fetch data online")
17 |
18 | var labels = []string{
19 | _AL: "AL",
20 | _AN: "AN",
21 | _B: "B",
22 | _BN: "BN",
23 | _CS: "CS",
24 | _EN: "EN",
25 | _ES: "ES",
26 | _ET: "ET",
27 | _L: "L",
28 | _NSM: "NSM",
29 | _ON: "ON",
30 | _R: "R",
31 | _S: "S",
32 | _WS: "WS",
33 |
34 | _LRO: "LRO",
35 | _RLO: "RLO",
36 | _LRE: "LRE",
37 | _RLE: "RLE",
38 | _PDF: "PDF",
39 | _LRI: "LRI",
40 | _RLI: "RLI",
41 | _FSI: "FSI",
42 | _PDI: "PDI",
43 | }
44 |
45 | func TestTables(t *testing.T) {
46 | if !*long {
47 | return
48 | }
49 |
50 | gen.Init()
51 |
52 | trie := newBidiTrie(0)
53 |
54 | ucd.Parse(gen.OpenUCDFile("BidiBrackets.txt"), func(p *ucd.Parser) {
55 | r1 := p.Rune(0)
56 | want := p.Rune(1)
57 |
58 | e, _ := trie.lookupString(string(r1))
59 | if got := entry(e).reverseBracket(r1); got != want {
60 | t.Errorf("Reverse(%U) = %U; want %U", r1, got, want)
61 | }
62 | })
63 |
64 | done := map[rune]bool{}
65 | test := func(name string, r rune, want string) {
66 | e, _ := trie.lookupString(string(r))
67 | if got := labels[entry(e).class(r)]; got != want {
68 | t.Errorf("%s:%U: got %s; want %s", name, r, got, want)
69 | }
70 | done[r] = true
71 | }
72 |
73 | // Insert the derived BiDi properties.
74 | ucd.Parse(gen.OpenUCDFile("extracted/DerivedBidiClass.txt"), func(p *ucd.Parser) {
75 | r := p.Rune(0)
76 | test("derived", r, p.String(1))
77 | })
78 | visitDefaults(func(r rune, c class) {
79 | if !done[r] {
80 | test("default", r, labels[c])
81 | }
82 | })
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/bidi/trieval.go:
--------------------------------------------------------------------------------
1 | // This file was generated by go generate; DO NOT EDIT
2 |
3 | package bidi
4 |
5 | type class int
6 |
7 | const (
8 | _L class = iota // LeftToRight
9 | _R // RightToLeft
10 | _EN // EuropeanNumber
11 | _ES // EuropeanSeparator
12 | _ET // EuropeanTerminator
13 | _AN // ArabicNumber
14 | _CS // CommonSeparator
15 | _B // ParagraphSeparator
16 | _S // SegmentSeparator
17 | _WS // WhiteSpace
18 | _ON // OtherNeutral
19 | _BN // BoundaryNeutral
20 | _NSM // NonspacingMark
21 | _AL // ArabicLetter
22 | classControl // Control LRO - PDI
23 |
24 | numClass
25 |
26 | _LRO // LeftToRightOverride
27 | _RLO // RightToLeftOverride
28 | _LRE // LeftToRightEmbedding
29 | _RLE // RightToLeftEmbedding
30 | _PDF // PopDirectionalFormat
31 | _LRI // LeftToRightIsolate
32 | _RLI // RightToLeftIsolate
33 | _FSI // FirstStrongIsolate
34 | _PDI // PopDirectionalIsolate
35 | )
36 |
37 | var controlToClass = map[rune]class{
38 | 0x202D: _LRO, // LeftToRightOverride,
39 | 0x202E: _RLO, // RightToLeftOverride,
40 | 0x202A: _LRE, // LeftToRightEmbedding,
41 | 0x202B: _RLE, // RightToLeftEmbedding,
42 | 0x202C: _PDF, // PopDirectionalFormat,
43 | 0x2066: _LRI, // LeftToRightIsolate,
44 | 0x2067: _RLI, // RightToLeftIsolate,
45 | 0x2068: _FSI, // FirstStrongIsolate,
46 | 0x2069: _PDI, // PopDirectionalIsolate,
47 | }
48 |
49 | // A trie entry has the following bits:
50 | // 7..5 XOR mask for brackets
51 | // 4 1: Bracket open, 0: Bracket close
52 | // 3..0 class type
53 | type entry uint8
54 |
55 | const (
56 | openMask = 0x10
57 | xorMaskShift = 5
58 | )
59 |
60 | func (e entry) isBracket() bool { return e&0xF0 != 0 }
61 | func (e entry) isOpen() bool { return e&openMask != 0 }
62 | func (e entry) reverseBracket(r rune) rune { return xorMasks[e>>xorMaskShift] ^ r }
63 | func (e entry) class(r rune) class {
64 | c := class(e & 0x0F)
65 | if c == classControl {
66 | return controlToClass[r]
67 | }
68 | return c
69 | }
70 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/cases/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package cases_test
6 |
7 | import (
8 | "fmt"
9 |
10 | "golang.org/x/text/cases"
11 | "golang.org/x/text/language"
12 | )
13 |
14 | func Example() {
15 | src := []string{
16 | "hello world!",
17 | "i with dot",
18 | "'n ijsberg",
19 | "here comes O'Brian",
20 | }
21 | for _, c := range []cases.Caser{
22 | cases.Lower(language.Und),
23 | cases.Upper(language.Turkish),
24 | cases.Title(language.Dutch),
25 | cases.Title(language.Und, cases.NoLower),
26 | } {
27 | fmt.Println()
28 | for _, s := range src {
29 | fmt.Println(c.String(s))
30 | }
31 | }
32 |
33 | // Output:
34 | // hello world!
35 | // i with dot
36 | // 'n ijsberg
37 | // here comes o'brian
38 | //
39 | // HELLO WORLD!
40 | // İ WİTH DOT
41 | // 'N İJSBERG
42 | // HERE COMES O'BRİAN
43 | //
44 | // Hello World!
45 | // I With Dot
46 | // 'n IJsberg
47 | // Here Comes O'brian
48 | //
49 | // Hello World!
50 | // I With Dot
51 | // 'N Ijsberg
52 | // Here Comes O'Brian
53 | }
54 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/codereview.cfg:
--------------------------------------------------------------------------------
1 | issuerepo: golang/go
2 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/colltab/colltab.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package colltab // import "golang.org/x/text/collate/colltab"
6 |
7 | // A Weighter can be used as a source for Collator and Searcher.
8 | type Weighter interface {
9 | // Start finds the start of the segment that includes position p.
10 | Start(p int, b []byte) int
11 |
12 | // StartString finds the start of the segment that includes position p.
13 | StartString(p int, s string) int
14 |
15 | // AppendNext appends Elems to buf corresponding to the longest match
16 | // of a single character or contraction from the start of s.
17 | // It returns the new buf and the number of bytes consumed.
18 | AppendNext(buf []Elem, s []byte) (ce []Elem, n int)
19 |
20 | // AppendNextString appends Elems to buf corresponding to the longest match
21 | // of a single character or contraction from the start of s.
22 | // It returns the new buf and the number of bytes consumed.
23 | AppendNextString(buf []Elem, s string) (ce []Elem, n int)
24 |
25 | // Domain returns a slice of all single characters and contractions for which
26 | // collation elements are defined in this table.
27 | Domain() []string
28 |
29 | // Top returns the highest variable primary value.
30 | Top() uint32
31 | }
32 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/colltab/colltab_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package colltab
6 |
7 | // testWeighter is a simple Weighter that returns weights from a user-defined map.
8 | type testWeighter map[string][]Elem
9 |
10 | func (t testWeighter) Start(int, []byte) int { return 0 }
11 | func (t testWeighter) StartString(int, string) int { return 0 }
12 | func (t testWeighter) Domain() []string { return nil }
13 | func (t testWeighter) Top() uint32 { return 0 }
14 |
15 | // maxContractBytes is the maximum length of any key in the map.
16 | const maxContractBytes = 10
17 |
18 | func (t testWeighter) AppendNext(buf []Elem, s []byte) ([]Elem, int) {
19 | n := len(s)
20 | if n > maxContractBytes {
21 | n = maxContractBytes
22 | }
23 | for i := n; i > 0; i-- {
24 | if e, ok := t[string(s[:i])]; ok {
25 | return append(buf, e...), i
26 | }
27 | }
28 | panic("incomplete testWeighter: could not find " + string(s))
29 | }
30 |
31 | func (t testWeighter) AppendNextString(buf []Elem, s string) ([]Elem, int) {
32 | n := len(s)
33 | if n > maxContractBytes {
34 | n = maxContractBytes
35 | }
36 | for i := n; i > 0; i-- {
37 | if e, ok := t[s[:i]]; ok {
38 | return append(buf, e...), i
39 | }
40 | }
41 | panic("incomplete testWeighter: could not find " + s)
42 | }
43 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/colltab/contract_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package colltab
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | type lookupStrings struct {
12 | str string
13 | offset int
14 | n int // bytes consumed from input
15 | }
16 |
17 | type LookupTest struct {
18 | lookup []lookupStrings
19 | n int
20 | tries contractTrieSet
21 | }
22 |
23 | var lookupTests = []LookupTest{
24 | {[]lookupStrings{
25 | {"abc", 1, 3},
26 | {"a", 0, 0},
27 | {"b", 0, 0},
28 | {"c", 0, 0},
29 | {"d", 0, 0},
30 | },
31 | 1,
32 | contractTrieSet{
33 | {'a', 0, 1, 0xFF},
34 | {'b', 0, 1, 0xFF},
35 | {'c', 'c', 0, 1},
36 | },
37 | },
38 | {[]lookupStrings{
39 | {"abc", 1, 3},
40 | {"abd", 2, 3},
41 | {"abe", 3, 3},
42 | {"a", 0, 0},
43 | {"ab", 0, 0},
44 | {"d", 0, 0},
45 | {"f", 0, 0},
46 | },
47 | 1,
48 | contractTrieSet{
49 | {'a', 0, 1, 0xFF},
50 | {'b', 0, 1, 0xFF},
51 | {'c', 'e', 0, 1},
52 | },
53 | },
54 | {[]lookupStrings{
55 | {"abc", 1, 3},
56 | {"ab", 2, 2},
57 | {"a", 3, 1},
58 | {"abcd", 1, 3},
59 | {"abe", 2, 2},
60 | },
61 | 1,
62 | contractTrieSet{
63 | {'a', 0, 1, 3},
64 | {'b', 0, 1, 2},
65 | {'c', 'c', 0, 1},
66 | },
67 | },
68 | {[]lookupStrings{
69 | {"abc", 1, 3},
70 | {"abd", 2, 3},
71 | {"ab", 3, 2},
72 | {"ac", 4, 2},
73 | {"a", 5, 1},
74 | {"b", 6, 1},
75 | {"ba", 6, 1},
76 | },
77 | 2,
78 | contractTrieSet{
79 | {'b', 'b', 0, 6},
80 | {'a', 0, 2, 5},
81 | {'c', 'c', 0, 4},
82 | {'b', 0, 1, 3},
83 | {'c', 'd', 0, 1},
84 | },
85 | },
86 | {[]lookupStrings{
87 | {"bcde", 2, 4},
88 | {"bc", 7, 2},
89 | {"ab", 6, 2},
90 | {"bcd", 5, 3},
91 | {"abcd", 1, 4},
92 | {"abc", 4, 3},
93 | {"bcdf", 3, 4},
94 | },
95 | 2,
96 | contractTrieSet{
97 | {'b', 3, 1, 0xFF},
98 | {'a', 0, 1, 0xFF},
99 | {'b', 0, 1, 6},
100 | {'c', 0, 1, 4},
101 | {'d', 'd', 0, 1},
102 | {'c', 0, 1, 7},
103 | {'d', 0, 1, 5},
104 | {'e', 'f', 0, 2},
105 | },
106 | },
107 | }
108 |
109 | func lookup(c *contractTrieSet, nnode int, s []uint8) (i, n int) {
110 | scan := c.scanner(0, nnode, s)
111 | scan.scan(0)
112 | return scan.result()
113 | }
114 |
115 | func TestLookupContraction(t *testing.T) {
116 | for i, tt := range lookupTests {
117 | cts := contractTrieSet(tt.tries)
118 | for j, lu := range tt.lookup {
119 | str := lu.str
120 | for _, s := range []string{str, str + "X"} {
121 | const msg = `%d:%d: %s of "%s" %v; want %v`
122 | offset, n := lookup(&cts, tt.n, []byte(s))
123 | if offset != lu.offset {
124 | t.Errorf(msg, i, j, "offset", s, offset, lu.offset)
125 | }
126 | if n != lu.n {
127 | t.Errorf(msg, i, j, "bytes consumed", s, n, len(str))
128 | }
129 | }
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/colltab/export.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package colltab
6 |
7 | // Init is for internal use only.
8 | func Init(data interface{}) Weighter {
9 | init, ok := data.(tableInitializer)
10 | if !ok {
11 | return nil
12 | }
13 | t := &table{}
14 | loff, voff := init.FirstBlockOffsets()
15 | t.index.index = init.TrieIndex()
16 | t.index.index0 = t.index.index[blockSize*int(loff):]
17 | t.index.values = init.TrieValues()
18 | t.index.values0 = t.index.values[blockSize*int(voff):]
19 | t.expandElem = init.ExpandElems()
20 | t.contractTries = init.ContractTries()
21 | t.contractElem = init.ContractElems()
22 | t.maxContractLen = init.MaxContractLen()
23 | t.variableTop = init.VariableTop()
24 | return t
25 | }
26 |
27 | type tableInitializer interface {
28 | TrieIndex() []uint16
29 | TrieValues() []uint32
30 | FirstBlockOffsets() (lookup, value uint16)
31 | ExpandElems() []uint32
32 | ContractTries() []struct{ l, h, n, i uint8 }
33 | ContractElems() []uint32
34 | MaxContractLen() int
35 | VariableTop() uint32
36 | }
37 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/colltab/trie_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package colltab
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | // We take the smallest, largest and an arbitrary value for each
12 | // of the UTF-8 sequence lengths.
13 | var testRunes = []rune{
14 | 0x01, 0x0C, 0x7F, // 1-byte sequences
15 | 0x80, 0x100, 0x7FF, // 2-byte sequences
16 | 0x800, 0x999, 0xFFFF, // 3-byte sequences
17 | 0x10000, 0x10101, 0x10FFFF, // 4-byte sequences
18 | 0x200, 0x201, 0x202, 0x210, 0x215, // five entries in one sparse block
19 | }
20 |
21 | // Test cases for illegal runes.
22 | type trietest struct {
23 | size int
24 | bytes []byte
25 | }
26 |
27 | var tests = []trietest{
28 | // illegal runes
29 | {1, []byte{0x80}},
30 | {1, []byte{0xFF}},
31 | {1, []byte{t2, tx - 1}},
32 | {1, []byte{t2, t2}},
33 | {2, []byte{t3, tx, tx - 1}},
34 | {2, []byte{t3, tx, t2}},
35 | {1, []byte{t3, tx - 1, tx}},
36 | {3, []byte{t4, tx, tx, tx - 1}},
37 | {3, []byte{t4, tx, tx, t2}},
38 | {1, []byte{t4, t2, tx, tx - 1}},
39 | {2, []byte{t4, tx, t2, tx - 1}},
40 |
41 | // short runes
42 | {0, []byte{t2}},
43 | {0, []byte{t3, tx}},
44 | {0, []byte{t4, tx, tx}},
45 |
46 | // we only support UTF-8 up to utf8.UTFMax bytes (4 bytes)
47 | {1, []byte{t5, tx, tx, tx, tx}},
48 | {1, []byte{t6, tx, tx, tx, tx, tx}},
49 | }
50 |
51 | func TestLookupTrie(t *testing.T) {
52 | for i, r := range testRunes {
53 | b := []byte(string(r))
54 | v, sz := testTrie.lookup(b)
55 | if int(v) != i {
56 | t.Errorf("lookup(%U): found value %#x, expected %#x", r, v, i)
57 | }
58 | if sz != len(b) {
59 | t.Errorf("lookup(%U): found size %d, expected %d", r, sz, len(b))
60 | }
61 | }
62 | for i, tt := range tests {
63 | v, sz := testTrie.lookup(tt.bytes)
64 | if int(v) != 0 {
65 | t.Errorf("lookup of illegal rune, case %d: found value %#x, expected 0", i, v)
66 | }
67 | if sz != tt.size {
68 | t.Errorf("lookup of illegal rune, case %d: found size %d, expected %d", i, sz, tt.size)
69 | }
70 | }
71 | }
72 |
73 | // test data is taken from exp/collate/locale/build/trie_test.go
74 | var testValues = [832]uint32{
75 | 0x000c: 0x00000001,
76 | 0x007f: 0x00000002,
77 | 0x00c0: 0x00000003,
78 | 0x0100: 0x00000004,
79 | 0x0140: 0x0000000c, 0x0141: 0x0000000d, 0x0142: 0x0000000e,
80 | 0x0150: 0x0000000f,
81 | 0x0155: 0x00000010,
82 | 0x01bf: 0x00000005,
83 | 0x01c0: 0x00000006,
84 | 0x0219: 0x00000007,
85 | 0x027f: 0x00000008,
86 | 0x0280: 0x00000009,
87 | 0x02c1: 0x0000000a,
88 | 0x033f: 0x0000000b,
89 | }
90 |
91 | var testLookup = [640]uint16{
92 | 0x0e0: 0x05, 0x0e6: 0x06,
93 | 0x13f: 0x07,
94 | 0x140: 0x08, 0x144: 0x09,
95 | 0x190: 0x03,
96 | 0x1ff: 0x0a,
97 | 0x20f: 0x05,
98 | 0x242: 0x01, 0x244: 0x02,
99 | 0x248: 0x03,
100 | 0x25f: 0x04,
101 | 0x260: 0x01,
102 | 0x26f: 0x02,
103 | 0x270: 0x04, 0x274: 0x06,
104 | }
105 |
106 | var testTrie = trie{testLookup[6*blockSize:], testValues[:], testLookup[:], testValues[:]}
107 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/export_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package collate
6 |
7 | // Export for testing.
8 | // TODO: no longer necessary. Remove at some point.
9 |
10 | import (
11 | "fmt"
12 |
13 | "golang.org/x/text/collate/colltab"
14 | )
15 |
16 | const (
17 | defaultSecondary = 0x20
18 | defaultTertiary = 0x2
19 | )
20 |
21 | type Weights struct {
22 | Primary, Secondary, Tertiary, Quaternary int
23 | }
24 |
25 | func W(ce ...int) Weights {
26 | w := Weights{ce[0], defaultSecondary, defaultTertiary, 0}
27 | if len(ce) > 1 {
28 | w.Secondary = ce[1]
29 | }
30 | if len(ce) > 2 {
31 | w.Tertiary = ce[2]
32 | }
33 | if len(ce) > 3 {
34 | w.Quaternary = ce[3]
35 | }
36 | return w
37 | }
38 | func (w Weights) String() string {
39 | return fmt.Sprintf("[%X.%X.%X.%X]", w.Primary, w.Secondary, w.Tertiary, w.Quaternary)
40 | }
41 |
42 | func convertFromWeights(ws []Weights) []colltab.Elem {
43 | out := make([]colltab.Elem, len(ws))
44 | for i, w := range ws {
45 | out[i], _ = colltab.MakeElem(w.Primary, w.Secondary, w.Tertiary, 0)
46 | if out[i] == colltab.Ignore && w.Quaternary > 0 {
47 | out[i] = colltab.MakeQuaternary(w.Quaternary)
48 | }
49 | }
50 | return out
51 | }
52 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/index.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package collate
6 |
7 | // tableIndex holds information for constructing a table
8 | // for a certain locale based on the main table.
9 | type tableIndex struct {
10 | lookupOffset uint32
11 | valuesOffset uint32
12 | }
13 |
14 | func (t tableIndex) TrieIndex() []uint16 {
15 | return mainLookup[:]
16 | }
17 |
18 | func (t tableIndex) TrieValues() []uint32 {
19 | return mainValues[:]
20 | }
21 |
22 | func (t tableIndex) FirstBlockOffsets() (lookup, value uint16) {
23 | return uint16(t.lookupOffset), uint16(t.valuesOffset)
24 | }
25 |
26 | func (t tableIndex) ExpandElems() []uint32 {
27 | return mainExpandElem[:]
28 | }
29 |
30 | func (t tableIndex) ContractTries() []struct{ l, h, n, i uint8 } {
31 | return mainCTEntries[:]
32 | }
33 |
34 | func (t tableIndex) ContractElems() []uint32 {
35 | return mainContractElem[:]
36 | }
37 |
38 | func (t tableIndex) MaxContractLen() int {
39 | return 18 // TODO: generate
40 | }
41 |
42 | func (t tableIndex) VariableTop() uint32 {
43 | return varTop
44 | }
45 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/sort.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package collate
6 |
7 | import (
8 | "bytes"
9 | "sort"
10 | )
11 |
12 | const (
13 | maxSortBuffer = 40960
14 | maxSortEntries = 4096
15 | )
16 |
17 | type swapper interface {
18 | Swap(i, j int)
19 | }
20 |
21 | type sorter struct {
22 | buf *Buffer
23 | keys [][]byte
24 | src swapper
25 | }
26 |
27 | func (s *sorter) init(n int) {
28 | if s.buf == nil {
29 | s.buf = &Buffer{}
30 | s.buf.init()
31 | }
32 | if cap(s.keys) < n {
33 | s.keys = make([][]byte, n)
34 | }
35 | s.keys = s.keys[0:n]
36 | }
37 |
38 | func (s *sorter) sort(src swapper) {
39 | s.src = src
40 | sort.Sort(s)
41 | }
42 |
43 | func (s sorter) Len() int {
44 | return len(s.keys)
45 | }
46 |
47 | func (s sorter) Less(i, j int) bool {
48 | return bytes.Compare(s.keys[i], s.keys[j]) == -1
49 | }
50 |
51 | func (s sorter) Swap(i, j int) {
52 | s.keys[i], s.keys[j] = s.keys[j], s.keys[i]
53 | s.src.Swap(i, j)
54 | }
55 |
56 | // A Lister can be sorted by Collator's Sort method.
57 | type Lister interface {
58 | Len() int
59 | Swap(i, j int)
60 | // Bytes returns the bytes of the text at index i.
61 | Bytes(i int) []byte
62 | }
63 |
64 | // Sort uses sort.Sort to sort the strings represented by x using the rules of c.
65 | func (c *Collator) Sort(x Lister) {
66 | n := x.Len()
67 | c.sorter.init(n)
68 | for i := 0; i < n; i++ {
69 | c.sorter.keys[i] = c.Key(c.sorter.buf, x.Bytes(i))
70 | }
71 | c.sorter.sort(x)
72 | }
73 |
74 | // SortStrings uses sort.Sort to sort the strings in x using the rules of c.
75 | func (c *Collator) SortStrings(x []string) {
76 | c.sorter.init(len(x))
77 | for i, s := range x {
78 | c.sorter.keys[i] = c.KeyFromString(c.sorter.buf, s)
79 | }
80 | c.sorter.sort(sort.StringSlice(x))
81 | }
82 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/sort_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package collate_test
6 |
7 | import (
8 | "fmt"
9 | "testing"
10 |
11 | "golang.org/x/text/collate"
12 | "golang.org/x/text/language"
13 | )
14 |
15 | func ExampleCollator_Strings() {
16 | c := collate.New(language.Und)
17 | strings := []string{
18 | "ad",
19 | "ab",
20 | "äb",
21 | "ac",
22 | }
23 | c.SortStrings(strings)
24 | fmt.Println(strings)
25 | // Output: [ab äb ac ad]
26 | }
27 |
28 | type sorter []string
29 |
30 | func (s sorter) Len() int {
31 | return len(s)
32 | }
33 |
34 | func (s sorter) Swap(i, j int) {
35 | s[j], s[i] = s[i], s[j]
36 | }
37 |
38 | func (s sorter) Bytes(i int) []byte {
39 | return []byte(s[i])
40 | }
41 |
42 | func TestSort(t *testing.T) {
43 | c := collate.New(language.English)
44 | strings := []string{
45 | "bcd",
46 | "abc",
47 | "ddd",
48 | }
49 | c.Sort(sorter(strings))
50 | res := fmt.Sprint(strings)
51 | want := "[abc bcd ddd]"
52 | if res != want {
53 | t.Errorf("found %s; want %s", res, want)
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/tools/colcmp/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright 2012 The Go Authors. All rights reserved.
2 | # Use of this source code is governed by a BSD-style
3 | # license that can be found in the LICENSE file.
4 |
5 | chars:
6 | go run ../../maketables.go -tables=chars -package=main > chars.go
7 | gofmt -w -s chars.go
8 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/tools/colcmp/col.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "log"
9 | "unicode/utf16"
10 |
11 | "golang.org/x/text/collate"
12 | "golang.org/x/text/language"
13 | )
14 |
15 | // Input holds an input string in both UTF-8 and UTF-16 format.
16 | type Input struct {
17 | index int // used for restoring to original random order
18 | UTF8 []byte
19 | UTF16 []uint16
20 | key []byte // used for sorting
21 | }
22 |
23 | func (i Input) String() string {
24 | return string(i.UTF8)
25 | }
26 |
27 | func makeInput(s8 []byte, s16 []uint16) Input {
28 | return Input{UTF8: s8, UTF16: s16}
29 | }
30 |
31 | func makeInputString(s string) Input {
32 | return Input{
33 | UTF8: []byte(s),
34 | UTF16: utf16.Encode([]rune(s)),
35 | }
36 | }
37 |
38 | // Collator is an interface for architecture-specific implementations of collation.
39 | type Collator interface {
40 | // Key generates a sort key for the given input. Implemenations
41 | // may return nil if a collator does not support sort keys.
42 | Key(s Input) []byte
43 |
44 | // Compare returns -1 if a < b, 1 if a > b and 0 if a == b.
45 | Compare(a, b Input) int
46 | }
47 |
48 | // CollatorFactory creates a Collator for a given language tag.
49 | type CollatorFactory struct {
50 | name string
51 | makeFn func(tag string) (Collator, error)
52 | description string
53 | }
54 |
55 | var collators = []CollatorFactory{}
56 |
57 | // AddFactory registers f as a factory for an implementation of Collator.
58 | func AddFactory(f CollatorFactory) {
59 | collators = append(collators, f)
60 | }
61 |
62 | func getCollator(name, locale string) Collator {
63 | for _, f := range collators {
64 | if f.name == name {
65 | col, err := f.makeFn(locale)
66 | if err != nil {
67 | log.Fatal(err)
68 | }
69 | return col
70 | }
71 | }
72 | log.Fatalf("collator of type %q not found", name)
73 | return nil
74 | }
75 |
76 | // goCollator is an implemention of Collator using go's own collator.
77 | type goCollator struct {
78 | c *collate.Collator
79 | buf collate.Buffer
80 | }
81 |
82 | func init() {
83 | AddFactory(CollatorFactory{"go", newGoCollator, "Go's native collator implementation."})
84 | }
85 |
86 | func newGoCollator(loc string) (Collator, error) {
87 | c := &goCollator{c: collate.New(language.Make(loc))}
88 | return c, nil
89 | }
90 |
91 | func (c *goCollator) Key(b Input) []byte {
92 | return c.c.Key(&c.buf, b.UTF8)
93 | }
94 |
95 | func (c *goCollator) Compare(a, b Input) int {
96 | return c.c.Compare(a.UTF8, b.UTF8)
97 | }
98 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/collate/tools/colcmp/darwin.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin
6 |
7 | package main
8 |
9 | /*
10 | #cgo LDFLAGS: -framework CoreFoundation
11 | #include
12 | #include
13 | */
14 | import "C"
15 | import (
16 | "unsafe"
17 | )
18 |
19 | func init() {
20 | AddFactory(CollatorFactory{"osx", newOSX16Collator,
21 | "OS X/Darwin collator, using native strings."})
22 | AddFactory(CollatorFactory{"osx8", newOSX8Collator,
23 | "OS X/Darwin collator for UTF-8."})
24 | }
25 |
26 | func osxUInt8P(s []byte) *C.UInt8 {
27 | return (*C.UInt8)(unsafe.Pointer(&s[0]))
28 | }
29 |
30 | func osxCharP(s []uint16) *C.UniChar {
31 | return (*C.UniChar)(unsafe.Pointer(&s[0]))
32 | }
33 |
34 | // osxCollator implements an Collator based on OS X's CoreFoundation.
35 | type osxCollator struct {
36 | loc C.CFLocaleRef
37 | opt C.CFStringCompareFlags
38 | }
39 |
40 | func (c *osxCollator) init(locale string) {
41 | l := C.CFStringCreateWithBytes(
42 | nil,
43 | osxUInt8P([]byte(locale)),
44 | C.CFIndex(len(locale)),
45 | C.kCFStringEncodingUTF8,
46 | C.Boolean(0),
47 | )
48 | c.loc = C.CFLocaleCreate(nil, l)
49 | }
50 |
51 | func newOSX8Collator(locale string) (Collator, error) {
52 | c := &osx8Collator{}
53 | c.init(locale)
54 | return c, nil
55 | }
56 |
57 | func newOSX16Collator(locale string) (Collator, error) {
58 | c := &osx16Collator{}
59 | c.init(locale)
60 | return c, nil
61 | }
62 |
63 | func (c osxCollator) Key(s Input) []byte {
64 | return nil // sort keys not supported by OS X CoreFoundation
65 | }
66 |
67 | type osx8Collator struct {
68 | osxCollator
69 | }
70 |
71 | type osx16Collator struct {
72 | osxCollator
73 | }
74 |
75 | func (c osx16Collator) Compare(a, b Input) int {
76 | sa := C.CFStringCreateWithCharactersNoCopy(
77 | nil,
78 | osxCharP(a.UTF16),
79 | C.CFIndex(len(a.UTF16)),
80 | nil,
81 | )
82 | sb := C.CFStringCreateWithCharactersNoCopy(
83 | nil,
84 | osxCharP(b.UTF16),
85 | C.CFIndex(len(b.UTF16)),
86 | nil,
87 | )
88 | _range := C.CFRangeMake(0, C.CFStringGetLength(sa))
89 | return int(C.CFStringCompareWithOptionsAndLocale(sa, sb, _range, c.opt, c.loc))
90 | }
91 |
92 | func (c osx8Collator) Compare(a, b Input) int {
93 | sa := C.CFStringCreateWithBytesNoCopy(
94 | nil,
95 | osxUInt8P(a.UTF8),
96 | C.CFIndex(len(a.UTF8)),
97 | C.kCFStringEncodingUTF8,
98 | C.Boolean(0),
99 | nil,
100 | )
101 | sb := C.CFStringCreateWithBytesNoCopy(
102 | nil,
103 | osxUInt8P(b.UTF8),
104 | C.CFIndex(len(b.UTF8)),
105 | C.kCFStringEncodingUTF8,
106 | C.Boolean(0),
107 | nil,
108 | )
109 | _range := C.CFRangeMake(0, C.CFStringGetLength(sa))
110 | return int(C.CFStringCompareWithOptionsAndLocale(sa, sb, _range, c.opt, c.loc))
111 | }
112 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/currency/common.go:
--------------------------------------------------------------------------------
1 | // This file was generated by go generate; DO NOT EDIT
2 |
3 | package currency
4 |
5 | import "golang.org/x/text/language"
6 |
7 | // This file contains code common to gen.go and the package code.
8 |
9 | const (
10 | cashShift = 3
11 | roundMask = 0x7
12 | )
13 |
14 | // currencyInfo contains information about a currency.
15 | // bits 0..2: index into roundings for standard rounding
16 | // bits 3..5: index into roundings for cash rounding
17 | type currencyInfo byte
18 |
19 | // roundingType defines the scale (number of fractional decimals) and increments
20 | // in terms of units of size 10^-scale. For example, for scale == 2 and
21 | // increment == 1, the currency is rounded to units of 0.01.
22 | type roundingType struct {
23 | scale, increment uint8
24 | }
25 |
26 | // roundings contains rounding data for currencies. This struct is
27 | // created by hand as it is very unlikely to change much.
28 | var roundings = [...]roundingType{
29 | {2, 1}, // default
30 | {0, 1},
31 | {1, 1},
32 | {3, 1},
33 | {4, 1},
34 | {2, 5}, // cash rounding alternative
35 | }
36 |
37 | // regionToCode returns a 16-bit region code. Only two-letter codes are
38 | // supported. (Three-letter codes are not needed.)
39 | func regionToCode(r language.Region) uint16 {
40 | if s := r.String(); len(s) == 2 {
41 | return uint16(s[0])<<8 | uint16(s[1])
42 | }
43 | return 0
44 | }
45 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/currency/format_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package currency
6 |
7 | import (
8 | "testing"
9 |
10 | "golang.org/x/text/language"
11 | "golang.org/x/text/message"
12 | )
13 |
14 | var (
15 | en = language.English
16 | fr = language.French
17 | en_US = language.AmericanEnglish
18 | en_AU = language.MustParse("en-AU")
19 | und = language.Und
20 | )
21 |
22 | func TestFormatting(t *testing.T) {
23 | testCases := []struct {
24 | tag language.Tag
25 | value interface{}
26 | format Formatter
27 | want string
28 | }{
29 | 0: {en, USD.Amount(0.1), nil, "USD 0.10"},
30 | 1: {en, XPT.Amount(1.0), Symbol, "XPT 1.00"},
31 |
32 | 2: {en, USD.Amount(2.0), ISO, "USD 2.00"},
33 | 3: {und, USD.Amount(3.0), Symbol, "US$ 3.00"},
34 | 4: {en, USD.Amount(4.0), Symbol, "$ 4.00"},
35 |
36 | 5: {en, USD.Amount(5.20), NarrowSymbol, "$ 5.20"},
37 | 6: {en, AUD.Amount(6.20), Symbol, "A$ 6.20"},
38 |
39 | 7: {en_AU, AUD.Amount(7.20), Symbol, "$ 7.20"},
40 | 8: {en_AU, USD.Amount(8.20), Symbol, "US$ 8.20"},
41 |
42 | 9: {en, 9.0, Symbol.Default(EUR), "€ 9.00"},
43 | 10: {en, 10.123, Symbol.Default(KRW), "₩ 10"},
44 | 11: {fr, 11.52, Symbol.Default(TWD), "TWD 11.52"},
45 | 12: {en, 12.123, Symbol.Default(czk), "CZK 12.12"},
46 | 13: {en, 13.123, Symbol.Default(czk).Kind(Cash), "CZK 13"},
47 | 14: {en, 14.12345, ISO.Default(MustParseISO("CLF")), "CLF 14.1235"},
48 | 15: {en, USD.Amount(15.00), ISO.Default(TWD), "USD 15.00"},
49 | 16: {en, KRW.Amount(16.00), ISO.Kind(Cash), "KRW 16"},
50 |
51 | // TODO: support integers as well.
52 |
53 | 17: {en, USD, nil, "USD"},
54 | 18: {en, USD, ISO, "USD"},
55 | 19: {en, USD, Symbol, "$"},
56 | 20: {en_AU, USD, Symbol, "US$"},
57 | 21: {en_AU, USD, NarrowSymbol, "$"},
58 | }
59 | for i, tc := range testCases {
60 | p := message.NewPrinter(tc.tag)
61 | v := tc.value
62 | if tc.format != nil {
63 | v = tc.format(v)
64 | }
65 | if got := p.Sprint(v); got != tc.want {
66 | t.Errorf("%d: got %q; want %q", i, got, tc.want)
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/currency/gen_common.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build ignore
6 |
7 | package main
8 |
9 | import "golang.org/x/text/language"
10 |
11 | // This file contains code common to gen.go and the package code.
12 |
13 | const (
14 | cashShift = 3
15 | roundMask = 0x7
16 | )
17 |
18 | // currencyInfo contains information about a currency.
19 | // bits 0..2: index into roundings for standard rounding
20 | // bits 3..5: index into roundings for cash rounding
21 | type currencyInfo byte
22 |
23 | // roundingType defines the scale (number of fractional decimals) and increments
24 | // in terms of units of size 10^-scale. For example, for scale == 2 and
25 | // increment == 1, the currency is rounded to units of 0.01.
26 | type roundingType struct {
27 | scale, increment uint8
28 | }
29 |
30 | // roundings contains rounding data for currencies. This struct is
31 | // created by hand as it is very unlikely to change much.
32 | var roundings = [...]roundingType{
33 | {2, 1}, // default
34 | {0, 1},
35 | {1, 1},
36 | {3, 1},
37 | {4, 1},
38 | {2, 5}, // cash rounding alternative
39 | }
40 |
41 | // regionToCode returns a 16-bit region code. Only two-letter codes are
42 | // supported. (Three-letter codes are not needed.)
43 | func regionToCode(r language.Region) uint16 {
44 | if s := r.String(); len(s) == 2 {
45 | return uint16(s[0])<<8 | uint16(s[1])
46 | }
47 | return 0
48 | }
49 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/currency/tables_test.go:
--------------------------------------------------------------------------------
1 | package currency
2 |
3 | import (
4 | "flag"
5 | "strings"
6 | "testing"
7 |
8 | "golang.org/x/text/internal/gen"
9 | "golang.org/x/text/language"
10 | "golang.org/x/text/message"
11 | "golang.org/x/text/unicode/cldr"
12 | )
13 |
14 | var (
15 | long = flag.Bool("long", false,
16 | "run time-consuming tests, such as tests that fetch data online")
17 |
18 | draft = flag.String("draft",
19 | "contributed",
20 | `Minimal draft requirements (approved, contributed, provisional, unconfirmed).`)
21 | )
22 |
23 | func TestTables(t *testing.T) {
24 | if !*long {
25 | return
26 | }
27 |
28 | gen.Init()
29 |
30 | // Read the CLDR zip file.
31 | r := gen.OpenCLDRCoreZip()
32 | defer r.Close()
33 |
34 | d := &cldr.Decoder{}
35 | d.SetDirFilter("supplemental", "main")
36 | d.SetSectionFilter("numbers")
37 | data, err := d.DecodeZip(r)
38 | if err != nil {
39 | t.Fatalf("DecodeZip: %v", err)
40 | }
41 |
42 | dr, err := cldr.ParseDraft(*draft)
43 | if err != nil {
44 | t.Fatalf("filter: %v", err)
45 | }
46 |
47 | for _, lang := range data.Locales() {
48 | p := message.NewPrinter(language.MustParse(lang))
49 |
50 | ldml := data.RawLDML(lang)
51 | if ldml.Numbers == nil || ldml.Numbers.Currencies == nil {
52 | continue
53 | }
54 | for _, c := range ldml.Numbers.Currencies.Currency {
55 | syms := cldr.MakeSlice(&c.Symbol)
56 | syms.SelectDraft(dr)
57 |
58 | for _, sym := range c.Symbol {
59 | cur, err := ParseISO(c.Type)
60 | if err != nil {
61 | continue
62 | }
63 | formatter := Symbol
64 | switch sym.Alt {
65 | case "":
66 | case "narrow":
67 | formatter = NarrowSymbol
68 | default:
69 | continue
70 | }
71 | want := sym.Data()
72 | if got := p.Sprint(formatter(cur)); got != want {
73 | t.Errorf("%s:%sSymbol(%s) = %s; want %s", lang, strings.Title(sym.Alt), c.Type, got, want)
74 | }
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/display/dict_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package display
6 |
7 | import (
8 | "fmt"
9 | "testing"
10 |
11 | "golang.org/x/text/internal/testtext"
12 | )
13 |
14 | func TestLinking(t *testing.T) {
15 | base := getSize(t, `display.Tags(language.English).Name(language.English)`)
16 | compact := getSize(t, `display.English.Languages().Name(language.English)`)
17 |
18 | if d := base - compact; d < 1.5*1024*1024 {
19 | t.Errorf("size(base)-size(compact) was %d; want > 1.5MB", base, compact)
20 | }
21 | }
22 |
23 | func getSize(t *testing.T, main string) int {
24 | size, err := testtext.CodeSize(fmt.Sprintf(body, main))
25 | if err != nil {
26 | t.Skipf("skipping link size test; binary size could not be determined: %v", err)
27 | }
28 | return size
29 | }
30 |
31 | const body = `package main
32 | import (
33 | "golang.org/x/text/display"
34 | "golang.org/x/text/language"
35 | )
36 | func main() {
37 | %s
38 | }
39 | `
40 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:generate go run gen.go
6 |
7 | // text is a repository of text-related packages, such as character encodings,
8 | // text transformations, and locale-specific text handling.
9 | package text
10 |
11 | // TODO: more documentation on general concepts, such as Transformers, use
12 | // of normalization, etc.
13 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package encoding_test
6 |
7 | import (
8 | "fmt"
9 | "io"
10 | "os"
11 | "strings"
12 |
13 | "golang.org/x/text/encoding"
14 | "golang.org/x/text/encoding/charmap"
15 | "golang.org/x/text/transform"
16 | )
17 |
18 | func ExampleDecodeWindows1252() {
19 | sr := strings.NewReader("Gar\xe7on !")
20 | tr := transform.NewReader(sr, charmap.Windows1252.NewDecoder())
21 | io.Copy(os.Stdout, tr)
22 | // Output: Garçon !
23 | }
24 |
25 | func ExampleUTF8Validator() {
26 | for i := 0; i < 2; i++ {
27 | transformer := charmap.Windows1252.NewEncoder()
28 | if i == 1 {
29 | transformer = transform.Chain(encoding.UTF8Validator, transformer)
30 | }
31 | dst := make([]byte, 256)
32 | src := []byte("abc\xffxyz") // src is invalid UTF-8.
33 | nDst, nSrc, err := transformer.Transform(dst, src, true)
34 | fmt.Printf("i=%d: produced %q, consumed %q, error %v\n",
35 | i, dst[:nDst], src[:nSrc], err)
36 | }
37 | // Output:
38 | // i=0: produced "abc\x1axyz", consumed "abc\xffxyz", error
39 | // i=1: produced "abc", consumed "abc", error encoding: invalid UTF-8
40 | }
41 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/htmlindex/htmlindex.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:generate go run gen.go
6 |
7 | // Package htmlindex maps character set encoding names to Encodings as
8 | // recommended by the W3C for use in HTML 5. See http://www.w3.org/TR/encoding.
9 | package htmlindex
10 |
11 | // TODO: perhaps have a "bare" version of the index (used by this package) that
12 | // is not pre-loaded with all encodings. Global variables in encodings prevent
13 | // the linker from being able to purge unneeded tables. This means that
14 | // referencing all encodings, as this package does for the default index, links
15 | // in all encodings unconditionally.
16 | //
17 | // This issue can be solved by either solving the linking issue (see
18 | // https://github.com/golang/go/issues/6330) or refactoring the encoding tables
19 | // (e.g. moving the tables to internal packages that do not use global
20 | // variables).
21 |
22 | // TODO: allow canonicalizing names
23 |
24 | import (
25 | "errors"
26 | "strings"
27 | "sync"
28 |
29 | "golang.org/x/text/encoding"
30 | "golang.org/x/text/encoding/internal/identifier"
31 | "golang.org/x/text/language"
32 | )
33 |
34 | var (
35 | errInvalidName = errors.New("htmlindex: invalid encoding name")
36 | errUnknown = errors.New("htmlindex: unknown Encoding")
37 | errUnsupported = errors.New("htmlindex: this encoding is not supported")
38 | )
39 |
40 | var (
41 | matcherOnce sync.Once
42 | matcher language.Matcher
43 | )
44 |
45 | // LanguageDefault returns the canonical name of the default encoding for a
46 | // given language.
47 | func LanguageDefault(tag language.Tag) string {
48 | matcherOnce.Do(func() {
49 | tags := []language.Tag{}
50 | for _, t := range strings.Split(locales, " ") {
51 | tags = append(tags, language.MustParse(t))
52 | }
53 | matcher = language.NewMatcher(tags)
54 | })
55 | _, i, _ := matcher.Match(tag)
56 | return canonical[localeMap[i]] // Default is Windows-1252.
57 | }
58 |
59 | // Get returns an Encoding for one of the names listed in
60 | // http://www.w3.org/TR/encoding using the Default Index. Matching is case-
61 | // insensitive.
62 | func Get(name string) (encoding.Encoding, error) {
63 | x, ok := nameMap[strings.ToLower(strings.TrimSpace(name))]
64 | if !ok {
65 | return nil, errInvalidName
66 | }
67 | return encodings[x], nil
68 | }
69 |
70 | // Name reports the canonical name of the given Encoding. It will return
71 | // an error if e is not associated with a supported encoding scheme.
72 | func Name(e encoding.Encoding) (string, error) {
73 | id, ok := e.(identifier.Interface)
74 | if !ok {
75 | return "", errUnknown
76 | }
77 | mib, _ := id.ID()
78 | if mib == 0 {
79 | return "", errUnknown
80 | }
81 | v, ok := mibMap[mib]
82 | if !ok {
83 | return "", errUnsupported
84 | }
85 | return canonical[v], nil
86 | }
87 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/ianaindex/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package ianaindex_test
6 |
7 | import (
8 | "fmt"
9 |
10 | "golang.org/x/text/encoding/charmap"
11 | "golang.org/x/text/encoding/ianaindex"
12 | )
13 |
14 | func ExampleIndex() {
15 | fmt.Println(ianaindex.MIME.Name(charmap.ISO8859_7))
16 |
17 | fmt.Println(ianaindex.IANA.Name(charmap.ISO8859_7))
18 |
19 | e, _ := ianaindex.IANA.Get("cp437")
20 | fmt.Println(ianaindex.IANA.Name(e))
21 |
22 | // TODO: Output:
23 | // ISO-8859-7
24 | // ISO8859_7:1987
25 | // IBM437
26 | }
27 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/ianaindex/ianaindex.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package ianaindex maps names to Encodings as specified by the IANA registry.
6 | // This includes both the MIME and IANA names.
7 | //
8 | // See http://www.iana.org/assignments/character-sets/character-sets.xhtml for
9 | // more details.
10 | package ianaindex
11 |
12 | import (
13 | "golang.org/x/text/encoding"
14 | )
15 |
16 | // TODO: allow users to specify their own aliases?
17 | // TODO: allow users to specify their own indexes?
18 | // TODO: allow canonicalizing names
19 |
20 | // NOTE: only use these top-level variables if we can get the linker to drop
21 | // the indexes when they are not used. Make them a function or perhaps only
22 | // support MIME otherwise.
23 |
24 | var (
25 | // MIME is an index to map MIME names. It does not support aliases.
26 | MIME *Index
27 |
28 | // IANA is an index that supports all names and aliases using IANA names as
29 | // the canonical identifier.
30 | IANA *Index
31 | )
32 |
33 | // Index maps names registered by IANA to Encodings.
34 | type Index struct {
35 | }
36 |
37 | // Get returns an Encoding for IANA-registered names. Matching is
38 | // case-insensitive.
39 | func (x *Index) Get(name string) (encoding.Encoding, error) {
40 | panic("TODO: implement")
41 | }
42 |
43 | // Name reports the canonical name of the given Encoding. It will return an
44 | // error if the e is not associated with a known encoding scheme.
45 | func (x *Index) Name(e encoding.Encoding) (string, error) {
46 | panic("TODO: implement")
47 | }
48 |
49 | // TODO: the coverage of this index is rather spotty. Allowing users to set
50 | // encodings would allow:
51 | // - users to increase coverage
52 | // - allow a partially loaded set of encodings in case the user doesn't need to
53 | // them all.
54 | // - write an OS-specific wrapper for supported encodings and set them.
55 | // The exact definition of Set depends a bit on if and how we want to let users
56 | // write their own Encoding implementations. Also, it is not possible yet to
57 | // only partially load the encodings without doing some refactoring. Until this
58 | // is solved, we might as well not support Set.
59 | // // Set sets the e to be used for the encoding scheme identified by name. Only
60 | // // canonical names may be used. An empty name assigns e to its internally
61 | // // associated encoding scheme.
62 | // func (x *Index) Set(name string, e encoding.Encoding) error {
63 | // panic("TODO: implement")
64 | // }
65 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/internal/internal.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package internal contains code that is shared among encoding implementations.
6 | package internal
7 |
8 | import (
9 | "golang.org/x/text/encoding"
10 | "golang.org/x/text/encoding/internal/identifier"
11 | "golang.org/x/text/transform"
12 | )
13 |
14 | // Encoding is an implementation of the Encoding interface that adds the String
15 | // and ID methods to an existing encoding.
16 | type Encoding struct {
17 | encoding.Encoding
18 | Name string
19 | MIB identifier.MIB
20 | }
21 |
22 | // _ verifies that Encoding implements identifier.Interface.
23 | var _ identifier.Interface = (*Encoding)(nil)
24 |
25 | func (e *Encoding) String() string {
26 | return e.Name
27 | }
28 |
29 | func (e *Encoding) ID() (mib identifier.MIB, other string) {
30 | return e.MIB, ""
31 | }
32 |
33 | // SimpleEncoding is an Encoding that combines two Transformers.
34 | type SimpleEncoding struct {
35 | Decoder transform.Transformer
36 | Encoder transform.Transformer
37 | }
38 |
39 | func (e *SimpleEncoding) NewDecoder() transform.Transformer {
40 | return e.Decoder
41 | }
42 |
43 | func (e *SimpleEncoding) NewEncoder() transform.Transformer {
44 | return e.Encoder
45 | }
46 |
47 | // FuncEncoding is an Encoding that combines two functions returning a new
48 | // Transformer.
49 | type FuncEncoding struct {
50 | Decoder func() transform.Transformer
51 | Encoder func() transform.Transformer
52 | }
53 |
54 | func (e FuncEncoding) NewDecoder() transform.Transformer {
55 | return e.Decoder()
56 | }
57 |
58 | func (e FuncEncoding) NewEncoder() transform.Transformer {
59 | return e.Encoder()
60 | }
61 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/japanese/all.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package japanese
6 |
7 | import (
8 | "golang.org/x/text/encoding"
9 | )
10 |
11 | // All is a list of all defined encodings in this package.
12 | var All = []encoding.Encoding{EUCJP, ISO2022JP, ShiftJIS}
13 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/simplifiedchinese/all.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package simplifiedchinese
6 |
7 | import (
8 | "golang.org/x/text/encoding"
9 | )
10 |
11 | // All is a list of all defined encodings in this package.
12 | var All = []encoding.Encoding{GB18030, GBK, HZGB2312}
13 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/candide-gb18030.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/candide-gb18030.txt
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/candide-utf-16le.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/candide-utf-16le.txt
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/candide-windows-1252.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/candide-windows-1252.txt
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/rashomon-euc-jp.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/rashomon-euc-jp.txt
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/rashomon-shift-jis.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/rashomon-shift-jis.txt
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/sunzi-bingfa-simplified-gbk.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/sunzi-bingfa-simplified-gbk.txt
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/sunzi-bingfa-traditional-big5.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/sunzi-bingfa-traditional-big5.txt
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/unsu-joh-eun-nal-euc-kr.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoeCao/cmpp-gateway/7bcf51217eb544d0a8f2a77a7ce313f628a73e62/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/testdata/unsu-joh-eun-nal-euc-kr.txt
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/encoding/unicode/override.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package unicode
6 |
7 | import (
8 | "golang.org/x/text/transform"
9 | )
10 |
11 | // BOMOverride returns a new decoder transformer that is identical to fallback,
12 | // except that the presence of a Byte Order Mark at the start of the input
13 | // causes it to switch to the corresponding Unicode decoding. It will only
14 | // consider BOMs for UTF-8, UTF-16BE, and UTF-16LE.
15 | //
16 | // This differs from using ExpectBOM by allowing a BOM to switch to UTF-8, not
17 | // just UTF-16 variants, and allowing falling back to any encoding scheme.
18 | //
19 | // This technique is recommended by the W3C for use in HTML 5: "For
20 | // compatibility with deployed content, the byte order mark (also known as BOM)
21 | // is considered more authoritative than anything else."
22 | // http://www.w3.org/TR/encoding/#specification-hooks
23 | //
24 | // Using BOMOverride is mostly intended for use cases where the first characters
25 | // of a fallback encoding are known to not be a BOM, for example, for valid HTML
26 | // and most encodings.
27 | func BOMOverride(fallback transform.Transformer) transform.Transformer {
28 | // TODO: possibly allow a variadic argument of unicode encodings to allow
29 | // specifying details of which fallbacks are supported as well as
30 | // specifying the details of the implementations. This would also allow for
31 | // support for UTF-32, which should not be supported by default.
32 | return &bomOverride{fallback: fallback}
33 | }
34 |
35 | type bomOverride struct {
36 | fallback transform.Transformer
37 | current transform.Transformer
38 | }
39 |
40 | func (d *bomOverride) Reset() {
41 | d.current = nil
42 | d.fallback.Reset()
43 | }
44 |
45 | var (
46 | // TODO: we could use decode functions here, instead of allocating a new
47 | // decoder on every NewDecoder as IgnoreBOM decoders can be stateless.
48 | utf16le = UTF16(LittleEndian, IgnoreBOM)
49 | utf16be = UTF16(BigEndian, IgnoreBOM)
50 | )
51 |
52 | const utf8BOM = "\ufeff"
53 |
54 | func (d *bomOverride) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
55 | if d.current != nil {
56 | return d.current.Transform(dst, src, atEOF)
57 | }
58 | if len(src) < 3 && !atEOF {
59 | return 0, 0, transform.ErrShortSrc
60 | }
61 | d.current = d.fallback
62 | bomSize := 0
63 | if len(src) >= 2 {
64 | if src[0] == 0xFF && src[1] == 0xFE {
65 | d.current = utf16le.NewDecoder()
66 | bomSize = 2
67 | } else if src[0] == 0xFE && src[1] == 0xFF {
68 | d.current = utf16be.NewDecoder()
69 | bomSize = 2
70 | } else if len(src) >= 3 &&
71 | src[0] == utf8BOM[0] &&
72 | src[1] == utf8BOM[1] &&
73 | src[2] == utf8BOM[2] {
74 | d.current = transform.Nop
75 | bomSize = 3
76 | }
77 | }
78 | if bomSize < len(src) {
79 | nDst, nSrc, err = d.current.Transform(dst, src[bomSize:], atEOF)
80 | }
81 | return nDst, nSrc + bomSize, err
82 | }
83 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/colltab/colltab_test.go:
--------------------------------------------------------------------------------
1 | package colltab
2 |
3 | import (
4 | "testing"
5 |
6 | "golang.org/x/text/language"
7 | )
8 |
9 | func TestMatchLang(t *testing.T) {
10 | tags := []language.Tag{
11 | 0: language.Und,
12 | 1: language.MustParse("bs"),
13 | 2: language.German,
14 | 3: language.English,
15 | 4: language.AmericanEnglish,
16 | 5: language.MustParse("en-US-u-va-posix"),
17 | 6: language.Portuguese,
18 | 7: language.Serbian,
19 | 8: language.MustParse("sr-Latn"),
20 | 9: language.Chinese,
21 | 10: language.SimplifiedChinese, // Cannot match.
22 | 11: language.TraditionalChinese,
23 | }
24 | for i, tc := range []struct {
25 | x int
26 | t language.Tag
27 | }{
28 | {0, language.Und},
29 | {0, language.Persian}, // Default to first element when no match.
30 | {3, language.English},
31 | {4, language.AmericanEnglish},
32 | {5, language.MustParse("en-US-u-va-posix")}, // Ext. variant match.
33 | {4, language.MustParse("en-US-u-va-noposix")}, // Ext. variant mismatch.
34 | {3, language.MustParse("en-UK-u-va-noposix")}, // Ext. variant mismatch.
35 | {7, language.Serbian},
36 | {0, language.Croatian}, // Don't match to close language!
37 | {0, language.MustParse("gsw")}, // Don't match to close language!
38 | {1, language.MustParse("bs-Cyrl")}, // Odd, but correct.
39 | {1, language.MustParse("bs-Latn")}, // Estimated script drops.
40 | {8, language.MustParse("sr-Latn")},
41 | {9, language.Chinese},
42 | {10, language.SimplifiedChinese}, // Default script drops.
43 | {11, language.TraditionalChinese},
44 | {11, language.MustParse("und-TW")}, // Infer script and language.
45 | {11, language.MustParse("und-HK")}, // Infer script and language.
46 | {6, language.MustParse("und-BR")}, // Infer script and language.
47 | {6, language.MustParse("und-PT")}, // Infer script and language.
48 | {2, language.MustParse("und-Latn-DE")}, // Infer language.
49 | {0, language.MustParse("und-Jpan-BR")}, // Infers "ja", so no match.
50 | {0, language.MustParse("zu")}, // No match past index.
51 | } {
52 | if x := MatchLang(tc.t, tags); x != tc.x {
53 | t.Errorf("%d: MatchLang(%q, tags) = %d; want %d", i, tc.t, x, tc.x)
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/colltab/contract_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package colltab
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | type lookupStrings struct {
12 | str string
13 | offset int
14 | n int // bytes consumed from input
15 | }
16 |
17 | var lookupTests = []struct {
18 | lookup []lookupStrings
19 | n int
20 | tries contractTrieSet
21 | }{
22 | {
23 | []lookupStrings{
24 | {"abc", 1, 3},
25 | {"a", 0, 0},
26 | {"b", 0, 0},
27 | {"c", 0, 0},
28 | {"d", 0, 0},
29 | },
30 | 1,
31 | contractTrieSet{
32 | {'a', 0, 1, 0xFF},
33 | {'b', 0, 1, 0xFF},
34 | {'c', 'c', 0, 1},
35 | },
36 | },
37 | {
38 | []lookupStrings{
39 | {"abc", 1, 3},
40 | {"abd", 2, 3},
41 | {"abe", 3, 3},
42 | {"a", 0, 0},
43 | {"ab", 0, 0},
44 | {"d", 0, 0},
45 | {"f", 0, 0},
46 | },
47 | 1,
48 | contractTrieSet{
49 | {'a', 0, 1, 0xFF},
50 | {'b', 0, 1, 0xFF},
51 | {'c', 'e', 0, 1},
52 | },
53 | },
54 | {
55 | []lookupStrings{
56 | {"abc", 1, 3},
57 | {"ab", 2, 2},
58 | {"a", 3, 1},
59 | {"abcd", 1, 3},
60 | {"abe", 2, 2},
61 | },
62 | 1,
63 | contractTrieSet{
64 | {'a', 0, 1, 3},
65 | {'b', 0, 1, 2},
66 | {'c', 'c', 0, 1},
67 | },
68 | },
69 | {
70 | []lookupStrings{
71 | {"abc", 1, 3},
72 | {"abd", 2, 3},
73 | {"ab", 3, 2},
74 | {"ac", 4, 2},
75 | {"a", 5, 1},
76 | {"b", 6, 1},
77 | {"ba", 6, 1},
78 | },
79 | 2,
80 | contractTrieSet{
81 | {'b', 'b', 0, 6},
82 | {'a', 0, 2, 5},
83 | {'c', 'c', 0, 4},
84 | {'b', 0, 1, 3},
85 | {'c', 'd', 0, 1},
86 | },
87 | },
88 | {
89 | []lookupStrings{
90 | {"bcde", 2, 4},
91 | {"bc", 7, 2},
92 | {"ab", 6, 2},
93 | {"bcd", 5, 3},
94 | {"abcd", 1, 4},
95 | {"abc", 4, 3},
96 | {"bcdf", 3, 4},
97 | },
98 | 2,
99 | contractTrieSet{
100 | {'b', 3, 1, 0xFF},
101 | {'a', 0, 1, 0xFF},
102 | {'b', 0, 1, 6},
103 | {'c', 0, 1, 4},
104 | {'d', 'd', 0, 1},
105 | {'c', 0, 1, 7},
106 | {'d', 0, 1, 5},
107 | {'e', 'f', 0, 2},
108 | },
109 | },
110 | }
111 |
112 | func lookup(c *contractTrieSet, nnode int, s []uint8) (i, n int) {
113 | scan := c.scanner(0, nnode, s)
114 | scan.scan(0)
115 | return scan.result()
116 | }
117 |
118 | func TestLookupContraction(t *testing.T) {
119 | for i, tt := range lookupTests {
120 | cts := contractTrieSet(tt.tries)
121 | for j, lu := range tt.lookup {
122 | str := lu.str
123 | for _, s := range []string{str, str + "X"} {
124 | const msg = "%d:%d: %s of %q %v; want %v"
125 | offset, n := lookup(&cts, tt.n, []byte(s))
126 | if offset != lu.offset {
127 | t.Errorf(msg, i, j, "offset", s, offset, lu.offset)
128 | }
129 | if n != lu.n {
130 | t.Errorf(msg, i, j, "bytes consumed", s, n, len(str))
131 | }
132 | }
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/colltab/iter_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package colltab
6 |
7 | import (
8 | "testing"
9 |
10 | "golang.org/x/text/collate/colltab"
11 | )
12 |
13 | const (
14 | defaultSecondary = 0x20
15 | )
16 |
17 | func makeCE(w []int) colltab.Elem {
18 | ce, err := colltab.MakeElem(w[0], w[1], w[2], uint8(w[3]))
19 | if err != nil {
20 | panic(err)
21 | }
22 | return ce
23 | }
24 |
25 | func TestDoNorm(t *testing.T) {
26 | const div = -1 // The insertion point of the next block.
27 | tests := []struct {
28 | in, out []int
29 | }{{
30 | in: []int{4, div, 3},
31 | out: []int{3, 4},
32 | }, {
33 | in: []int{4, div, 3, 3, 3},
34 | out: []int{3, 3, 3, 4},
35 | }, {
36 | in: []int{0, 4, div, 3},
37 | out: []int{0, 3, 4},
38 | }, {
39 | in: []int{0, 0, 4, 5, div, 3, 3},
40 | out: []int{0, 0, 3, 3, 4, 5},
41 | }, {
42 | in: []int{0, 0, 1, 4, 5, div, 3, 3},
43 | out: []int{0, 0, 1, 3, 3, 4, 5},
44 | }, {
45 | in: []int{0, 0, 1, 4, 5, div, 4, 4},
46 | out: []int{0, 0, 1, 4, 4, 4, 5},
47 | },
48 | }
49 | for j, tt := range tests {
50 | i := Iter{}
51 | var w, p int
52 | for k, cc := range tt.in {
53 |
54 | if cc == div {
55 | w = 100
56 | p = k
57 | continue
58 | }
59 | i.Elems = append(i.Elems, makeCE([]int{w, defaultSecondary, 2, cc}))
60 | }
61 | i.doNorm(p, i.Elems[p].CCC())
62 | if len(i.Elems) != len(tt.out) {
63 | t.Errorf("%d: length was %d; want %d", j, len(i.Elems), len(tt.out))
64 | }
65 | prevCCC := uint8(0)
66 | for k, ce := range i.Elems {
67 | if int(ce.CCC()) != tt.out[k] {
68 | t.Errorf("%d:%d: unexpected CCC. Was %d; want %d", j, k, ce.CCC(), tt.out[k])
69 | }
70 | if k > 0 && ce.CCC() == prevCCC && i.Elems[k-1].Primary() > ce.Primary() {
71 | t.Errorf("%d:%d: normalization crossed across CCC boundary.", j, k)
72 | }
73 | }
74 | }
75 |
76 | // Combining rune overflow is tested in search/pattern_test.go.
77 | }
78 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/format/format.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package format contains types for defining language-specific formatting of
6 | // values.
7 | //
8 | // This package is internal now, but will eventually be exposed after the API
9 | // settles.
10 | package format // import "golang.org/x/text/internal/format"
11 |
12 | import (
13 | "fmt"
14 |
15 | "golang.org/x/text/language"
16 | )
17 |
18 | // State represents the printer state passed to custom formatters. It provides
19 | // access to the fmt.State interface and the sentence and language-related
20 | // context.
21 | type State interface {
22 | fmt.State
23 |
24 | // Language reports the requested language in which to render a message.
25 | Language() language.Tag
26 |
27 | // TODO: more info:
28 | // - sentence context
29 | // - user preferences, like measurement systems
30 | // - options
31 | }
32 |
33 | // A Statement is a Var or an Expression.
34 | type Statement interface {
35 | statement()
36 | }
37 |
38 | // A String a literal string format.
39 | type String string
40 |
41 | func (String) statement() {}
42 |
43 | // TODO: Select, Var, Case, StatementSequence
44 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/gen.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build ignore
6 |
7 | package main
8 |
9 | import (
10 | "log"
11 |
12 | "golang.org/x/text/internal/gen"
13 | "golang.org/x/text/language"
14 | "golang.org/x/text/unicode/cldr"
15 | )
16 |
17 | func main() {
18 | r := gen.OpenCLDRCoreZip()
19 | defer r.Close()
20 |
21 | d := &cldr.Decoder{}
22 | data, err := d.DecodeZip(r)
23 | if err != nil {
24 | log.Fatalf("DecodeZip: %v", err)
25 | }
26 |
27 | w := gen.NewCodeWriter()
28 | defer w.WriteGoFile("tables.go", "internal")
29 |
30 | // Create parents table.
31 | parents := make([]uint16, language.NumCompactTags)
32 | for _, loc := range data.Locales() {
33 | tag := language.MustParse(loc)
34 | index, ok := language.CompactIndex(tag)
35 | if !ok {
36 | continue
37 | }
38 | parentIndex := 0 // und
39 | for p := tag.Parent(); p != language.Und; p = p.Parent() {
40 | if x, ok := language.CompactIndex(p); ok {
41 | parentIndex = x
42 | break
43 | }
44 | }
45 | parents[index] = uint16(parentIndex)
46 | }
47 |
48 | w.WriteComment(`
49 | Parent maps a compact index of a tag to the compact index of the parent of
50 | this tag.`)
51 | w.WriteVar("Parent", parents)
52 | }
53 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/gen_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | import (
8 | "testing"
9 |
10 | "golang.org/x/text/language"
11 | )
12 |
13 | func TestParents(t *testing.T) {
14 | testCases := []struct {
15 | tag, parent string
16 | }{
17 | {"af", "und"},
18 | {"en", "und"},
19 | {"en-001", "en"},
20 | {"en-AU", "en-001"},
21 | {"en-US", "en"},
22 | {"en-US-u-va-posix", "en-US"},
23 | {"ca-ES-valencia", "ca"}, // ca-ES has no data.
24 | }
25 | for _, tc := range testCases {
26 | tag, ok := language.CompactIndex(language.MustParse(tc.tag))
27 | if !ok {
28 | t.Fatalf("Could not get index of flag %s", tc.tag)
29 | }
30 | want, ok := language.CompactIndex(language.MustParse(tc.parent))
31 | if !ok {
32 | t.Fatalf("Could not get index of parent %s of tag %s", tc.parent, tc.tag)
33 | }
34 | if got := int(Parent[tag]); got != want {
35 | t.Errorf("Parent[%s] = %d; want %d (%s)", tc.tag, got, want, tc.parent)
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/internal.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:generate go run gen.go
6 |
7 | // Package internal contains non-exported functionality that are used by
8 | // packages in the text repository.
9 | package internal // import "golang.org/x/text/internal"
10 |
11 | import (
12 | "sort"
13 |
14 | "golang.org/x/text/language"
15 | )
16 |
17 | // SortTags sorts tags in place.
18 | func SortTags(tags []language.Tag) {
19 | sort.Sort(sorter(tags))
20 | }
21 |
22 | type sorter []language.Tag
23 |
24 | func (s sorter) Len() int {
25 | return len(s)
26 | }
27 |
28 | func (s sorter) Swap(i, j int) {
29 | s[i], s[j] = s[j], s[i]
30 | }
31 |
32 | func (s sorter) Less(i, j int) bool {
33 | return s[i].String() < s[j].String()
34 | }
35 |
36 | // UniqueTags sorts and filters duplicate tags in place and returns a slice with
37 | // only unique tags.
38 | func UniqueTags(tags []language.Tag) []language.Tag {
39 | if len(tags) <= 1 {
40 | return tags
41 | }
42 | SortTags(tags)
43 | k := 0
44 | for i := 1; i < len(tags); i++ {
45 | if tags[k].String() < tags[i].String() {
46 | k++
47 | tags[k] = tags[i]
48 | }
49 | }
50 | return tags[:k+1]
51 | }
52 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/internal_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | import (
8 | "fmt"
9 | "strings"
10 | "testing"
11 |
12 | "golang.org/x/text/language"
13 | )
14 |
15 | func TestUnique(t *testing.T) {
16 | testCases := []struct {
17 | in, want string
18 | }{
19 | {"", "[]"},
20 | {"en", "[en]"},
21 | {"en en", "[en]"},
22 | {"en en en", "[en]"},
23 | {"en-u-cu-eur en", "[en en-u-cu-eur]"},
24 | {"nl en", "[en nl]"},
25 | {"pt-Pt pt", "[pt pt-PT]"},
26 | }
27 | for _, tc := range testCases {
28 | tags := []language.Tag{}
29 | for _, s := range strings.Split(tc.in, " ") {
30 | if s != "" {
31 | tags = append(tags, language.MustParse(s))
32 | }
33 | }
34 | if got := fmt.Sprint(UniqueTags(tags)); got != tc.want {
35 | t.Errorf("Unique(%s) = %s; want %s", tc.in, got, tc.want)
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/match.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | // This file contains matchers that implement CLDR inheritance.
8 | //
9 | // See http://unicode.org/reports/tr35/#Locale_Inheritance.
10 | //
11 | // Some of the inheritance described in this document is already handled by
12 | // the cldr package.
13 |
14 | import (
15 | "golang.org/x/text/language"
16 | )
17 |
18 | // TODO: consider if (some of the) matching algorithm needs to be public after
19 | // getting some feel about what is generic and what is specific.
20 |
21 | // NewInheritanceMatcher returns a matcher that matches based on the inheritance
22 | // chain.
23 | //
24 | // The matcher uses canonicalization and the parent relationship to find a
25 | // match. The resulting match will always be either Und or a language with the
26 | // same language and script as the requested language. It will not match
27 | // languages for which there is understood to be mutual or one-directional
28 | // intelligibility.
29 | //
30 | // A Match will indicate an Exact match if the language matches after
31 | // canonicalization and High if the matched tag is a parent.
32 | func NewInheritanceMatcher(t []language.Tag) language.Matcher {
33 | tags := make(inheritanceMatcher)
34 | for i, tag := range t {
35 | ct, err := language.All.Canonicalize(tag)
36 | if err != nil {
37 | ct = tag
38 | }
39 | tags[ct] = i
40 | }
41 | return tags
42 | }
43 |
44 | type inheritanceMatcher map[language.Tag]int
45 |
46 | func (m inheritanceMatcher) Match(want ...language.Tag) (language.Tag, int, language.Confidence) {
47 | for _, t := range want {
48 | ct, err := language.All.Canonicalize(t)
49 | if err != nil {
50 | ct = t
51 | }
52 | conf := language.Exact
53 | for {
54 | if index, ok := m[ct]; ok {
55 | return ct, index, conf
56 | }
57 | if ct == language.Und {
58 | break
59 | }
60 | ct = ct.Parent()
61 | conf = language.High
62 | }
63 | }
64 | return language.Und, 0, language.No
65 | }
66 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/match_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | import (
8 | "strings"
9 | "testing"
10 |
11 | "golang.org/x/text/language"
12 | )
13 |
14 | func TestInheritanceMatcher(t *testing.T) {
15 | for i, tt := range []struct {
16 | haveTags string
17 | wantTags string
18 | match string
19 | conf language.Confidence
20 | }{
21 | {"und,en,en-US", "en-US", "en-US", language.Exact}, // most specific match
22 | {"zh-Hant,zh", "zh-TW", "zh-Hant", language.High}, // zh-TW implies Hant.
23 | {"und,zh", "zh-TW", "und", language.High}, // zh-TW does not match zh.
24 | {"zh", "zh-TW", "und", language.No}, // zh-TW does not match zh.
25 | {"iw,en,nl", "he", "he", language.Exact}, // matches after canonicalization
26 | {"he,en,nl", "iw", "he", language.Exact}, // matches after canonicalization
27 | // Prefer first match over more specific match for various reasons:
28 | // a) consistency of user interface is more important than an exact match,
29 | // b) _if_ und is specified, it should be considered a correct and useful match,
30 | // Note that a call to this Match will almost always be with a single tag.
31 | {"und,en,en-US", "he,en-US", "und", language.High},
32 | } {
33 | have := parseTags(tt.haveTags)
34 | m := NewInheritanceMatcher(have)
35 | tag, index, conf := m.Match(parseTags(tt.wantTags)...)
36 | want := language.Raw.Make(tt.match)
37 | if tag != want {
38 | t.Errorf("%d:tag: got %q; want %q", i, tag, want)
39 | }
40 | if conf != language.No {
41 | if got, _ := language.All.Canonicalize(have[index]); got != want {
42 | t.Errorf("%d:index: got %q; want %q ", i, got, want)
43 | }
44 | }
45 | if conf != tt.conf {
46 | t.Errorf("%d:conf: got %v; want %v", i, conf, tt.conf)
47 | }
48 | }
49 | }
50 |
51 | func parseTags(list string) (out []language.Tag) {
52 | for _, s := range strings.Split(list, ",") {
53 | out = append(out, language.Raw.Make(strings.TrimSpace(s)))
54 | }
55 | return out
56 | }
57 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/tag/tag.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package tag contains functionality handling tags and related data.
6 | package tag // import "golang.org/x/text/internal/tag"
7 |
8 | import "sort"
9 |
10 | // An Index converts tags to a compact numeric value.
11 | //
12 | // All elements are of size 4. Tags may be up to 4 bytes long. Excess bytes can
13 | // be used to store additional information about the tag.
14 | type Index string
15 |
16 | // Elem returns the element data at the given index.
17 | func (s Index) Elem(x int) string {
18 | return string(s[x*4 : x*4+4])
19 | }
20 |
21 | // Index reports the index of the given key or -1 if it could not be found.
22 | // Only the first len(key) bytes from the start of the 4-byte entries will be
23 | // considered for the search and the first match in Index will be returned.
24 | func (s Index) Index(key []byte) int {
25 | n := len(key)
26 | // search the index of the first entry with an equal or higher value than
27 | // key in s.
28 | index := sort.Search(len(s)/4, func(i int) bool {
29 | return cmp(s[i*4:i*4+n], key) != -1
30 | })
31 | i := index * 4
32 | if cmp(s[i:i+len(key)], key) != 0 {
33 | return -1
34 | }
35 | return index
36 | }
37 |
38 | // Next finds the next occurrence of key after index x, which must have been
39 | // obtained from a call to Index using the same key. It returns x+1 or -1.
40 | func (s Index) Next(key []byte, x int) int {
41 | if x++; x*4 < len(s) && cmp(s[x*4:x*4+len(key)], key) == 0 {
42 | return x
43 | }
44 | return -1
45 | }
46 |
47 | // cmp returns an integer comparing a and b lexicographically.
48 | func cmp(a Index, b []byte) int {
49 | n := len(a)
50 | if len(b) < n {
51 | n = len(b)
52 | }
53 | for i, c := range b[:n] {
54 | switch {
55 | case a[i] > c:
56 | return 1
57 | case a[i] < c:
58 | return -1
59 | }
60 | }
61 | switch {
62 | case len(a) < len(b):
63 | return -1
64 | case len(a) > len(b):
65 | return 1
66 | }
67 | return 0
68 | }
69 |
70 | // Compare returns an integer comparing a and b lexicographically.
71 | func Compare(a string, b []byte) int {
72 | return cmp(Index(a), b)
73 | }
74 |
75 | // FixCase reformats b to the same pattern of cases as form.
76 | // If returns false if string b is malformed.
77 | func FixCase(form string, b []byte) bool {
78 | if len(form) != len(b) {
79 | return false
80 | }
81 | for i, c := range b {
82 | if form[i] <= 'Z' {
83 | if c >= 'a' {
84 | c -= 'z' - 'Z'
85 | }
86 | if c < 'A' || 'Z' < c {
87 | return false
88 | }
89 | } else {
90 | if c <= 'Z' {
91 | c += 'z' - 'Z'
92 | }
93 | if c < 'a' || 'z' < c {
94 | return false
95 | }
96 | }
97 | b[i] = c
98 | }
99 | return true
100 | }
101 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/tag/tag_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package tag
6 |
7 | import (
8 | "strings"
9 | "testing"
10 | )
11 |
12 | var strdata = []string{
13 | "aa ",
14 | "aaa ",
15 | "aaaa",
16 | "aaab",
17 | "aab ",
18 | "ab ",
19 | "ba ",
20 | "xxxx",
21 | "\xff\xff\xff\xff",
22 | }
23 |
24 | var testCases = map[string]int{
25 | "a": 0,
26 | "aa": 0,
27 | "aaa": 1,
28 | "aa ": 0,
29 | "aaaa": 2,
30 | "aaab": 3,
31 | "b": 6,
32 | "ba": 6,
33 | " ": -1,
34 | "aaax": -1,
35 | "bbbb": -1,
36 | "zzzz": -1,
37 | }
38 |
39 | func TestIndex(t *testing.T) {
40 | index := Index(strings.Join(strdata, ""))
41 | for k, v := range testCases {
42 | if i := index.Index([]byte(k)); i != v {
43 | t.Errorf("%s: got %d; want %d", k, i, v)
44 | }
45 | }
46 | }
47 |
48 | func TestFixCase(t *testing.T) {
49 | tests := []string{
50 | "aaaa", "AbCD", "abcd",
51 | "Zzzz", "AbCD", "Abcd",
52 | "Zzzz", "AbC", "",
53 | "XXX", "ab ", "",
54 | "XXX", "usd", "USD",
55 | "cmn", "AB ", "",
56 | "gsw", "CMN", "cmn",
57 | }
58 | for tc := tests; len(tc) > 0; tc = tc[3:] {
59 | b := []byte(tc[1])
60 | if !FixCase(tc[0], b) {
61 | b = nil
62 | }
63 | if string(b) != tc[2] {
64 | t.Errorf("FixCase(%q, %q) = %q; want %q", tc[0], tc[1], b, tc[2])
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/testtext/codesize.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package testtext
6 |
7 | import (
8 | "bytes"
9 | "fmt"
10 | "io/ioutil"
11 | "os"
12 | "os/exec"
13 | "path/filepath"
14 | "runtime"
15 | )
16 |
17 | // CodeSize builds the given code sample and returns the binary size or en error
18 | // if an error occurred. The code sample typically will look like this:
19 | // package main
20 | // import "golang.org/x/text/somepackage"
21 | // func main() {
22 | // somepackage.Func() // reference Func to cause it to be linked in.
23 | // }
24 | // See dict_test.go in the display package for an example.
25 | func CodeSize(s string) (int, error) {
26 | // Write the file.
27 | tmpdir, err := ioutil.TempDir(os.TempDir(), "testtext")
28 | if err != nil {
29 | return 0, fmt.Errorf("testtext: failed to create tmpdir: %v", err)
30 | }
31 | defer os.RemoveAll(tmpdir)
32 | filename := filepath.Join(tmpdir, "main.go")
33 | if err := ioutil.WriteFile(filename, []byte(s), 0644); err != nil {
34 | return 0, fmt.Errorf("testtext: failed to write main.go: %v", err)
35 | }
36 |
37 | // Build the binary.
38 | w := &bytes.Buffer{}
39 | cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "build", "-o", "main")
40 | cmd.Dir = tmpdir
41 | cmd.Stderr = w
42 | cmd.Stdout = w
43 | if err := cmd.Run(); err != nil {
44 | return 0, fmt.Errorf("testtext: failed to execute command: %v\nmain.go:\n%vErrors:%s", err, s, w)
45 | }
46 |
47 | // Determine the size.
48 | fi, err := os.Stat(filepath.Join(tmpdir, "main"))
49 | if err != nil {
50 | return 0, fmt.Errorf("testtext: failed to get file info: %v", err)
51 | }
52 | return int(fi.Size()), nil
53 | }
54 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/triegen/compact.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package triegen
6 |
7 | // This file defines Compacter and its implementations.
8 |
9 | import "io"
10 |
11 | // A Compacter generates an alternative, more space-efficient way to store a
12 | // trie value block. A trie value block holds all possible values for the last
13 | // byte of a UTF-8 encoded rune. Excluding ASCII characters, a trie value block
14 | // always has 64 values, as a UTF-8 encoding ends with a byte in [0x80, 0xC0).
15 | type Compacter interface {
16 | // Size returns whether the Compacter could encode the given block as well
17 | // as its size in case it can. len(v) is always 64.
18 | Size(v []uint64) (sz int, ok bool)
19 |
20 | // Store stores the block using the Compacter's compression method.
21 | // It returns a handle with which the block can be retrieved.
22 | // len(v) is always 64.
23 | Store(v []uint64) uint32
24 |
25 | // Print writes the data structures associated to the given store to w.
26 | Print(w io.Writer) error
27 |
28 | // Handler returns the name of a function that gets called during trie
29 | // lookup for blocks generated by the Compacter. The function should be of
30 | // the form func (n uint32, b byte) uint64, where n is the index returned by
31 | // the Compacter's Store method and b is the last byte of the UTF-8
32 | // encoding, where 0x80 <= b < 0xC0, for which to do the lookup in the
33 | // block.
34 | Handler() string
35 | }
36 |
37 | // simpleCompacter is the default Compacter used by builder. It implements a
38 | // normal trie block.
39 | type simpleCompacter builder
40 |
41 | func (b *simpleCompacter) Size([]uint64) (sz int, ok bool) {
42 | return blockSize * b.ValueSize, true
43 | }
44 |
45 | func (b *simpleCompacter) Store(v []uint64) uint32 {
46 | h := uint32(len(b.ValueBlocks) - blockOffset)
47 | b.ValueBlocks = append(b.ValueBlocks, v)
48 | return h
49 | }
50 |
51 | func (b *simpleCompacter) Print(io.Writer) error {
52 | // Structures are printed in print.go.
53 | return nil
54 | }
55 |
56 | func (b *simpleCompacter) Handler() string {
57 | panic("Handler should be special-cased for this Compacter")
58 | }
59 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/triegen/example_compact_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package triegen_test
6 |
7 | import (
8 | "fmt"
9 | "io"
10 | "io/ioutil"
11 |
12 | "golang.org/x/text/internal/triegen"
13 | )
14 |
15 | func ExampleCompacter() {
16 | t := triegen.NewTrie("root")
17 | for r := rune(0); r < 10000; r += 64 {
18 | t.Insert(r, 0x9015BADA55^uint64(r))
19 | }
20 | sz, _ := t.Gen(ioutil.Discard)
21 |
22 | fmt.Printf("Size normal: %5d\n", sz)
23 |
24 | var c myCompacter
25 | sz, _ = t.Gen(ioutil.Discard, triegen.Compact(&c))
26 |
27 | fmt.Printf("Size compacted: %5d\n", sz)
28 |
29 | // Output:
30 | // Size normal: 81344
31 | // Size compacted: 3224
32 | }
33 |
34 | // A myCompacter accepts a block if only the first value is given.
35 | type myCompacter []uint64
36 |
37 | func (c *myCompacter) Size(values []uint64) (sz int, ok bool) {
38 | for _, v := range values[1:] {
39 | if v != 0 {
40 | return 0, false
41 | }
42 | }
43 | return 8, true // the size of a uint64
44 | }
45 |
46 | func (c *myCompacter) Store(v []uint64) uint32 {
47 | x := uint32(len(*c))
48 | *c = append(*c, v[0])
49 | return x
50 | }
51 |
52 | func (c *myCompacter) Print(w io.Writer) error {
53 | fmt.Fprintln(w, "var firstValue = []uint64{")
54 | for _, v := range *c {
55 | fmt.Fprintf(w, "\t%#x,\n", v)
56 | }
57 | fmt.Fprintln(w, "}")
58 | return nil
59 | }
60 |
61 | func (c *myCompacter) Handler() string {
62 | return "getFirstValue"
63 |
64 | // Where getFirstValue is included along with the generated code:
65 | // func getFirstValue(n uint32, b byte) uint64 {
66 | // if b == 0x80 { // the first continuation byte
67 | // return firstValue[n]
68 | // }
69 | // return 0
70 | // }
71 | }
72 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/triegen/gen_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build generate
6 |
7 | package triegen_test
8 |
9 | // The code in this file generates captures and writes the tries generated in
10 | // the examples to data_test.go. To invoke it, run:
11 | // go test -tags=generate
12 | //
13 | // Making the generation code a "test" allows us to link in the necessary test
14 | // code.
15 |
16 | import (
17 | "log"
18 | "os"
19 | "os/exec"
20 | )
21 |
22 | func init() {
23 | const tmpfile = "tmpout"
24 | const dstfile = "data_test.go"
25 |
26 | f, err := os.Create(tmpfile)
27 | if err != nil {
28 | log.Fatalf("Could not create output file: %v", err)
29 | }
30 | defer os.Remove(tmpfile)
31 | defer f.Close()
32 |
33 | // We exit before this function returns, regardless of success or failure,
34 | // so there's no need to save (and later restore) the existing genWriter
35 | // value.
36 | genWriter = f
37 |
38 | f.Write([]byte(header))
39 |
40 | Example_build()
41 | ExampleGen_build()
42 |
43 | if err := exec.Command("gofmt", "-w", tmpfile).Run(); err != nil {
44 | log.Fatal(err)
45 | }
46 | os.Remove(dstfile)
47 | os.Rename(tmpfile, dstfile)
48 |
49 | os.Exit(0)
50 | }
51 |
52 | const header = `// This file is generated with "go test -tags generate". DO NOT EDIT!
53 | // +build !generate
54 |
55 | package triegen_test
56 | `
57 |
58 | // Stubs for generated tries. These are needed as we exclude data_test.go if
59 | // the generate flag is set. This will clearly make the tests fail, but that
60 | // is okay. It allows us to bootstrap.
61 |
62 | type trie struct{}
63 |
64 | func (t *trie) lookupString(string) (uint8, int) { return 0, 1 }
65 | func (t *trie) lookupStringUnsafe(string) uint64 { return 0 }
66 |
67 | func newRandTrie(i int) *trie { return &trie{} }
68 | func newMultiTrie(i int) *trie { return &trie{} }
69 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/ucd/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package ucd_test
6 |
7 | import (
8 | "fmt"
9 | "strings"
10 |
11 | "golang.org/x/text/internal/ucd"
12 | )
13 |
14 | func Example() {
15 | // Read rune-by-rune from UnicodeData.
16 | var count int
17 | p := ucd.New(strings.NewReader(unicodeData))
18 | for p.Next() {
19 | count++
20 | if lower := p.Runes(ucd.SimpleLowercaseMapping); lower != nil {
21 | fmt.Printf("lower(%U) -> %U\n", p.Rune(0), lower[0])
22 | }
23 | }
24 | if err := p.Err(); err != nil {
25 | fmt.Println(err)
26 | }
27 | fmt.Println("Number of runes visited:", count)
28 |
29 | // Read raw ranges from Scripts.
30 | p = ucd.New(strings.NewReader(scripts), ucd.KeepRanges)
31 | for p.Next() {
32 | start, end := p.Range(0)
33 | fmt.Printf("%04X..%04X: %s\n", start, end, p.String(1))
34 | }
35 | if err := p.Err(); err != nil {
36 | fmt.Println(err)
37 | }
38 |
39 | // Output:
40 | // lower(U+00C0) -> U+00E0
41 | // lower(U+00C1) -> U+00E1
42 | // lower(U+00C2) -> U+00E2
43 | // lower(U+00C3) -> U+00E3
44 | // lower(U+00C4) -> U+00E4
45 | // Number of runes visited: 6594
46 | // 0000..001F: Common
47 | // 0020..0020: Common
48 | // 0021..0023: Common
49 | // 0024..0024: Common
50 | }
51 |
52 | // Excerpt from UnicodeData.txt
53 | const unicodeData = `
54 | 00B9;SUPERSCRIPT ONE;No;0;EN; 0031;;1;1;N;SUPERSCRIPT DIGIT ONE;;;;
55 | 00BA;MASCULINE ORDINAL INDICATOR;Lo;0;L; 006F;;;;N;;;;;
56 | 00BB;RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK;Pf;0;ON;;;;;Y;RIGHT POINTING GUILLEMET;;;;
57 | 00BC;VULGAR FRACTION ONE QUARTER;No;0;ON; 0031 2044 0034;;;1/4;N;FRACTION ONE QUARTER;;;;
58 | 00BD;VULGAR FRACTION ONE HALF;No;0;ON; 0031 2044 0032;;;1/2;N;FRACTION ONE HALF;;;;
59 | 00BE;VULGAR FRACTION THREE QUARTERS;No;0;ON; 0033 2044 0034;;;3/4;N;FRACTION THREE QUARTERS;;;;
60 | 00BF;INVERTED QUESTION MARK;Po;0;ON;;;;;N;;;;;
61 | 00C0;LATIN CAPITAL LETTER A WITH GRAVE;Lu;0;L;0041 0300;;;;N;LATIN CAPITAL LETTER A GRAVE;;;00E0;
62 | 00C1;LATIN CAPITAL LETTER A WITH ACUTE;Lu;0;L;0041 0301;;;;N;LATIN CAPITAL LETTER A ACUTE;;;00E1;
63 | 00C2;LATIN CAPITAL LETTER A WITH CIRCUMFLEX;Lu;0;L;0041 0302;;;;N;LATIN CAPITAL LETTER A CIRCUMFLEX;;;00E2;
64 | 00C3;LATIN CAPITAL LETTER A WITH TILDE;Lu;0;L;0041 0303;;;;N;LATIN CAPITAL LETTER A TILDE;;;00E3;
65 | 00C4;LATIN CAPITAL LETTER A WITH DIAERESIS;Lu;0;L;0041 0308;;;;N;LATIN CAPITAL LETTER A DIAERESIS;;;00E4;
66 |
67 | # A legacy rune range.
68 | 3400;;Lo;0;L;;;;;N;;;;;
69 | 4DB5;;Lo;0;L;;;;;N;;;;;
70 | `
71 |
72 | // Excerpt from Scripts.txt
73 | const scripts = `
74 | # Property: Script
75 | # ================================================
76 |
77 | 0000..001F ; Common # Cc [32] ..
78 | 0020 ; Common # Zs SPACE
79 | 0021..0023 ; Common # Po [3] EXCLAMATION MARK..NUMBER SIGN
80 | 0024 ; Common # Sc DOLLAR SIGN
81 | `
82 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/internal/ucd/ucd_test.go:
--------------------------------------------------------------------------------
1 | package ucd
2 |
3 | import (
4 | "strings"
5 | "testing"
6 | )
7 |
8 | const file = `
9 | # Comments should be skipped
10 | # rune; bool; uint; int; float; runes; # Y
11 | 0..0005; Y; 0; 2; -5.25 ; 0 1 2 3 4 5;
12 | 6..0007; Yes ; 6; 1; -4.25 ; 0006 0007;
13 | 8; T ; 8 ; 0 ;-3.25 ;;# T
14 | 9; True ;9 ; -1;-2.25 ; 0009;
15 |
16 | # more comments to be ignored
17 | @Part0
18 |
19 | A; N; 10 ; -2; -1.25; ;# N
20 | B; No; 11 ; -3; -0.25;
21 | C; False;12; -4; 0.75;
22 | D; ;13;-5;1.75;
23 |
24 | @Part1 # Another part.
25 | # We test part comments get removed by not commenting the the next line.
26 | E..10FFFF; F; 14 ; -6; 2.75;
27 | `
28 |
29 | var want = []struct {
30 | start, end rune
31 | }{
32 | {0x00, 0x05},
33 | {0x06, 0x07},
34 | {0x08, 0x08},
35 | {0x09, 0x09},
36 | {0x0A, 0x0A},
37 | {0x0B, 0x0B},
38 | {0x0C, 0x0C},
39 | {0x0D, 0x0D},
40 | {0x0E, 0x10FFFF},
41 | }
42 |
43 | func TestGetters(t *testing.T) {
44 | parts := [][2]string{
45 | {"Part0", ""},
46 | {"Part1", "Another part."},
47 | }
48 | handler := func(p *Parser) {
49 | if len(parts) == 0 {
50 | t.Error("Part handler invoked too many times.")
51 | return
52 | }
53 | want := parts[0]
54 | parts = parts[1:]
55 | if got0, got1 := p.String(0), p.Comment(); got0 != want[0] || got1 != want[1] {
56 | t.Errorf(`part: got %q, %q; want %q"`, got0, got1, want)
57 | }
58 | }
59 |
60 | p := New(strings.NewReader(file), KeepRanges, Part(handler))
61 | for i := 0; p.Next(); i++ {
62 | start, end := p.Range(0)
63 | w := want[i]
64 | if start != w.start || end != w.end {
65 | t.Fatalf("%d:Range(0); got %#x..%#x; want %#x..%#x", i, start, end, w.start, w.end)
66 | }
67 | if w.start == w.end && p.Rune(0) != w.start {
68 | t.Errorf("%d:Range(0).start: got %U; want %U", i, p.Rune(0), w.start)
69 | }
70 | if got, want := p.Bool(1), w.start <= 9; got != want {
71 | t.Errorf("%d:Bool(1): got %v; want %v", i, got, want)
72 | }
73 | if got := p.Rune(4); got != 0 || p.Err() == nil {
74 | t.Errorf("%d:Rune(%q): got no error; want error", i, p.String(1))
75 | }
76 | p.err = nil
77 | if got := p.Uint(2); rune(got) != start {
78 | t.Errorf("%d:Uint(2): got %v; want %v", i, got, start)
79 | }
80 | if got, want := p.Int(3), 2-i; got != want {
81 | t.Errorf("%d:Int(3): got %v; want %v", i, got, want)
82 | }
83 | if got, want := p.Float(4), -5.25+float64(i); got != want {
84 | t.Errorf("%d:Int(3): got %v; want %v", i, got, want)
85 | }
86 | if got := p.Runes(5); got == nil {
87 | if p.String(5) != "" {
88 | t.Errorf("%d:Runes(5): expected non-empty list", i)
89 | }
90 | } else {
91 | if got[0] != start || got[len(got)-1] != end {
92 | t.Errorf("%d:Runes(5): got %#x; want %#x..%#x", i, got, start, end)
93 | }
94 | }
95 | if got := p.Comment(); got != "" && got != p.String(1) {
96 | t.Errorf("%d:Comment(): got %v; want %v", i, got, p.String(1))
97 | }
98 | }
99 | if err := p.Err(); err != nil {
100 | t.Errorf("Parser error: %v", err)
101 | }
102 | if len(parts) != 0 {
103 | t.Errorf("expected %d more invocations of part handler", len(parts))
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/language/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright 2013 The Go Authors. All rights reserved.
2 | # Use of this source code is governed by a BSD-style
3 | # license that can be found in the LICENSE file.
4 |
5 | CLEANFILES+=maketables
6 |
7 | maketables: maketables.go
8 | go build $^
9 |
10 | tables: maketables
11 | ./maketables > tables.go
12 | gofmt -w -s tables.go
13 |
14 | # Build (but do not run) maketables during testing,
15 | # just to make sure it still compiles.
16 | testshort: maketables
17 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/language/common.go:
--------------------------------------------------------------------------------
1 | // This file was generated by go generate; DO NOT EDIT
2 |
3 | package language
4 |
5 | // This file contains code common to the maketables.go and the package code.
6 |
7 | // langAliasType is the type of an alias in langAliasMap.
8 | type langAliasType int8
9 |
10 | const (
11 | langDeprecated langAliasType = iota
12 | langMacro
13 | langLegacy
14 |
15 | langAliasTypeUnknown langAliasType = -1
16 | )
17 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/language/display/dict_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package display
6 |
7 | import (
8 | "fmt"
9 | "testing"
10 |
11 | "golang.org/x/text/internal/testtext"
12 | )
13 |
14 | func TestLinking(t *testing.T) {
15 | base := getSize(t, `display.Tags(language.English).Name(language.English)`)
16 | compact := getSize(t, `display.English.Languages().Name(language.English)`)
17 |
18 | if d := base - compact; d < 1.5*1024*1024 {
19 | t.Errorf("size(base)-size(compact) was %d; want > 1.5MB", base, compact)
20 | }
21 | }
22 |
23 | func getSize(t *testing.T, main string) int {
24 | size, err := testtext.CodeSize(fmt.Sprintf(body, main))
25 | if err != nil {
26 | t.Skipf("skipping link size test; binary size could not be determined: %v", err)
27 | }
28 | return size
29 | }
30 |
31 | const body = `package main
32 | import (
33 | "golang.org/x/text/language"
34 | "golang.org/x/text/language/display"
35 | )
36 | func main() {
37 | %s
38 | }
39 | `
40 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/language/display/examples_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package display_test
6 |
7 | import (
8 | "fmt"
9 |
10 | "golang.org/x/text/language"
11 | "golang.org/x/text/language/display"
12 | )
13 |
14 | func ExampleNamer() {
15 | supported := []string{
16 | "en-US", "en-GB", "ja", "zh", "zh-Hans", "zh-Hant", "pt", "pt-PT", "ko", "ar", "el", "ru", "uk", "pa",
17 | }
18 |
19 | en := display.English.Languages()
20 |
21 | for _, s := range supported {
22 | t := language.MustParse(s)
23 | fmt.Printf("%-20s (%s)\n", en.Name(t), display.Self.Name(t))
24 | }
25 |
26 | // Output:
27 | // American English (American English)
28 | // British English (British English)
29 | // Japanese (日本語)
30 | // Chinese (中文)
31 | // Simplified Chinese (简体中文)
32 | // Traditional Chinese (繁體中文)
33 | // Portuguese (português)
34 | // European Portuguese (português europeu)
35 | // Korean (한국어)
36 | // Arabic (العربية)
37 | // Greek (Ελληνικά)
38 | // Russian (русский)
39 | // Ukrainian (українська)
40 | // Punjabi (ਪੰਜਾਬੀ)
41 | }
42 |
43 | func ExampleTags() {
44 | n := display.Tags(language.English)
45 | fmt.Println(n.Name(language.Make("nl")))
46 | fmt.Println(n.Name(language.Make("nl-BE")))
47 | fmt.Println(n.Name(language.Make("nl-CW")))
48 | fmt.Println(n.Name(language.Make("nl-Arab")))
49 | fmt.Println(n.Name(language.Make("nl-Cyrl-RU")))
50 |
51 | // Output:
52 | // Dutch
53 | // Flemish
54 | // Dutch (Curaçao)
55 | // Dutch (Arabic)
56 | // Dutch (Cyrillic, Russia)
57 | }
58 |
59 | // ExampleDictionary shows how to reduce the amount of data linked into your
60 | // binary by only using the predefined Dictionary variables of the languages you
61 | // wish to support.
62 | func ExampleDictionary() {
63 | tags := []language.Tag{
64 | language.English,
65 | language.German,
66 | language.Japanese,
67 | language.Russian,
68 | }
69 | dicts := []*display.Dictionary{
70 | display.English,
71 | display.German,
72 | display.Japanese,
73 | display.Russian,
74 | }
75 |
76 | m := language.NewMatcher(tags)
77 |
78 | getDict := func(t language.Tag) *display.Dictionary {
79 | _, i, confidence := m.Match(t)
80 | // Skip this check if you want to support a fall-back language, which
81 | // will be the first one passed to NewMatcher.
82 | if confidence == language.No {
83 | return nil
84 | }
85 | return dicts[i]
86 | }
87 |
88 | // The matcher will match Swiss German to German.
89 | n := getDict(language.Make("gsw")).Languages()
90 | fmt.Println(n.Name(language.German))
91 | fmt.Println(n.Name(language.Make("de-CH")))
92 | fmt.Println(n.Name(language.Make("gsw")))
93 |
94 | // Output:
95 | // Deutsch
96 | // Schweizer Hochdeutsch
97 | // Schweizerdeutsch
98 | }
99 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/language/gen_common.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build ignore
6 |
7 | package main
8 |
9 | // This file contains code common to the maketables.go and the package code.
10 |
11 | // langAliasType is the type of an alias in langAliasMap.
12 | type langAliasType int8
13 |
14 | const (
15 | langDeprecated langAliasType = iota
16 | langMacro
17 | langLegacy
18 |
19 | langAliasTypeUnknown langAliasType = -1
20 | )
21 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/language/go1_1.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !go1.2
6 |
7 | package language
8 |
9 | import "sort"
10 |
11 | func sortStable(s sort.Interface) {
12 | ss := stableSort{
13 | s: s,
14 | pos: make([]int, s.Len()),
15 | }
16 | for i := range ss.pos {
17 | ss.pos[i] = i
18 | }
19 | sort.Sort(&ss)
20 | }
21 |
22 | type stableSort struct {
23 | s sort.Interface
24 | pos []int
25 | }
26 |
27 | func (s *stableSort) Len() int {
28 | return len(s.pos)
29 | }
30 |
31 | func (s *stableSort) Less(i, j int) bool {
32 | return s.s.Less(i, j) || !s.s.Less(j, i) && s.pos[i] < s.pos[j]
33 | }
34 |
35 | func (s *stableSort) Swap(i, j int) {
36 | s.s.Swap(i, j)
37 | s.pos[i], s.pos[j] = s.pos[j], s.pos[i]
38 | }
39 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/language/go1_2.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.2
6 |
7 | package language
8 |
9 | import "sort"
10 |
11 | var sortStable = sort.Stable
12 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/message/catalog_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package message
6 |
7 | import (
8 | "reflect"
9 | "testing"
10 |
11 | "golang.org/x/text/internal"
12 | "golang.org/x/text/language"
13 | )
14 |
15 | type entry struct{ tag, key, msg string }
16 |
17 | var testCases = []struct {
18 | desc string
19 | cat []entry
20 | lookup []entry
21 | }{{
22 | desc: "empty catalog",
23 | lookup: []entry{
24 | {"en", "key", ""},
25 | {"en", "", ""},
26 | {"nl", "", ""},
27 | },
28 | }, {
29 | desc: "one entry",
30 | cat: []entry{
31 | {"en", "hello", "Hello!"},
32 | },
33 | lookup: []entry{
34 | {"und", "hello", ""},
35 | {"nl", "hello", ""},
36 | {"en", "hello", "Hello!"},
37 | {"en-US", "hello", "Hello!"},
38 | {"en-GB", "hello", "Hello!"},
39 | {"en-oxendict", "hello", "Hello!"},
40 | {"en-oxendict-u-ms-metric", "hello", "Hello!"},
41 | },
42 | }, {
43 | desc: "hierarchical languages",
44 | cat: []entry{
45 | {"en", "hello", "Hello!"},
46 | {"en-GB", "hello", "Hellø!"},
47 | {"en-US", "hello", "Howdy!"},
48 | {"en", "greetings", "Greetings!"},
49 | },
50 | lookup: []entry{
51 | {"und", "hello", ""},
52 | {"nl", "hello", ""},
53 | {"en", "hello", "Hello!"},
54 | {"en-US", "hello", "Howdy!"},
55 | {"en-GB", "hello", "Hellø!"},
56 | {"en-oxendict", "hello", "Hello!"},
57 | {"en-US-oxendict-u-ms-metric", "hello", "Howdy!"},
58 |
59 | {"und", "greetings", ""},
60 | {"nl", "greetings", ""},
61 | {"en", "greetings", "Greetings!"},
62 | {"en-US", "greetings", "Greetings!"},
63 | {"en-GB", "greetings", "Greetings!"},
64 | {"en-oxendict", "greetings", "Greetings!"},
65 | {"en-US-oxendict-u-ms-metric", "greetings", "Greetings!"},
66 | },
67 | }}
68 |
69 | func initCat(entries []entry) (*Catalog, []language.Tag) {
70 | tags := []language.Tag{}
71 | cat := newCatalog()
72 | for _, e := range entries {
73 | tag := language.MustParse(e.tag)
74 | tags = append(tags, tag)
75 | cat.SetString(tag, e.key, e.msg)
76 | }
77 | return cat, internal.UniqueTags(tags)
78 | }
79 |
80 | func TestCatalog(t *testing.T) {
81 | for _, tc := range testCases {
82 | cat, wantTags := initCat(tc.cat)
83 |
84 | // languages
85 | if got := cat.Languages(); !reflect.DeepEqual(got, wantTags) {
86 | t.Errorf("%s:Languages: got %v; want %v", tc.desc, got, wantTags)
87 | }
88 |
89 | // Lookup
90 | for _, e := range tc.lookup {
91 | tag := language.MustParse(e.tag)
92 | msg, ok := cat.get(tag, e.key)
93 | if okWant := e.msg != ""; ok != okWant || msg != e.msg {
94 | t.Errorf("%s:Lookup(%s, %s) = %s, %v; want %s, %v", tc.desc, tag, e.key, msg, ok, e.msg, okWant)
95 | }
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/runes/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package runes_test
6 |
7 | import (
8 | "fmt"
9 | "unicode"
10 |
11 | "golang.org/x/text/runes"
12 | "golang.org/x/text/transform"
13 | "golang.org/x/text/unicode/norm"
14 | "golang.org/x/text/width"
15 | )
16 |
17 | func ExampleRemove() {
18 | t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
19 | s, _, _ := transform.String(t, "résumé")
20 | fmt.Println(s)
21 |
22 | // Output:
23 | // resume
24 | }
25 |
26 | func ExampleMap() {
27 | replaceHyphens := runes.Map(func(r rune) rune {
28 | if unicode.Is(unicode.Hyphen, r) {
29 | return '|'
30 | }
31 | return r
32 | })
33 | s, _, _ := transform.String(replaceHyphens, "a-b‐c⸗d﹣e")
34 | fmt.Println(s)
35 |
36 | // Output:
37 | // a|b|c|d|e
38 | }
39 |
40 | func ExampleIn() {
41 | // Convert Latin characters to their canonical form, while keeping other
42 | // width distinctions.
43 | t := runes.If(runes.In(unicode.Latin), width.Fold, nil)
44 | s, _, _ := transform.String(t, "アルアノリウ tech / アルアノリウ tech")
45 | fmt.Println(s)
46 |
47 | // Output:
48 | // アルアノリウ tech / アルアノリウ tech
49 | }
50 |
51 | func ExampleIf() {
52 | // Widen everything but ASCII.
53 | isASCII := func(r rune) bool { return r <= unicode.MaxASCII }
54 | t := runes.If(runes.Predicate(isASCII), nil, width.Widen)
55 | s, _, _ := transform.String(t, "アルアノリウ tech / 中國 / 5₩")
56 | fmt.Println(s)
57 |
58 | // Output:
59 | // アルアノリウ tech / 中國 / 5₩
60 | }
61 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/search/index.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Note: this file is identical to the file text/collate/index.go. Both files
6 | // will be removed when the new colltab package is finished and in use.
7 |
8 | package search
9 |
10 | // tableIndex holds information for constructing a table
11 | // for a certain locale based on the main table.
12 | type tableIndex struct {
13 | lookupOffset uint32
14 | valuesOffset uint32
15 | }
16 |
17 | func (t tableIndex) TrieIndex() []uint16 {
18 | return mainLookup[:]
19 | }
20 |
21 | func (t tableIndex) TrieValues() []uint32 {
22 | return mainValues[:]
23 | }
24 |
25 | func (t tableIndex) FirstBlockOffsets() (lookup, value uint16) {
26 | return uint16(t.lookupOffset), uint16(t.valuesOffset)
27 | }
28 |
29 | func (t tableIndex) ExpandElems() []uint32 {
30 | return mainExpandElem[:]
31 | }
32 |
33 | func (t tableIndex) ContractTries() []struct{ l, h, n, i uint8 } {
34 | return mainCTEntries[:]
35 | }
36 |
37 | func (t tableIndex) ContractElems() []uint32 {
38 | return mainContractElem[:]
39 | }
40 |
41 | func (t tableIndex) MaxContractLen() int {
42 | return 18 // TODO: generate
43 | }
44 |
45 | func (t tableIndex) VariableTop() uint32 {
46 | return varTop
47 | }
48 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/transform/examples_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package transform_test
6 |
7 | import (
8 | "fmt"
9 | "unicode"
10 |
11 | "golang.org/x/text/transform"
12 | "golang.org/x/text/unicode/norm"
13 | )
14 |
15 | func ExampleRemoveFunc() {
16 | input := []byte(`tschüß; до свидания`)
17 |
18 | b := make([]byte, len(input))
19 |
20 | t := transform.RemoveFunc(unicode.IsSpace)
21 | n, _, _ := t.Transform(b, input, true)
22 | fmt.Println(string(b[:n]))
23 |
24 | t = transform.RemoveFunc(func(r rune) bool {
25 | return !unicode.Is(unicode.Latin, r)
26 | })
27 | n, _, _ = t.Transform(b, input, true)
28 | fmt.Println(string(b[:n]))
29 |
30 | n, _, _ = t.Transform(b, norm.NFD.Bytes(input), true)
31 | fmt.Println(string(b[:n]))
32 |
33 | // Output:
34 | // tschüß;досвидания
35 | // tschüß
36 | // tschuß
37 | }
38 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/cldr/cldr_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package cldr
6 |
7 | import "testing"
8 |
9 | func TestParseDraft(t *testing.T) {
10 | tests := []struct {
11 | in string
12 | draft Draft
13 | err bool
14 | }{
15 | {"unconfirmed", Unconfirmed, false},
16 | {"provisional", Provisional, false},
17 | {"contributed", Contributed, false},
18 | {"approved", Approved, false},
19 | {"", Approved, false},
20 | {"foo", Approved, true},
21 | }
22 | for _, tt := range tests {
23 | if d, err := ParseDraft(tt.in); d != tt.draft || (err != nil) != tt.err {
24 | t.Errorf("%q: was %v, %v; want %v, %v", tt.in, d, err != nil, tt.draft, tt.err)
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/cldr/examples_test.go:
--------------------------------------------------------------------------------
1 | package cldr_test
2 |
3 | import (
4 | "fmt"
5 |
6 | "golang.org/x/text/unicode/cldr"
7 | )
8 |
9 | func ExampleSlice() {
10 | var dr *cldr.CLDR // assume this is initalized
11 |
12 | x, _ := dr.LDML("en")
13 | cs := x.Collations.Collation
14 | // remove all but the default
15 | cldr.MakeSlice(&cs).Filter(func(e cldr.Elem) bool {
16 | return e.GetCommon().Type != x.Collations.Default()
17 | })
18 | for i, c := range cs {
19 | fmt.Println(i, c.Type)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // unicode holds packages with implementations of Unicode standards that are
6 | // mostly used as building blocks for other packages in golang.org/x/text,
7 | // layout engines, or are otherwise more low-level in nature.
8 | package unicode
9 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/norm/example_iter_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm_test
6 |
7 | import (
8 | "bytes"
9 | "fmt"
10 | "unicode/utf8"
11 |
12 | "golang.org/x/text/unicode/norm"
13 | )
14 |
15 | // EqualSimple uses a norm.Iter to compare two non-normalized
16 | // strings for equivalence.
17 | func EqualSimple(a, b string) bool {
18 | var ia, ib norm.Iter
19 | ia.InitString(norm.NFKD, a)
20 | ib.InitString(norm.NFKD, b)
21 | for !ia.Done() && !ib.Done() {
22 | if !bytes.Equal(ia.Next(), ib.Next()) {
23 | return false
24 | }
25 | }
26 | return ia.Done() && ib.Done()
27 | }
28 |
29 | // FindPrefix finds the longest common prefix of ASCII characters
30 | // of a and b.
31 | func FindPrefix(a, b string) int {
32 | i := 0
33 | for ; i < len(a) && i < len(b) && a[i] < utf8.RuneSelf && a[i] == b[i]; i++ {
34 | }
35 | return i
36 | }
37 |
38 | // EqualOpt is like EqualSimple, but optimizes the special
39 | // case for ASCII characters.
40 | func EqualOpt(a, b string) bool {
41 | n := FindPrefix(a, b)
42 | a, b = a[n:], b[n:]
43 | var ia, ib norm.Iter
44 | ia.InitString(norm.NFKD, a)
45 | ib.InitString(norm.NFKD, b)
46 | for !ia.Done() && !ib.Done() {
47 | if !bytes.Equal(ia.Next(), ib.Next()) {
48 | return false
49 | }
50 | if n := int64(FindPrefix(a[ia.Pos():], b[ib.Pos():])); n != 0 {
51 | ia.Seek(n, 1)
52 | ib.Seek(n, 1)
53 | }
54 | }
55 | return ia.Done() && ib.Done()
56 | }
57 |
58 | var compareTests = []struct{ a, b string }{
59 | {"aaa", "aaa"},
60 | {"aaa", "aab"},
61 | {"a\u0300a", "\u00E0a"},
62 | {"a\u0300\u0320b", "a\u0320\u0300b"},
63 | {"\u1E0A\u0323", "\x44\u0323\u0307"},
64 | // A character that decomposes into multiple segments
65 | // spans several iterations.
66 | {"\u3304", "\u30A4\u30CB\u30F3\u30AF\u3099"},
67 | }
68 |
69 | func ExampleIter() {
70 | for i, t := range compareTests {
71 | r0 := EqualSimple(t.a, t.b)
72 | r1 := EqualOpt(t.a, t.b)
73 | fmt.Printf("%d: %v %v\n", i, r0, r1)
74 | }
75 | // Output:
76 | // 0: true true
77 | // 1: false false
78 | // 2: true true
79 | // 3: true true
80 | // 4: true true
81 | // 5: true true
82 | }
83 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/norm/forminfo_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build test
6 |
7 | package norm
8 |
9 | import "testing"
10 |
11 | func TestProperties(t *testing.T) {
12 | var d runeData
13 | CK := [2]string{"C", "K"}
14 | for k, r := 1, rune(0); r < 0x2ffff; r++ {
15 | if k < len(testData) && r == testData[k].r {
16 | d = testData[k]
17 | k++
18 | }
19 | s := string(r)
20 | for j, p := range []Properties{NFC.PropertiesString(s), NFKC.PropertiesString(s)} {
21 | f := d.f[j]
22 | if p.CCC() != d.ccc {
23 | t.Errorf("%U: ccc(%s): was %d; want %d %X", r, CK[j], p.CCC(), d.ccc, p.index)
24 | }
25 | if p.isYesC() != (f.qc == Yes) {
26 | t.Errorf("%U: YesC(%s): was %v; want %v", r, CK[j], p.isYesC(), f.qc == Yes)
27 | }
28 | if p.combinesBackward() != (f.qc == Maybe) {
29 | t.Errorf("%U: combines backwards(%s): was %v; want %v", r, CK[j], p.combinesBackward(), f.qc == Maybe)
30 | }
31 | if p.nLeadingNonStarters() != d.nLead {
32 | t.Errorf("%U: nLead(%s): was %d; want %d %#v %#v", r, CK[j], p.nLeadingNonStarters(), d.nLead, p, d)
33 | }
34 | if p.nTrailingNonStarters() != d.nTrail {
35 | t.Errorf("%U: nTrail(%s): was %d; want %d %#v %#v", r, CK[j], p.nTrailingNonStarters(), d.nTrail, p, d)
36 | }
37 | if p.combinesForward() != f.combinesForward {
38 | t.Errorf("%U: combines forward(%s): was %v; want %v %#v", r, CK[j], p.combinesForward(), f.combinesForward, p)
39 | }
40 | // Skip Hangul as it is algorithmically computed.
41 | if r >= hangulBase && r < hangulEnd {
42 | continue
43 | }
44 | if p.hasDecomposition() {
45 | if has := f.decomposition != ""; !has {
46 | t.Errorf("%U: hasDecomposition(%s): was %v; want %v", r, CK[j], p.hasDecomposition(), has)
47 | }
48 | if string(p.Decomposition()) != f.decomposition {
49 | t.Errorf("%U: decomp(%s): was %+q; want %+q", r, CK[j], p.Decomposition(), f.decomposition)
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/norm/input.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm
6 |
7 | import "unicode/utf8"
8 |
9 | type input struct {
10 | str string
11 | bytes []byte
12 | }
13 |
14 | func inputBytes(str []byte) input {
15 | return input{bytes: str}
16 | }
17 |
18 | func inputString(str string) input {
19 | return input{str: str}
20 | }
21 |
22 | func (in *input) setBytes(str []byte) {
23 | in.str = ""
24 | in.bytes = str
25 | }
26 |
27 | func (in *input) setString(str string) {
28 | in.str = str
29 | in.bytes = nil
30 | }
31 |
32 | func (in *input) _byte(p int) byte {
33 | if in.bytes == nil {
34 | return in.str[p]
35 | }
36 | return in.bytes[p]
37 | }
38 |
39 | func (in *input) skipASCII(p, max int) int {
40 | if in.bytes == nil {
41 | for ; p < max && in.str[p] < utf8.RuneSelf; p++ {
42 | }
43 | } else {
44 | for ; p < max && in.bytes[p] < utf8.RuneSelf; p++ {
45 | }
46 | }
47 | return p
48 | }
49 |
50 | func (in *input) skipContinuationBytes(p int) int {
51 | if in.bytes == nil {
52 | for ; p < len(in.str) && !utf8.RuneStart(in.str[p]); p++ {
53 | }
54 | } else {
55 | for ; p < len(in.bytes) && !utf8.RuneStart(in.bytes[p]); p++ {
56 | }
57 | }
58 | return p
59 | }
60 |
61 | func (in *input) appendSlice(buf []byte, b, e int) []byte {
62 | if in.bytes != nil {
63 | return append(buf, in.bytes[b:e]...)
64 | }
65 | for i := b; i < e; i++ {
66 | buf = append(buf, in.str[i])
67 | }
68 | return buf
69 | }
70 |
71 | func (in *input) copySlice(buf []byte, b, e int) int {
72 | if in.bytes == nil {
73 | return copy(buf, in.str[b:e])
74 | }
75 | return copy(buf, in.bytes[b:e])
76 | }
77 |
78 | func (in *input) charinfoNFC(p int) (uint16, int) {
79 | if in.bytes == nil {
80 | return nfcData.lookupString(in.str[p:])
81 | }
82 | return nfcData.lookup(in.bytes[p:])
83 | }
84 |
85 | func (in *input) charinfoNFKC(p int) (uint16, int) {
86 | if in.bytes == nil {
87 | return nfkcData.lookupString(in.str[p:])
88 | }
89 | return nfkcData.lookup(in.bytes[p:])
90 | }
91 |
92 | func (in *input) hangul(p int) (r rune) {
93 | if in.bytes == nil {
94 | if !isHangulString(in.str[p:]) {
95 | return 0
96 | }
97 | r, _ = utf8.DecodeRuneInString(in.str[p:])
98 | } else {
99 | if !isHangul(in.bytes[p:]) {
100 | return 0
101 | }
102 | r, _ = utf8.DecodeRune(in.bytes[p:])
103 | }
104 | return r
105 | }
106 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/norm/norm_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm_test
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func TestPlaceHolder(t *testing.T) {
12 | // Does nothing, just allows the Makefile to be canonical
13 | // while waiting for the package itself to be written.
14 | }
15 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/norm/readwriter_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm
6 |
7 | import (
8 | "bytes"
9 | "fmt"
10 | "testing"
11 | )
12 |
13 | var bufSizes = []int{1, 2, 3, 4, 5, 6, 7, 8, 100, 101, 102, 103, 4000, 4001, 4002, 4003}
14 |
15 | func readFunc(size int) appendFunc {
16 | return func(f Form, out []byte, s string) []byte {
17 | out = append(out, s...)
18 | r := f.Reader(bytes.NewBuffer(out))
19 | buf := make([]byte, size)
20 | result := []byte{}
21 | for n, err := 0, error(nil); err == nil; {
22 | n, err = r.Read(buf)
23 | result = append(result, buf[:n]...)
24 | }
25 | return result
26 | }
27 | }
28 |
29 | func TestReader(t *testing.T) {
30 | for _, s := range bufSizes {
31 | name := fmt.Sprintf("TestReader%d", s)
32 | runNormTests(t, name, readFunc(s))
33 | }
34 | }
35 |
36 | func writeFunc(size int) appendFunc {
37 | return func(f Form, out []byte, s string) []byte {
38 | in := append(out, s...)
39 | result := new(bytes.Buffer)
40 | w := f.Writer(result)
41 | buf := make([]byte, size)
42 | for n := 0; len(in) > 0; in = in[n:] {
43 | n = copy(buf, in)
44 | _, _ = w.Write(buf[:n])
45 | }
46 | w.Close()
47 | return result.Bytes()
48 | }
49 | }
50 |
51 | func TestWriter(t *testing.T) {
52 | for _, s := range bufSizes {
53 | name := fmt.Sprintf("TestWriter%d", s)
54 | runNormTests(t, name, writeFunc(s))
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/norm/transform.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm
6 |
7 | import (
8 | "unicode/utf8"
9 |
10 | "golang.org/x/text/transform"
11 | )
12 |
13 | // Reset implements the Reset method of the transform.Transformer interface.
14 | func (Form) Reset() {}
15 |
16 | // Transform implements the Transform method of the transform.Transformer
17 | // interface. It may need to write segments of up to MaxSegmentSize at once.
18 | // Users should either catch ErrShortDst and allow dst to grow or have dst be at
19 | // least of size MaxTransformChunkSize to be guaranteed of progress.
20 | func (f Form) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
21 | n := 0
22 | // Cap the maximum number of src bytes to check.
23 | b := src
24 | eof := atEOF
25 | if ns := len(dst); ns < len(b) {
26 | err = transform.ErrShortDst
27 | eof = false
28 | b = b[:ns]
29 | }
30 | i, ok := formTable[f].quickSpan(inputBytes(b), n, len(b), eof)
31 | n += copy(dst[n:], b[n:i])
32 | if !ok {
33 | nDst, nSrc, err = f.transform(dst[n:], src[n:], atEOF)
34 | return nDst + n, nSrc + n, err
35 | }
36 | if n < len(src) && !atEOF {
37 | err = transform.ErrShortSrc
38 | }
39 | return n, n, err
40 | }
41 |
42 | func flushTransform(rb *reorderBuffer) bool {
43 | // Write out (must fully fit in dst, or else it is a ErrShortDst).
44 | if len(rb.out) < rb.nrune*utf8.UTFMax {
45 | return false
46 | }
47 | rb.out = rb.out[rb.flushCopy(rb.out):]
48 | return true
49 | }
50 |
51 | var errs = []error{nil, transform.ErrShortDst, transform.ErrShortSrc}
52 |
53 | // transform implements the transform.Transformer interface. It is only called
54 | // when quickSpan does not pass for a given string.
55 | func (f Form) transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
56 | // TODO: get rid of reorderBuffer. See CL 23460044.
57 | rb := reorderBuffer{}
58 | rb.init(f, src)
59 | for {
60 | // Load segment into reorder buffer.
61 | rb.setFlusher(dst[nDst:], flushTransform)
62 | end := decomposeSegment(&rb, nSrc, atEOF)
63 | if end < 0 {
64 | return nDst, nSrc, errs[-end]
65 | }
66 | nDst = len(dst) - len(rb.out)
67 | nSrc = end
68 |
69 | // Next quickSpan.
70 | end = rb.nsrc
71 | eof := atEOF
72 | if n := nSrc + len(dst) - nDst; n < end {
73 | err = transform.ErrShortDst
74 | end = n
75 | eof = false
76 | }
77 | end, ok := rb.f.quickSpan(rb.src, nSrc, end, eof)
78 | n := copy(dst[nDst:], rb.src.bytes[nSrc:end])
79 | nSrc += n
80 | nDst += n
81 | if ok {
82 | if n < rb.nsrc && !atEOF {
83 | err = transform.ErrShortSrc
84 | }
85 | return nDst, nSrc, err
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/norm/trie.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm
6 |
7 | type valueRange struct {
8 | value uint16 // header: value:stride
9 | lo, hi byte // header: lo:n
10 | }
11 |
12 | type sparseBlocks struct {
13 | values []valueRange
14 | offset []uint16
15 | }
16 |
17 | var nfcSparse = sparseBlocks{
18 | values: nfcSparseValues[:],
19 | offset: nfcSparseOffset[:],
20 | }
21 |
22 | var nfkcSparse = sparseBlocks{
23 | values: nfkcSparseValues[:],
24 | offset: nfkcSparseOffset[:],
25 | }
26 |
27 | var (
28 | nfcData = newNfcTrie(0)
29 | nfkcData = newNfkcTrie(0)
30 | )
31 |
32 | // lookupValue determines the type of block n and looks up the value for b.
33 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block
34 | // is a list of ranges with an accompanying value. Given a matching range r,
35 | // the value for b is by r.value + (b - r.lo) * stride.
36 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 {
37 | offset := t.offset[n]
38 | header := t.values[offset]
39 | lo := offset + 1
40 | hi := lo + uint16(header.lo)
41 | for lo < hi {
42 | m := lo + (hi-lo)/2
43 | r := t.values[m]
44 | if r.lo <= b && b <= r.hi {
45 | return r.value + uint16(b-r.lo)*header.value
46 | }
47 | if b < r.lo {
48 | hi = m
49 | } else {
50 | lo = m + 1
51 | }
52 | }
53 | return 0
54 | }
55 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/rangetable/rangetable.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package rangetable provides utilities for creating and inspecting
6 | // unicode.RangeTables.
7 | package rangetable
8 |
9 | import (
10 | "sort"
11 | "unicode"
12 | )
13 |
14 | // New creates a RangeTable from the given runes, which may contain duplicates.
15 | func New(r ...rune) *unicode.RangeTable {
16 | if len(r) == 0 {
17 | return &unicode.RangeTable{}
18 | }
19 |
20 | sort.Sort(byRune(r))
21 |
22 | // Remove duplicates.
23 | k := 1
24 | for i := 1; i < len(r); i++ {
25 | if r[k-1] != r[i] {
26 | r[k] = r[i]
27 | k++
28 | }
29 | }
30 |
31 | var rt unicode.RangeTable
32 | for _, r := range r[:k] {
33 | if r <= 0xFFFF {
34 | rt.R16 = append(rt.R16, unicode.Range16{Lo: uint16(r), Hi: uint16(r), Stride: 1})
35 | } else {
36 | rt.R32 = append(rt.R32, unicode.Range32{Lo: uint32(r), Hi: uint32(r), Stride: 1})
37 | }
38 | }
39 |
40 | // Optimize RangeTable.
41 | return Merge(&rt)
42 | }
43 |
44 | type byRune []rune
45 |
46 | func (r byRune) Len() int { return len(r) }
47 | func (r byRune) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
48 | func (r byRune) Less(i, j int) bool { return r[i] < r[j] }
49 |
50 | // Visit visits all runes in the given RangeTable in order, calling fn for each.
51 | func Visit(rt *unicode.RangeTable, fn func(rune)) {
52 | for _, r16 := range rt.R16 {
53 | for r := rune(r16.Lo); r <= rune(r16.Hi); r += rune(r16.Stride) {
54 | fn(r)
55 | }
56 | }
57 | for _, r32 := range rt.R32 {
58 | for r := rune(r32.Lo); r <= rune(r32.Hi); r += rune(r32.Stride) {
59 | fn(r)
60 | }
61 | }
62 | }
63 |
64 | // Assigned returns a RangeTable with all assigned code points for a given
65 | // Unicode version. This includes graphic, format, control, and private-use
66 | // characters. It returns nil if the data for the given version is not
67 | // available.
68 | func Assigned(version string) *unicode.RangeTable {
69 | return assigned[version]
70 | }
71 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/unicode/rangetable/rangetable_test.go:
--------------------------------------------------------------------------------
1 | package rangetable
2 |
3 | import (
4 | "reflect"
5 | "testing"
6 | "unicode"
7 | )
8 |
9 | var (
10 | empty = &unicode.RangeTable{}
11 | many = &unicode.RangeTable{
12 | R16: []unicode.Range16{{0, 0xffff, 5}},
13 | R32: []unicode.Range32{{0x10004, 0x10009, 5}},
14 | LatinOffset: 0,
15 | }
16 | )
17 |
18 | func TestVisit(t *testing.T) {
19 | Visit(empty, func(got rune) {
20 | t.Error("call from empty RangeTable")
21 | })
22 |
23 | var want rune
24 | Visit(many, func(got rune) {
25 | if got != want {
26 | t.Errorf("got %U; want %U", got, want)
27 | }
28 | want += 5
29 | })
30 | if want -= 5; want != 0x10009 {
31 | t.Errorf("last run was %U; want U+10009", want)
32 | }
33 | }
34 |
35 | func TestNew(t *testing.T) {
36 | for i, rt := range []*unicode.RangeTable{
37 | empty,
38 | unicode.Co,
39 | unicode.Letter,
40 | unicode.ASCII_Hex_Digit,
41 | many,
42 | maxRuneTable,
43 | } {
44 | var got, want []rune
45 | Visit(rt, func(r rune) {
46 | want = append(want, r)
47 | })
48 | Visit(New(want...), func(r rune) {
49 | got = append(got, r)
50 | })
51 | if !reflect.DeepEqual(got, want) {
52 | t.Errorf("%d:\ngot %v;\nwant %v", i, got, want)
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/width/common_test.go:
--------------------------------------------------------------------------------
1 | // This file was generated by go generate; DO NOT EDIT
2 |
3 | package width
4 |
5 | // This code is shared between the main code generator and the test code.
6 |
7 | import (
8 | "flag"
9 | "log"
10 | "strconv"
11 | "strings"
12 |
13 | "golang.org/x/text/internal/gen"
14 | "golang.org/x/text/internal/ucd"
15 | )
16 |
17 | var (
18 | outputFile = flag.String("out", "tables.go", "output file")
19 | )
20 |
21 | var typeMap = map[string]elem{
22 | "A": tagAmbiguous,
23 | "N": tagNeutral,
24 | "Na": tagNarrow,
25 | "W": tagWide,
26 | "F": tagFullwidth,
27 | "H": tagHalfwidth,
28 | }
29 |
30 | // getWidthData calls f for every entry for which it is defined.
31 | //
32 | // f may be called multiple times for the same rune. The last call to f is the
33 | // correct value. f is not called for all runes. The default tag type is
34 | // Neutral.
35 | func getWidthData(f func(r rune, tag elem, alt rune)) {
36 | // Set the default values for Unified Ideographs. In line with Annex 11,
37 | // we encode full ranges instead of the defined runes in Unified_Ideograph.
38 | for _, b := range []struct{ lo, hi rune }{
39 | {0x4E00, 0x9FFF}, // the CJK Unified Ideographs block,
40 | {0x3400, 0x4DBF}, // the CJK Unified Ideographs Externsion A block,
41 | {0xF900, 0xFAFF}, // the CJK Compatibility Ideographs block,
42 | {0x20000, 0x2FFFF}, // the Supplementary Ideographic Plane,
43 | {0x30000, 0x3FFFF}, // the Tertiary Ideographic Plane,
44 | } {
45 | for r := b.lo; r <= b.hi; r++ {
46 | f(r, tagWide, 0)
47 | }
48 | }
49 |
50 | inverse := map[rune]rune{}
51 | maps := map[string]bool{
52 | "": true,
53 | "": true,
54 | }
55 |
56 | // We cannot reuse package norm's decomposition, as we need an unexpanded
57 | // decomposition. We make use of the opportunity to verify that the
58 | // decomposition type is as expected.
59 | ucd.Parse(gen.OpenUCDFile("UnicodeData.txt"), func(p *ucd.Parser) {
60 | r := p.Rune(0)
61 | s := strings.SplitN(p.String(ucd.DecompMapping), " ", 2)
62 | if !maps[s[0]] {
63 | return
64 | }
65 | x, err := strconv.ParseUint(s[1], 16, 32)
66 | if err != nil {
67 | log.Fatalf("Error parsing rune %q", s[1])
68 | }
69 | if inverse[r] != 0 || inverse[rune(x)] != 0 {
70 | log.Fatalf("Circular dependency in mapping between %U and %U", r, x)
71 | }
72 | inverse[r] = rune(x)
73 | inverse[rune(x)] = r
74 | })
75 |
76 | // ;
77 | ucd.Parse(gen.OpenUCDFile("EastAsianWidth.txt"), func(p *ucd.Parser) {
78 | tag, ok := typeMap[p.String(1)]
79 | if !ok {
80 | log.Fatalf("Unknown width type %q", p.String(1))
81 | }
82 | r := p.Rune(0)
83 | alt, ok := inverse[r]
84 | if tag == tagFullwidth || tag == tagHalfwidth && r != wonSign {
85 | tag |= tagNeedsFold
86 | if !ok {
87 | log.Fatalf("Narrow or wide rune %U has no decomposition", r)
88 | }
89 | }
90 | f(r, tag, alt)
91 | })
92 | }
93 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/width/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package width_test
6 |
7 | import (
8 | "fmt"
9 |
10 | "golang.org/x/text/width"
11 | )
12 |
13 | func ExampleTransformer_fold() {
14 | s := "abヲ₩○¥A"
15 | f := width.Fold.String(s)
16 | fmt.Printf("%U: %s\n", []rune(s), s)
17 | fmt.Printf("%U: %s\n", []rune(f), f)
18 |
19 | // Output:
20 | // [U+0061 U+0062 U+FF66 U+FFE6 U+FFEE U+FFE5 U+FF21]: abヲ₩○¥A
21 | // [U+0061 U+0062 U+30F2 U+20A9 U+25CB U+00A5 U+0041]: abヲ₩○¥A
22 | }
23 |
24 | func ExampleTransformer_widen() {
25 | s := "ab¥ヲ₩○"
26 | w := width.Widen.String(s)
27 | fmt.Printf("%U: %s\n", []rune(s), s)
28 | fmt.Printf("%U: %s\n", []rune(w), w)
29 |
30 | // Output:
31 | // [U+0061 U+0062 U+00A5 U+FF66 U+20A9 U+FFEE]: ab¥ヲ₩○
32 | // [U+FF41 U+FF42 U+FFE5 U+30F2 U+FFE6 U+25CB]: ab¥ヲ₩○
33 | }
34 |
35 | func ExampleTransformer_narrow() {
36 | s := "abヲ₩○¥A"
37 | n := width.Narrow.String(s)
38 | fmt.Printf("%U: %s\n", []rune(s), s)
39 | fmt.Printf("%U: %s\n", []rune(n), n)
40 |
41 | // Ambiguous characters with a halfwidth equivalent get mapped as well.
42 | s = "←"
43 | n = width.Narrow.String(s)
44 | fmt.Printf("%U: %s\n", []rune(s), s)
45 | fmt.Printf("%U: %s\n", []rune(n), n)
46 |
47 | // Output:
48 | // [U+0061 U+0062 U+30F2 U+FFE6 U+25CB U+FFE5 U+FF21]: abヲ₩○¥A
49 | // [U+0061 U+0062 U+FF66 U+20A9 U+FFEE U+00A5 U+0041]: abヲ₩○¥A
50 | // [U+2190]: ←
51 | // [U+FFE9]: ←
52 | }
53 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/width/gen_common.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build ignore
6 |
7 | package main
8 |
9 | // This code is shared between the main code generator and the test code.
10 |
11 | import (
12 | "flag"
13 | "log"
14 | "strconv"
15 | "strings"
16 |
17 | "golang.org/x/text/internal/gen"
18 | "golang.org/x/text/internal/ucd"
19 | )
20 |
21 | var (
22 | outputFile = flag.String("out", "tables.go", "output file")
23 | )
24 |
25 | var typeMap = map[string]elem{
26 | "A": tagAmbiguous,
27 | "N": tagNeutral,
28 | "Na": tagNarrow,
29 | "W": tagWide,
30 | "F": tagFullwidth,
31 | "H": tagHalfwidth,
32 | }
33 |
34 | // getWidthData calls f for every entry for which it is defined.
35 | //
36 | // f may be called multiple times for the same rune. The last call to f is the
37 | // correct value. f is not called for all runes. The default tag type is
38 | // Neutral.
39 | func getWidthData(f func(r rune, tag elem, alt rune)) {
40 | // Set the default values for Unified Ideographs. In line with Annex 11,
41 | // we encode full ranges instead of the defined runes in Unified_Ideograph.
42 | for _, b := range []struct{ lo, hi rune }{
43 | {0x4E00, 0x9FFF}, // the CJK Unified Ideographs block,
44 | {0x3400, 0x4DBF}, // the CJK Unified Ideographs Externsion A block,
45 | {0xF900, 0xFAFF}, // the CJK Compatibility Ideographs block,
46 | {0x20000, 0x2FFFF}, // the Supplementary Ideographic Plane,
47 | {0x30000, 0x3FFFF}, // the Tertiary Ideographic Plane,
48 | } {
49 | for r := b.lo; r <= b.hi; r++ {
50 | f(r, tagWide, 0)
51 | }
52 | }
53 |
54 | inverse := map[rune]rune{}
55 | maps := map[string]bool{
56 | "": true,
57 | "": true,
58 | }
59 |
60 | // We cannot reuse package norm's decomposition, as we need an unexpanded
61 | // decomposition. We make use of the opportunity to verify that the
62 | // decomposition type is as expected.
63 | ucd.Parse(gen.OpenUCDFile("UnicodeData.txt"), func(p *ucd.Parser) {
64 | r := p.Rune(0)
65 | s := strings.SplitN(p.String(ucd.DecompMapping), " ", 2)
66 | if !maps[s[0]] {
67 | return
68 | }
69 | x, err := strconv.ParseUint(s[1], 16, 32)
70 | if err != nil {
71 | log.Fatalf("Error parsing rune %q", s[1])
72 | }
73 | if inverse[r] != 0 || inverse[rune(x)] != 0 {
74 | log.Fatalf("Circular dependency in mapping between %U and %U", r, x)
75 | }
76 | inverse[r] = rune(x)
77 | inverse[rune(x)] = r
78 | })
79 |
80 | // ;
81 | ucd.Parse(gen.OpenUCDFile("EastAsianWidth.txt"), func(p *ucd.Parser) {
82 | tag, ok := typeMap[p.String(1)]
83 | if !ok {
84 | log.Fatalf("Unknown width type %q", p.String(1))
85 | }
86 | r := p.Rune(0)
87 | alt, ok := inverse[r]
88 | if tag == tagFullwidth || tag == tagHalfwidth && r != wonSign {
89 | tag |= tagNeedsFold
90 | if !ok {
91 | log.Fatalf("Narrow or wide rune %U has no decomposition", r)
92 | }
93 | }
94 | f(r, tag, alt)
95 | })
96 | }
97 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/width/gen_trieval.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build ignore
6 |
7 | package main
8 |
9 | // elem is an entry of the width trie. The high byte is used to encode the type
10 | // of the rune. The low byte is used to store the index to a mapping entry in
11 | // the inverseData array.
12 | type elem uint16
13 |
14 | const (
15 | tagNeutral elem = iota << typeShift
16 | tagAmbiguous
17 | tagWide
18 | tagNarrow
19 | tagFullwidth
20 | tagHalfwidth
21 | )
22 |
23 | const (
24 | numTypeBits = 3
25 | typeShift = 16 - numTypeBits
26 |
27 | // tagNeedsFold is true for all fullwidth and halfwidth runes except for
28 | // the Won sign U+20A9.
29 | tagNeedsFold = 0x1000
30 |
31 | // The Korean Won sign is halfwidth, but SHOULD NOT be mapped to a wide
32 | // variant.
33 | wonSign rune = 0x20A9
34 | )
35 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/width/kind_string.go:
--------------------------------------------------------------------------------
1 | // generated by stringer -type=Kind; DO NOT EDIT
2 |
3 | package width
4 |
5 | import "fmt"
6 |
7 | const _Kind_name = "NeutralEastAsianAmbiguousEastAsianWideEastAsianNarrowEastAsianFullwidthEastAsianHalfwidth"
8 |
9 | var _Kind_index = [...]uint8{0, 7, 25, 38, 53, 71, 89}
10 |
11 | func (i Kind) String() string {
12 | if i < 0 || i+1 >= Kind(len(_Kind_index)) {
13 | return fmt.Sprintf("Kind(%d)", i)
14 | }
15 | return _Kind_name[_Kind_index[i]:_Kind_index[i+1]]
16 | }
17 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/width/tables_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package width
6 |
7 | import (
8 | "flag"
9 | "testing"
10 |
11 | "golang.org/x/text/internal/gen"
12 | )
13 |
14 | var long = flag.Bool("long", false,
15 | "run time-consuming tests, such as tests that fetch data online")
16 |
17 | const (
18 | loSurrogate = 0xD800
19 | hiSurrogate = 0xDFFF
20 | )
21 |
22 | func TestTables(t *testing.T) {
23 | if !gen.IsLocal() && !*long {
24 | t.Skip("skipping test to prevent downloading; to run use -long or use -local to specify a local source")
25 | }
26 | runes := map[rune]Kind{}
27 | getWidthData(func(r rune, tag elem, _ rune) {
28 | runes[r] = tag.kind()
29 | })
30 | for r := rune(0); r < 0x10FFFF; r++ {
31 | if loSurrogate <= r && r <= hiSurrogate {
32 | continue
33 | }
34 | p := LookupRune(r)
35 | if got, want := p.Kind(), runes[r]; got != want {
36 | t.Errorf("Kind of %U was %s; want %s.", r, got, want)
37 | }
38 | want, mapped := foldRune(r)
39 | if got := p.Folded(); (got == 0) == mapped || got != 0 && got != want {
40 | t.Errorf("Folded(%U) = %U; want %U", r, got, want)
41 | }
42 | want, mapped = widenRune(r)
43 | if got := p.Wide(); (got == 0) == mapped || got != 0 && got != want {
44 | t.Errorf("Wide(%U) = %U; want %U", r, got, want)
45 | }
46 | want, mapped = narrowRune(r)
47 | if got := p.Narrow(); (got == 0) == mapped || got != 0 && got != want {
48 | t.Errorf("Narrow(%U) = %U; want %U", r, got, want)
49 | }
50 | }
51 | }
52 |
53 | // TestAmbiguous verifies that that ambiguous runes with a mapping always map to
54 | // a halfwidth rune.
55 | func TestAmbiguous(t *testing.T) {
56 | for r, m := range mapRunes {
57 | if m.e != tagAmbiguous {
58 | continue
59 | }
60 | if k := mapRunes[m.r].e.kind(); k != EastAsianHalfwidth {
61 | t.Errorf("Rune %U is ambiguous and maps to a rune of type %v", r, k)
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/vendor/github.com/bigwhite/gocmpp/vendor/golang.org/x/text/width/trieval.go:
--------------------------------------------------------------------------------
1 | // This file was generated by go generate; DO NOT EDIT
2 |
3 | package width
4 |
5 | // elem is an entry of the width trie. The high byte is used to encode the type
6 | // of the rune. The low byte is used to store the index to a mapping entry in
7 | // the inverseData array.
8 | type elem uint16
9 |
10 | const (
11 | tagNeutral elem = iota << typeShift
12 | tagAmbiguous
13 | tagWide
14 | tagNarrow
15 | tagFullwidth
16 | tagHalfwidth
17 | )
18 |
19 | const (
20 | numTypeBits = 3
21 | typeShift = 16 - numTypeBits
22 |
23 | // tagNeedsFold is true for all fullwidth and halfwidth runes except for
24 | // the Won sign U+20A9.
25 | tagNeedsFold = 0x1000
26 |
27 | // The Korean Won sign is halfwidth, but SHOULD NOT be mapped to a wide
28 | // variant.
29 | wonSign rune = 0x20A9
30 | )
31 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 | sudo: false
3 | services:
4 | - redis-server
5 |
6 | go:
7 | - 1.4
8 | - 1.5
9 | - 1.6
10 | - tip
11 |
12 | script:
13 | - go get -t -v ./...
14 | - diff -u <(echo -n) <(gofmt -d .)
15 | - go vet $(go list ./... | grep -v /vendor/)
16 | - go test -v -race ./...
17 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/README.markdown:
--------------------------------------------------------------------------------
1 | Redigo
2 | ======
3 |
4 | [](https://travis-ci.org/garyburd/redigo)
5 | [](https://godoc.org/github.com/garyburd/redigo/redis)
6 |
7 | Redigo is a [Go](http://golang.org/) client for the [Redis](http://redis.io/) database.
8 |
9 | Features
10 | -------
11 |
12 | * A [Print-like](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Executing_Commands) API with support for all Redis commands.
13 | * [Pipelining](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Pipelining), including pipelined transactions.
14 | * [Publish/Subscribe](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Publish_and_Subscribe).
15 | * [Connection pooling](http://godoc.org/github.com/garyburd/redigo/redis#Pool).
16 | * [Script helper type](http://godoc.org/github.com/garyburd/redigo/redis#Script) with optimistic use of EVALSHA.
17 | * [Helper functions](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Reply_Helpers) for working with command replies.
18 |
19 | Documentation
20 | -------------
21 |
22 | - [API Reference](http://godoc.org/github.com/garyburd/redigo/redis)
23 | - [FAQ](https://github.com/garyburd/redigo/wiki/FAQ)
24 |
25 | Installation
26 | ------------
27 |
28 | Install Redigo using the "go get" command:
29 |
30 | go get github.com/garyburd/redigo/redis
31 |
32 | The Go distribution is Redigo's only dependency.
33 |
34 | Related Projects
35 | ----------------
36 |
37 | - [rafaeljusto/redigomock](https://godoc.org/github.com/rafaeljusto/redigomock) - A mock library for Redigo.
38 | - [chasex/redis-go-cluster](https://github.com/chasex/redis-go-cluster) - A Redis cluster client implementation.
39 | - [FZambia/go-sentinel](https://github.com/FZambia/go-sentinel) - Redis Sentinel support for Redigo
40 | - [PuerkitoBio/redisc](https://github.com/PuerkitoBio/redisc) - Redis Cluster client built on top of Redigo
41 |
42 | Contributing
43 | ------------
44 |
45 | Send email to Gary Burd (address in GitHub profile) before doing any work on Redigo.
46 |
47 | License
48 | -------
49 |
50 | Redigo is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html).
51 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/internal/commandinfo.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Gary Burd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | // not use this file except in compliance with the License. You may obtain
5 | // a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | // License for the specific language governing permissions and limitations
13 | // under the License.
14 |
15 | package internal // import "github.com/garyburd/redigo/internal"
16 |
17 | import (
18 | "strings"
19 | )
20 |
21 | const (
22 | WatchState = 1 << iota
23 | MultiState
24 | SubscribeState
25 | MonitorState
26 | )
27 |
28 | type CommandInfo struct {
29 | Set, Clear int
30 | }
31 |
32 | var commandInfos = map[string]CommandInfo{
33 | "WATCH": {Set: WatchState},
34 | "UNWATCH": {Clear: WatchState},
35 | "MULTI": {Set: MultiState},
36 | "EXEC": {Clear: WatchState | MultiState},
37 | "DISCARD": {Clear: WatchState | MultiState},
38 | "PSUBSCRIBE": {Set: SubscribeState},
39 | "SUBSCRIBE": {Set: SubscribeState},
40 | "MONITOR": {Set: MonitorState},
41 | }
42 |
43 | func init() {
44 | for n, ci := range commandInfos {
45 | commandInfos[strings.ToLower(n)] = ci
46 | }
47 | }
48 |
49 | func LookupCommandInfo(commandName string) CommandInfo {
50 | if ci, ok := commandInfos[commandName]; ok {
51 | return ci
52 | }
53 | return commandInfos[strings.ToUpper(commandName)]
54 | }
55 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/internal/commandinfo_test.go:
--------------------------------------------------------------------------------
1 | package internal
2 |
3 | import "testing"
4 |
5 | func TestLookupCommandInfo(t *testing.T) {
6 | for _, n := range []string{"watch", "WATCH", "wAtch"} {
7 | if LookupCommandInfo(n) == (CommandInfo{}) {
8 | t.Errorf("LookupCommandInfo(%q) = CommandInfo{}, expected non-zero value", n)
9 | }
10 | }
11 | }
12 |
13 | func benchmarkLookupCommandInfo(b *testing.B, names ...string) {
14 | for i := 0; i < b.N; i++ {
15 | for _, c := range names {
16 | LookupCommandInfo(c)
17 | }
18 | }
19 | }
20 |
21 | func BenchmarkLookupCommandInfoCorrectCase(b *testing.B) {
22 | benchmarkLookupCommandInfo(b, "watch", "WATCH", "monitor", "MONITOR")
23 | }
24 |
25 | func BenchmarkLookupCommandInfoMixedCase(b *testing.B) {
26 | benchmarkLookupCommandInfo(b, "wAtch", "WeTCH", "monItor", "MONiTOR")
27 | }
28 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/internal/redistest/testdb.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Gary Burd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | // not use this file except in compliance with the License. You may obtain
5 | // a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | // License for the specific language governing permissions and limitations
13 | // under the License.
14 |
15 | // Package redistest contains utilities for writing Redigo tests.
16 | package redistest
17 |
18 | import (
19 | "errors"
20 | "time"
21 |
22 | "github.com/garyburd/redigo/redis"
23 | )
24 |
25 | type testConn struct {
26 | redis.Conn
27 | }
28 |
29 | func (t testConn) Close() error {
30 | _, err := t.Conn.Do("SELECT", "9")
31 | if err != nil {
32 | return nil
33 | }
34 | _, err = t.Conn.Do("FLUSHDB")
35 | if err != nil {
36 | return err
37 | }
38 | return t.Conn.Close()
39 | }
40 |
41 | // Dial dials the local Redis server and selects database 9. To prevent
42 | // stomping on real data, DialTestDB fails if database 9 contains data. The
43 | // returned connection flushes database 9 on close.
44 | func Dial() (redis.Conn, error) {
45 | c, err := redis.DialTimeout("tcp", ":6379", 0, 1*time.Second, 1*time.Second)
46 | if err != nil {
47 | return nil, err
48 | }
49 |
50 | _, err = c.Do("SELECT", "9")
51 | if err != nil {
52 | c.Close()
53 | return nil, err
54 | }
55 |
56 | n, err := redis.Int(c.Do("DBSIZE"))
57 | if err != nil {
58 | c.Close()
59 | return nil, err
60 | }
61 |
62 | if n != 0 {
63 | c.Close()
64 | return nil, errors.New("database #9 is not empty, test can not continue")
65 | }
66 |
67 | return testConn{c}, nil
68 | }
69 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/redis/redis.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Gary Burd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | // not use this file except in compliance with the License. You may obtain
5 | // a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | // License for the specific language governing permissions and limitations
13 | // under the License.
14 |
15 | package redis
16 |
17 | // Error represents an error returned in a command reply.
18 | type Error string
19 |
20 | func (err Error) Error() string { return string(err) }
21 |
22 | // Conn represents a connection to a Redis server.
23 | type Conn interface {
24 | // Close closes the connection.
25 | Close() error
26 |
27 | // Err returns a non-nil value if the connection is broken. The returned
28 | // value is either the first non-nil value returned from the underlying
29 | // network connection or a protocol parsing error. Applications should
30 | // close broken connections.
31 | Err() error
32 |
33 | // Do sends a command to the server and returns the received reply.
34 | Do(commandName string, args ...interface{}) (reply interface{}, err error)
35 |
36 | // Send writes the command to the client's output buffer.
37 | Send(commandName string, args ...interface{}) error
38 |
39 | // Flush flushes the output buffer to the Redis server.
40 | Flush() error
41 |
42 | // Receive receives a single reply from the Redis server
43 | Receive() (reply interface{}, err error)
44 | }
45 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/redis/script.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Gary Burd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | // not use this file except in compliance with the License. You may obtain
5 | // a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | // License for the specific language governing permissions and limitations
13 | // under the License.
14 |
15 | package redis
16 |
17 | import (
18 | "crypto/sha1"
19 | "encoding/hex"
20 | "io"
21 | "strings"
22 | )
23 |
24 | // Script encapsulates the source, hash and key count for a Lua script. See
25 | // http://redis.io/commands/eval for information on scripts in Redis.
26 | type Script struct {
27 | keyCount int
28 | src string
29 | hash string
30 | }
31 |
32 | // NewScript returns a new script object. If keyCount is greater than or equal
33 | // to zero, then the count is automatically inserted in the EVAL command
34 | // argument list. If keyCount is less than zero, then the application supplies
35 | // the count as the first value in the keysAndArgs argument to the Do, Send and
36 | // SendHash methods.
37 | func NewScript(keyCount int, src string) *Script {
38 | h := sha1.New()
39 | io.WriteString(h, src)
40 | return &Script{keyCount, src, hex.EncodeToString(h.Sum(nil))}
41 | }
42 |
43 | func (s *Script) args(spec string, keysAndArgs []interface{}) []interface{} {
44 | var args []interface{}
45 | if s.keyCount < 0 {
46 | args = make([]interface{}, 1+len(keysAndArgs))
47 | args[0] = spec
48 | copy(args[1:], keysAndArgs)
49 | } else {
50 | args = make([]interface{}, 2+len(keysAndArgs))
51 | args[0] = spec
52 | args[1] = s.keyCount
53 | copy(args[2:], keysAndArgs)
54 | }
55 | return args
56 | }
57 |
58 | // Do evaluates the script. Under the covers, Do optimistically evaluates the
59 | // script using the EVALSHA command. If the command fails because the script is
60 | // not loaded, then Do evaluates the script using the EVAL command (thus
61 | // causing the script to load).
62 | func (s *Script) Do(c Conn, keysAndArgs ...interface{}) (interface{}, error) {
63 | v, err := c.Do("EVALSHA", s.args(s.hash, keysAndArgs)...)
64 | if e, ok := err.(Error); ok && strings.HasPrefix(string(e), "NOSCRIPT ") {
65 | v, err = c.Do("EVAL", s.args(s.src, keysAndArgs)...)
66 | }
67 | return v, err
68 | }
69 |
70 | // SendHash evaluates the script without waiting for the reply. The script is
71 | // evaluated with the EVALSHA command. The application must ensure that the
72 | // script is loaded by a previous call to Send, Do or Load methods.
73 | func (s *Script) SendHash(c Conn, keysAndArgs ...interface{}) error {
74 | return c.Send("EVALSHA", s.args(s.hash, keysAndArgs)...)
75 | }
76 |
77 | // Send evaluates the script without waiting for the reply.
78 | func (s *Script) Send(c Conn, keysAndArgs ...interface{}) error {
79 | return c.Send("EVAL", s.args(s.src, keysAndArgs)...)
80 | }
81 |
82 | // Load loads the script without evaluating it.
83 | func (s *Script) Load(c Conn) error {
84 | _, err := c.Do("SCRIPT", "LOAD", s.src)
85 | return err
86 | }
87 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/redis/script_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Gary Burd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | // not use this file except in compliance with the License. You may obtain
5 | // a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | // License for the specific language governing permissions and limitations
13 | // under the License.
14 |
15 | package redis_test
16 |
17 | import (
18 | "fmt"
19 | "reflect"
20 | "testing"
21 | "time"
22 |
23 | "github.com/garyburd/redigo/redis"
24 | )
25 |
26 | var (
27 | // These variables are declared at package level to remove distracting
28 | // details from the examples.
29 | c redis.Conn
30 | reply interface{}
31 | err error
32 | )
33 |
34 | func ExampleScript() {
35 | // Initialize a package-level variable with a script.
36 | var getScript = redis.NewScript(1, `return redis.call('get', KEYS[1])`)
37 |
38 | // In a function, use the script Do method to evaluate the script. The Do
39 | // method optimistically uses the EVALSHA command. If the script is not
40 | // loaded, then the Do method falls back to the EVAL command.
41 | reply, err = getScript.Do(c, "foo")
42 | }
43 |
44 | func TestScript(t *testing.T) {
45 | c, err := redis.DialDefaultServer()
46 | if err != nil {
47 | t.Fatalf("error connection to database, %v", err)
48 | }
49 | defer c.Close()
50 |
51 | // To test fall back in Do, we make script unique by adding comment with current time.
52 | script := fmt.Sprintf("--%d\nreturn {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", time.Now().UnixNano())
53 | s := redis.NewScript(2, script)
54 | reply := []interface{}{[]byte("key1"), []byte("key2"), []byte("arg1"), []byte("arg2")}
55 |
56 | v, err := s.Do(c, "key1", "key2", "arg1", "arg2")
57 | if err != nil {
58 | t.Errorf("s.Do(c, ...) returned %v", err)
59 | }
60 |
61 | if !reflect.DeepEqual(v, reply) {
62 | t.Errorf("s.Do(c, ..); = %v, want %v", v, reply)
63 | }
64 |
65 | err = s.Load(c)
66 | if err != nil {
67 | t.Errorf("s.Load(c) returned %v", err)
68 | }
69 |
70 | err = s.SendHash(c, "key1", "key2", "arg1", "arg2")
71 | if err != nil {
72 | t.Errorf("s.SendHash(c, ...) returned %v", err)
73 | }
74 |
75 | err = c.Flush()
76 | if err != nil {
77 | t.Errorf("c.Flush() returned %v", err)
78 | }
79 |
80 | v, err = c.Receive()
81 | if !reflect.DeepEqual(v, reply) {
82 | t.Errorf("s.SendHash(c, ..); c.Receive() = %v, want %v", v, reply)
83 | }
84 |
85 | err = s.Send(c, "key1", "key2", "arg1", "arg2")
86 | if err != nil {
87 | t.Errorf("s.Send(c, ...) returned %v", err)
88 | }
89 |
90 | err = c.Flush()
91 | if err != nil {
92 | t.Errorf("c.Flush() returned %v", err)
93 | }
94 |
95 | v, err = c.Receive()
96 | if !reflect.DeepEqual(v, reply) {
97 | t.Errorf("s.Send(c, ..); c.Receive() = %v, want %v", v, reply)
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/redis/zpop_example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Gary Burd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | // not use this file except in compliance with the License. You may obtain
5 | // a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | // License for the specific language governing permissions and limitations
13 | // under the License.
14 |
15 | package redis_test
16 |
17 | import (
18 | "fmt"
19 | "github.com/garyburd/redigo/redis"
20 | )
21 |
22 | // zpop pops a value from the ZSET key using WATCH/MULTI/EXEC commands.
23 | func zpop(c redis.Conn, key string) (result string, err error) {
24 |
25 | defer func() {
26 | // Return connection to normal state on error.
27 | if err != nil {
28 | c.Do("DISCARD")
29 | }
30 | }()
31 |
32 | // Loop until transaction is successful.
33 | for {
34 | if _, err := c.Do("WATCH", key); err != nil {
35 | return "", err
36 | }
37 |
38 | members, err := redis.Strings(c.Do("ZRANGE", key, 0, 0))
39 | if err != nil {
40 | return "", err
41 | }
42 | if len(members) != 1 {
43 | return "", redis.ErrNil
44 | }
45 |
46 | c.Send("MULTI")
47 | c.Send("ZREM", key, members[0])
48 | queued, err := c.Do("EXEC")
49 | if err != nil {
50 | return "", err
51 | }
52 |
53 | if queued != nil {
54 | result = members[0]
55 | break
56 | }
57 | }
58 |
59 | return result, nil
60 | }
61 |
62 | // zpopScript pops a value from a ZSET.
63 | var zpopScript = redis.NewScript(1, `
64 | local r = redis.call('ZRANGE', KEYS[1], 0, 0)
65 | if r ~= nil then
66 | r = r[1]
67 | redis.call('ZREM', KEYS[1], r)
68 | end
69 | return r
70 | `)
71 |
72 | // This example implements ZPOP as described at
73 | // http://redis.io/topics/transactions using WATCH/MULTI/EXEC and scripting.
74 | func Example_zpop() {
75 | c, err := dial()
76 | if err != nil {
77 | fmt.Println(err)
78 | return
79 | }
80 | defer c.Close()
81 |
82 | // Add test data using a pipeline.
83 |
84 | for i, member := range []string{"red", "blue", "green"} {
85 | c.Send("ZADD", "zset", i, member)
86 | }
87 | if _, err := c.Do(""); err != nil {
88 | fmt.Println(err)
89 | return
90 | }
91 |
92 | // Pop using WATCH/MULTI/EXEC
93 |
94 | v, err := zpop(c, "zset")
95 | if err != nil {
96 | fmt.Println(err)
97 | return
98 | }
99 | fmt.Println(v)
100 |
101 | // Pop using a script.
102 |
103 | v, err = redis.String(zpopScript.Do(c, "zset"))
104 | if err != nil {
105 | fmt.Println(err)
106 | return
107 | }
108 | fmt.Println(v)
109 |
110 | // Output:
111 | // red
112 | // blue
113 | }
114 |
--------------------------------------------------------------------------------
/vendor/github.com/garyburd/redigo/redisx/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Gary Burd
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may
4 | // not use this file except in compliance with the License. You may obtain
5 | // a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | // License for the specific language governing permissions and limitations
13 | // under the License.
14 |
15 | // Package redisx contains experimental features for Redigo. Features in this
16 | // package may be modified or deleted at any time.
17 | package redisx // import "github.com/garyburd/redigo/redisx"
18 |
--------------------------------------------------------------------------------