Compare commits
58 Commits
v0.8
...
154a9b2207
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
154a9b2207 | ||
|
|
18ac803350 | ||
|
|
df1bbcb33d | ||
|
|
d1e0550622 | ||
|
|
d231cc2aa7 | ||
|
|
d0199ca559 | ||
|
|
edb1b48e1f | ||
|
|
33e3a92dab | ||
|
|
a5e4cd808a | ||
|
|
8da2cfea0c | ||
|
|
84135eecef | ||
|
|
ae02290975 | ||
|
|
18ec246ebc | ||
|
|
737a621a2b | ||
|
|
921949fd35 | ||
|
|
1b10eac271 | ||
|
|
72bf715cfe | ||
|
|
b25befca9b | ||
|
|
f884f743c9 | ||
|
|
262aba9633 | ||
|
|
abda47fc0d | ||
|
|
d1612237f8 | ||
|
|
2da7633c3b | ||
|
|
a0cdbe47c0 | ||
|
|
134fd7a498 | ||
|
|
15761c5a20 | ||
|
|
bc11bcf41a | ||
|
|
e4a6a9c22f | ||
|
|
ba322e596e | ||
|
|
1af3618bd8 | ||
|
|
281f915f17 | ||
|
|
1348c66fab | ||
|
|
ec4a28e0eb | ||
|
|
143101d62f | ||
|
|
202aa1a39f | ||
|
|
449d759156 | ||
|
|
dfea3defb1 | ||
|
|
0f396eb3d4 | ||
|
|
6ef0d1ded9 | ||
|
|
c2ee5c2bc1 | ||
|
|
3318ef3df0 | ||
|
|
274a14d9d1 | ||
|
|
be4a879e50 | ||
|
|
8c7f52eb70 | ||
|
|
1aadfc65b6 | ||
|
|
91a611b170 | ||
|
|
b3e49e2848 | ||
|
|
8a5a5d0cf4 | ||
|
|
3281104f2e | ||
|
|
94c2cd7c01 | ||
|
|
62913d1424 | ||
|
|
cfea265312 | ||
|
|
46fe312222 | ||
|
|
22809d9167 | ||
|
|
6d3b5f837f | ||
|
|
63260c9811 | ||
|
|
b0deed239e | ||
|
|
71778e30c1 |
16
Dockerfile
Executable file
16
Dockerfile
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
FROM golang:1.13-alpine as certs
|
||||||
|
RUN apk update && apk add --no-cache ca-certificates
|
||||||
|
|
||||||
|
FROM busybox:glibc
|
||||||
|
RUN mkdir -p /var/log
|
||||||
|
WORKDIR /main
|
||||||
|
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ENV GOPATH=""
|
||||||
|
ENV MNT="/mnt/"
|
||||||
|
ENTRYPOINT ["/main/exec-rssmon3"]
|
||||||
|
CMD []
|
||||||
|
|
||||||
@@ -15,9 +15,13 @@ func New() error {
|
|||||||
as.Append(args.STRING, "port", "port to listen on", "33419")
|
as.Append(args.STRING, "port", "port to listen on", "33419")
|
||||||
as.Append(args.STRING, "db", "database type code", storage.MAP.String())
|
as.Append(args.STRING, "db", "database type code", storage.MAP.String())
|
||||||
as.Append(args.STRING, "ns", "namespace", storage.DefaultNamespace)
|
as.Append(args.STRING, "ns", "namespace", storage.DefaultNamespace)
|
||||||
|
as.Append(args.STRING, "proxy", "http proxy", "")
|
||||||
if err := as.Parse(); err != nil {
|
if err := as.Parse(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if proxy := as.Get("proxy").GetString(); len(proxy) > 0 {
|
||||||
|
os.Setenv("http_proxy", proxy)
|
||||||
|
}
|
||||||
ctx, can := context.WithCancel(context.Background())
|
ctx, can := context.WithCancel(context.Background())
|
||||||
config = Config{
|
config = Config{
|
||||||
db: as.Get("db").GetString(),
|
db: as.Get("db").GetString(),
|
||||||
|
|||||||
@@ -180,8 +180,16 @@ func handle(vpntor, outdir, content string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func findMagnets(s string) []string {
|
func findMagnets(s string) []string {
|
||||||
magnetRegexp := regexp.MustCompile(`magnet:.xt[^ $"]*`)
|
patterns := []string{
|
||||||
return magnetRegexp.FindAllString(s, -1)
|
`magnet:.xt[^ $"]*`,
|
||||||
|
`https:..[^ "]*\.torrent`,
|
||||||
|
}
|
||||||
|
matches := []string{}
|
||||||
|
for _, pattern := range patterns {
|
||||||
|
magnetRegexp := regexp.MustCompile(pattern)
|
||||||
|
matches = append(matches, magnetRegexp.FindAllString(s, -1)...)
|
||||||
|
}
|
||||||
|
return matches
|
||||||
}
|
}
|
||||||
|
|
||||||
func submit(vpntor, outdir, magnet string) (*http.Response, error) {
|
func submit(vpntor, outdir, magnet string) (*http.Response, error) {
|
||||||
|
|||||||
@@ -239,6 +239,10 @@ func TestFindMagnets(t *testing.T) {
|
|||||||
s: `here is some magnet:-xt1 and magnet:-xt2 another one <a href="magnet:-xt3">link</a>`,
|
s: `here is some magnet:-xt1 and magnet:-xt2 another one <a href="magnet:-xt3">link</a>`,
|
||||||
l: 3,
|
l: 3,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
s: `here is a link https://my.domain/a.b/c.torrent, and another <a href="https://my.domain/a/b/c.torrent"></a>`,
|
||||||
|
l: 2,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
|
|||||||
42
main.go
42
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"local/lastn/lastn"
|
||||||
"local/rssmon3/config"
|
"local/rssmon3/config"
|
||||||
"local/rssmon3/handlers"
|
"local/rssmon3/handlers"
|
||||||
"local/rssmon3/monitor"
|
"local/rssmon3/monitor"
|
||||||
@@ -8,6 +9,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -37,6 +39,8 @@ func main() {
|
|||||||
h := handlers.New(m.Outgoing)
|
h := handlers.New(m.Outgoing)
|
||||||
go InterruptAfter(h.Run, sigc)
|
go InterruptAfter(h.Run, sigc)
|
||||||
|
|
||||||
|
go EnqueueBackups()
|
||||||
|
|
||||||
signal.Notify(sigc,
|
signal.Notify(sigc,
|
||||||
syscall.SIGHUP,
|
syscall.SIGHUP,
|
||||||
syscall.SIGINT,
|
syscall.SIGINT,
|
||||||
@@ -54,3 +58,41 @@ func InterruptAfter(foo func() error, c chan os.Signal) {
|
|||||||
}
|
}
|
||||||
c <- syscall.SIGINT
|
c <- syscall.SIGINT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EnqueueBackups() {
|
||||||
|
realpath, err := filepath.Abs(config.Values().Addr)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("dir", config.Values().Addr, "not found, so no backups")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf := lastn.Config{
|
||||||
|
N: 3,
|
||||||
|
Root: realpath,
|
||||||
|
Ns: "backups",
|
||||||
|
Store: "files",
|
||||||
|
StoreAddr: realpath + "-backups",
|
||||||
|
}
|
||||||
|
log.Printf("backups conf: %+v", conf)
|
||||||
|
lastn, err := lastn.New(conf)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("backups disabled:", realpath, ":", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ticker := time.NewTicker(time.Hour * 24)
|
||||||
|
log.Println("backup initial:", err)
|
||||||
|
if err := lastn.Push(); err != nil {
|
||||||
|
log.Println("backup failed:", err)
|
||||||
|
}
|
||||||
|
if err := lastn.Clean(); err != nil {
|
||||||
|
log.Println("backup clean failed:", err)
|
||||||
|
}
|
||||||
|
for _ = range ticker.C {
|
||||||
|
log.Println("backing up...")
|
||||||
|
if err := lastn.Push(); err != nil {
|
||||||
|
log.Println("backup push failed:", err)
|
||||||
|
}
|
||||||
|
if err := lastn.Clean(); err != nil {
|
||||||
|
log.Println("backup clean failed:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
13
rss/feed.go
13
rss/feed.go
@@ -1,6 +1,7 @@
|
|||||||
package rss
|
package rss
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"local/rssmon3/config"
|
"local/rssmon3/config"
|
||||||
"log"
|
"log"
|
||||||
@@ -23,6 +24,7 @@ type Feed struct {
|
|||||||
ContentFilter string
|
ContentFilter string
|
||||||
Tags []string
|
Tags []string
|
||||||
Copyright string
|
Copyright string
|
||||||
|
Headers []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func SubmitFeed(f *Feed) error {
|
func SubmitFeed(f *Feed) error {
|
||||||
@@ -61,7 +63,16 @@ func (f *Feed) Pull() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp, err := http.Get(f.URL)
|
req, err := http.NewRequest(http.MethodGet, f.URL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var headers map[string]string
|
||||||
|
json.Unmarshal(f.Headers, &headers)
|
||||||
|
for k, v := range headers {
|
||||||
|
req.Header.Set(k, v)
|
||||||
|
}
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
12
rss/item.go
12
rss/item.go
@@ -63,7 +63,7 @@ func newItem(i *gofeed.Item, contentFilter, copyright string) (*Item, error) {
|
|||||||
|
|
||||||
item.Content = fmt.Sprintf(`<a href="%s">%s</a><br>%s`, item.Link, item.Title, item.Content)
|
item.Content = fmt.Sprintf(`<a href="%s">%s</a><br>%s`, item.Link, item.Title, item.Content)
|
||||||
|
|
||||||
item.Content = clearBlankLines(item.Content)
|
item.Content = cleanSpecialCharacters(clearBlankLines(item.Content))
|
||||||
|
|
||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,11 @@ func (i *Item) Encode() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) Decode(b []byte) error {
|
func (i *Item) Decode(b []byte) error {
|
||||||
return config.Decode(b, i)
|
if err := config.Decode(b, i); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
i.Content = clearBlankLines(i.Content)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) save(ns1 string, ns ...string) error {
|
func (i *Item) save(ns1 string, ns ...string) error {
|
||||||
@@ -116,6 +120,10 @@ func (is Items) Swap(i, j int) {
|
|||||||
is[j] = k
|
is[j] = k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanSpecialCharacters(s string) string {
|
||||||
|
return strings.ToValidUTF8(s, "?")
|
||||||
|
}
|
||||||
|
|
||||||
func clearBlankLines(s string) string {
|
func clearBlankLines(s string) string {
|
||||||
r := regexp.MustCompile(`<br/>`)
|
r := regexp.MustCompile(`<br/>`)
|
||||||
s = r.ReplaceAllLiteralString(s, "<br>")
|
s = r.ReplaceAllLiteralString(s, "<br>")
|
||||||
|
|||||||
@@ -138,6 +138,29 @@ Out
|
|||||||
</html>`,
|
</html>`,
|
||||||
outLines: 6,
|
outLines: 6,
|
||||||
},
|
},
|
||||||
|
"remove with and without whitespace 2": {
|
||||||
|
in: `Daniel
|
||||||
|
Tillett</a><br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
|
||||||
|
<br/><br/><br/><br/><br/><br/>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
`,
|
||||||
|
outLines: 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, c := range cases {
|
for name, c := range cases {
|
||||||
|
|||||||
@@ -81,17 +81,28 @@ func (s *Server) feed(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var putFeed struct {
|
var putFeed struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Interval string `json:"refresh"`
|
Interval string `json:"refresh"`
|
||||||
TitleFilter string `json:"items"`
|
TitleFilter string `json:"items"`
|
||||||
Copyright string `json:"copyright"`
|
Copyright string `json:"copyright"`
|
||||||
ContentFilter string `json:"content"`
|
ContentFilter string `json:"content"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
|
Headers map[string]string `json:"headers"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Interval string `json:"refresh"`
|
||||||
|
TitleFilter string `json:"items"`
|
||||||
|
Copyright string `json:"copyright"`
|
||||||
|
ContentFilter string `json:"content"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&putFeed); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&putFeed); err != nil {
|
||||||
s.userError(w, r, err)
|
s.userError(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if putFeed.Headers == nil {
|
||||||
|
putFeed.Headers = map[string]string{}
|
||||||
|
}
|
||||||
|
putFeedHeaders, _ := json.Marshal(putFeed.Headers)
|
||||||
interval, err := time.ParseDuration(putFeed.Interval)
|
interval, err := time.ParseDuration(putFeed.Interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.userError(w, r, err)
|
s.userError(w, r, err)
|
||||||
@@ -104,6 +115,7 @@ func (s *Server) feed(w http.ResponseWriter, r *http.Request) {
|
|||||||
ContentFilter: putFeed.ContentFilter,
|
ContentFilter: putFeed.ContentFilter,
|
||||||
Tags: putFeed.Tags,
|
Tags: putFeed.Tags,
|
||||||
Copyright: putFeed.Copyright,
|
Copyright: putFeed.Copyright,
|
||||||
|
Headers: putFeedHeaders,
|
||||||
}
|
}
|
||||||
if err := rss.SubmitFeed(f); err != nil {
|
if err := rss.SubmitFeed(f); err != nil {
|
||||||
s.error(w, r, err)
|
s.error(w, r, err)
|
||||||
|
|||||||
99
testdata/add
vendored
Executable file
99
testdata/add
vendored
Executable file
@@ -0,0 +1,99 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
remote="${remote:-192.168.0.86}"
|
||||||
|
|
||||||
|
feeds='
|
||||||
|
https://mangadex.org/rss/follows/ryZGFkVgv9DAPqf45EsTHuQcxmteKBN6 manga na na "1h"
|
||||||
|
https://siftrss.com/f/WXPo6AKQLX manga na na "1h"
|
||||||
|
http://yaoi-blcd.tumblr.com/tagged/19-days/rss manga "Old.Xian.update.of..19" na "4h"
|
||||||
|
http://www.shanaproject.com/feeds/secure/user/5310/5MUGNU9B3I/ anime na na "24h"
|
||||||
|
http://www.manga.megchan.com/blog/?feed=rss2 manga na na "12h"
|
||||||
|
https://siftrss.com/f/6Q8a0ZK0RmL manga na na "12h"
|
||||||
|
https://dropoutmanga.wordpress.com/feed/ manga "(Hatsukoi|Tomo.chan)" na "6h"
|
||||||
|
http://merakiscans.com/manga-rss/solo-leveling/ manga na na "8h"
|
||||||
|
http://www.mangago.me/r/rsslink/a_man_like_you.xml manga na na "24h"
|
||||||
|
http://www.mangago.me/r/rsslink/unriped_expression.xml manga na na "24h"
|
||||||
|
http://www.mangago.me/r/rsslink/heesu_in_class_2.xml manga na na "24h"
|
||||||
|
http://www.mangago.me/r/rsslink/bj_alex.xml manga na na "24h"
|
||||||
|
https://heroscans.tumblr.com/rss manga "(Saizu)" na "24h"
|
||||||
|
http://feeds.pinboard.in/rss/popular/ news ".*" ".*" "24h"
|
||||||
|
https://www.vox.com/rss/index.xml news "yeahrightnoway" ".*" "24h"
|
||||||
|
https://www.techdirt.com/techdirt_rss.xml news ".*" ".*" "24h"
|
||||||
|
http://hotdiggedydemon.com/ comic ".*" ".*" "24h"
|
||||||
|
https://nyaa.si/?page=rss&u=Nauti anime "(akegurui.*XX)" ".*Anime...English.translated.*" "3h"
|
||||||
|
https://tapas.io/rss/series/72832 manga na na "24h"
|
||||||
|
https://tapas.io/rss/series/88570 manga na na "24h"
|
||||||
|
https://nyaa.si/?page=rss&q=kakegurui&c=0_0&f=0&u=Nauti anime "(akegurui.XX)" ".*Anime...English.translated.*" "3h"
|
||||||
|
https://nyaa.si/?page=rss&q=horriblesubs+mob+psycho+720&c=0_0&f=0 anime ".*" ".*Anime...English.translated.*" "3h"
|
||||||
|
https://www.youtube.com/feeds/videos.xml?channel_id=UC9CuvdOVfMPvKCiwdGKL3cQ youtube","gampegrumps ".*" ".*" "6h"
|
||||||
|
https://www.youtube.com/feeds/videos.xml?channel_id=UCbGO1tCyjMlzqIT-tyrJNqQ youtube","kshaway ".*" ".*" "6h"
|
||||||
|
https://www.youtube.com/feeds/videos.xml?channel_id=UC9YLd0REiXxLqQQH_CpJKZQ youtube","instalok ".*" ".*" "6h"
|
||||||
|
https://www.youtube.com/feeds/videos.xml?channel_id=UCsvn_Po0SmunchJYOWpOxMg youtube","videogamedunkey ".*" ".*" "6h"
|
||||||
|
https://www.youtube.com/feeds/videos.xml?channel_id=UCs-w7E2HZWwXmjt9RTvBB_A youtube","settled ".*" ".*" "6h"
|
||||||
|
https://roosterteeth.com/show/rt-podcast/feed/mp3 podcast ".*" ".*" "6h"
|
||||||
|
http://lizclimo.tumblr.com/rss comic na na "24h"
|
||||||
|
http://feeds.feedburner.com/blogspot/sBff cooking ".*" ".*" "24h"
|
||||||
|
https://jaiminisbox.com/reader/feeds/rss manga "olo.*eveling" ".*" "6h"
|
||||||
|
https://xkcd.com/atom.xml comic na na "24h"
|
||||||
|
https://matrix.org/blog/feed news ".*" ".*" "1h"
|
||||||
|
https://nyaa.si/?page=rss&f=0&c=0_0&q=shingeki+no+kyojin+final+season+720p anime","torrent ".*" ".*" "1h" Anime-ShingekiNoKyojin
|
||||||
|
https://workchronicles.com/feed/ comic na na "4h"
|
||||||
|
https://nyaa.si/?page=rss&f=0&c=0_0&q=re+zero+2nd+part+erai+raws+720 anime","torrent ".*" ".*" "2h" Anime-ReZero
|
||||||
|
https://www.webtoons.com/en/challenge/books-of-adam/rss?title_no=136637 comic na na "12h"
|
||||||
|
https://www.webtoons.com/en/romance/the-makeup-remover/rss?title_no=2186 comic na na "12h"
|
||||||
|
https://www.webtoons.com/en/romance/truebeauty/rss?title_no=1436 comic na na "12h"
|
||||||
|
https://subsplease.org/rss/?r=720 anime","torrent "^jfkaldsjfkldsjafd;sa" "<a.*?href=.magnet:.*?</a>" "2h" Anime
|
||||||
|
https://eztv.ag/ezrss.xml?h=h torrent "^([Rr]ick.[Aa]nd.[Mm]orty)" "<a.*?href=.magnet:.*?</a>" "2h" RickAndMorty
|
||||||
|
https://eztv.ag/ezrss.xml?c=c momma","torrent "^NOT(d.Rush.*720.*WEB|Gold.Rush.*S.*E.*720.*WEB)" "<a.*?href=.magnet:.*?</a>" "2h" GoldRush
|
||||||
|
https://eztv.ag/ezrss.xml?e=e momma","torrent "^(Archer|The.Handmaids.Tale.*720.*WEB|Australian.Ninja.Warrior.*HDTV)" "<a.*?href=.magnet:.*?</a>" "2h"
|
||||||
|
https://eztv.ag/ezrss.xml?b=b momma","torrent "^(Survivor.S.*720p|[Ss]urvivor.*[AaSs][UuAa])" "<a.*?href=.magnet:.*?</a>" "2h" Survivor
|
||||||
|
https://eztv.ag/ezrss.xml?a=a momma","torrent "^abc123(Wheel.[oO]f.Fortune.[S2]|Jeopardy.20|[tT]he.[pP]rice.[iI]s.[rR]ight|[lL]et.*[mM]ake.[aA].[dD]eal)" "<a.*?href=.magnet:.*?</a>" "2h" GameShows
|
||||||
|
https://eztv.ag/ezrss.xml?d=d momma","torrent "([Mm]andalorian)" "<a.*?href=.magnet:.*?</a>" "2h" Mandalorian
|
||||||
|
https://eztv.ag/ezrss.xml?f=f momma","torrent "^([Vv]ikings.S)" "<a.*?href=.magnet:.*?</a>" "2h" Vikings
|
||||||
|
http://rss.slashdot.org/Slashdot/slashdotMain?format=usm news ".*" ".*" "6h"
|
||||||
|
https://netflixtechblog.com/feed news ".*" ".*" "6h"
|
||||||
|
https://www.backblaze.com/blog/feed news "zzzzzzzzzzzzzz.*" "zzzzzzzzzzzzzzzzzz.*" "6h"
|
||||||
|
https://hackernoon.com/feed news "zzzzzzzzzzzzzz.*" "zzzzzzzzzzzzzzzzzz.*" "6h"
|
||||||
|
https://github.com/jpochyla/psst/commits.atom news ".*" ".*" "6h"
|
||||||
|
https://eztv.re/ezrss.xml?b=b momma","torrent "^(Survivor.S.*720p|[Ss]urvivor.*[AaSs][UuAa])" "<a.*?href=.magnet:.*?</a>" "2h" Survivor
|
||||||
|
https://gitlab.com/famedly/conduit.atom news "loljkcancelthisone" "loljkcancelpls" "1288h"
|
||||||
|
https://gitlab.com/famedly/conduit/-/tags?format=atom news ".*" ".*" "6h"
|
||||||
|
https://eztv.re/ezrss.xml?g=g momma","torrent ".*awn.*tars.S.*WEB.*" "<a.*?href=.magnet:.*?</a>" "2h" PawnStars
|
||||||
|
https://ludic.mataroa.blog/rss/ news ".*" ".*" "6h"
|
||||||
|
https://eztv.ag/ezrss.xml?d=d cooking","torrent "^noooooooooooooooooooooooomore([Mm]aster[cC]hef.*720p.WEB|[Mm]aster[cC]hef.Aus.*)" "<a.*?href=.nooooooooooooomagnet:.*?</a>" "2h" MasterChef
|
||||||
|
https://eztv.ag/ezrss.xml?g=g torrent","news "^nooooooooo([Ll]ast..eek..onight..ith..ohn..liver.*WEB)" "<a.*?href=.nooooooooomagnet:.*?</a>" "2h" LastWeekTonight
|
||||||
|
https://memorycache.ai/feed.xml news ".*" ".*" "2h"
|
||||||
|
'
|
||||||
|
#https://eztv.ag/ezrss.xml momma","torrent "^(Wheel.[oO]f.Fortune.[S2]|Jeopardy.20|Gold.Rush.*720.*WEB|Survivor.S.*720p|Gold.Rush.*S.*E.*720.*WEB|Archer|[Mm]aster[cC]hef.US.*720p.WEB|[Mm]aster[cC]hef.Aus.*|[tT]he.[pP]rice.[iI]s.[rR]ight|[lL]et.*[mM]ake.[aA].[dD]eal|The.Handmaids.Tale.*720.*WEB|[Ss]urvivor.*[AaSs][UuAa]|Australian.Ninja.Warrior.*HDTV)" "<a.*?href=.magnet:.*?</a>" "2h"
|
||||||
|
feedsB="$(printf "%s\n" "$feeds" | grep -v '^$' | tail -n 1)"
|
||||||
|
feeds="$feedsB"
|
||||||
|
|
||||||
|
defaultIF='""'
|
||||||
|
defaultCF='"<img.*?/(img)?>"'
|
||||||
|
defaultIN='"6h"'
|
||||||
|
|
||||||
|
feeds="${feeds// /,,}"
|
||||||
|
|
||||||
|
for feed in $feeds; do
|
||||||
|
feed="${feed//,,/ }"
|
||||||
|
link="$(echo "$feed" | awk '{print $1}')"
|
||||||
|
tag="$(echo "$feed" | awk '{print $2}')"
|
||||||
|
if="$(echo "$feed" | awk '{print $3}')"
|
||||||
|
cf="$(echo "$feed" | awk '{print $4}')"
|
||||||
|
in="$(echo "$feed" | awk '{print $5}')"
|
||||||
|
copyright="$(echo "$feed" | awk '{print $6}')"
|
||||||
|
if [ "$if" == "na" ]; then
|
||||||
|
if="$defaultIF"
|
||||||
|
fi
|
||||||
|
if [ "$cf" == "na" ]; then
|
||||||
|
cf="$defaultCF"
|
||||||
|
fi
|
||||||
|
if [ "$in" == "na" ]; then
|
||||||
|
in="$defaultIN"
|
||||||
|
fi
|
||||||
|
cmd="curl ${PROXY:-} -i ${remote}:33419/api/feed -X PUT --data '{\"url\":\"$link\", \"refresh\":$in, \"items\":$if, \"content\":$cf, \"tags\":[\"$tag\"], \"copyright\":\"$copyright\", \"headers\": {\"Cookie\": \"cf_chl_rc_ni=1; cf_clearance=fd4ce60270476e0a520dcde90c81d3d478fcecf9-1623375837-0-150\", \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0\"}}'"
|
||||||
|
echo "$cmd" >&2
|
||||||
|
eval "$cmd"
|
||||||
|
done
|
||||||
7
testdata/do
vendored
Executable file
7
testdata/do
vendored
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
* implement torret+podcast handlers
|
||||||
|
* fetch <img> and embed?
|
||||||
|
|
||||||
|
x render tags -> feeds for server
|
||||||
|
x load feed jobs on startup and queue
|
||||||
|
x push new jobs/queue items from server
|
||||||
|
x implement endpoints for server
|
||||||
0
vendor/github.com/PuerkitoBio/goquery/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/array.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/array.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/doc.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/doc.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/expand.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/expand.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/filter.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/filter.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/go.mod
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/go.mod
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/go.sum
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/go.sum
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/iteration.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/iteration.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/manipulation.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/manipulation.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/property.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/property.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/query.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/query.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/traversal.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/traversal.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/type.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/type.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/utilities.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/PuerkitoBio/goquery/utilities.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/go.mod
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/go.mod
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/parser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/parser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/selector.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/selector.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/serialize.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/serialize.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/specificity.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/andybalholm/cascadia/specificity.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/queue/error.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/queue/error.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/queue/priority_queue.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/queue/priority_queue.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/queue/queue.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/queue/queue.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/queue/ring.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/golang-collections/go-datastructures/queue/ring.go
generated
vendored
Normal file → Executable file
10
vendor/github.com/google/uuid/CONTRIBUTING.md
generated
vendored
Normal file
10
vendor/github.com/google/uuid/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# How to contribute
|
||||||
|
|
||||||
|
We definitely welcome patches and contribution to this project!
|
||||||
|
|
||||||
|
### Legal requirements
|
||||||
|
|
||||||
|
In order to protect both you and ourselves, you will need to sign the
|
||||||
|
[Contributor License Agreement](https://cla.developers.google.com/clas).
|
||||||
|
|
||||||
|
You may have already signed it for other Google projects.
|
||||||
9
vendor/github.com/google/uuid/CONTRIBUTORS
generated
vendored
Normal file
9
vendor/github.com/google/uuid/CONTRIBUTORS
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
Paul Borman <borman@google.com>
|
||||||
|
bmatsuo
|
||||||
|
shawnps
|
||||||
|
theory
|
||||||
|
jboverfelt
|
||||||
|
dsymonds
|
||||||
|
cd1
|
||||||
|
wallclockbuilder
|
||||||
|
dansouza
|
||||||
2
vendor/golang.org/x/text/LICENSE → vendor/github.com/google/uuid/LICENSE
generated
vendored
Executable file → Normal file
2
vendor/golang.org/x/text/LICENSE → vendor/github.com/google/uuid/LICENSE
generated
vendored
Executable file → Normal file
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
Copyright (c) 2009,2014 Google Inc. All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
19
vendor/github.com/google/uuid/README.md
generated
vendored
Normal file
19
vendor/github.com/google/uuid/README.md
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# uuid 
|
||||||
|
The uuid package generates and inspects UUIDs based on
|
||||||
|
[RFC 4122](http://tools.ietf.org/html/rfc4122)
|
||||||
|
and DCE 1.1: Authentication and Security Services.
|
||||||
|
|
||||||
|
This package is based on the github.com/pborman/uuid package (previously named
|
||||||
|
code.google.com/p/go-uuid). It differs from these earlier packages in that
|
||||||
|
a UUID is a 16 byte array rather than a byte slice. One loss due to this
|
||||||
|
change is the ability to represent an invalid UUID (vs a NIL UUID).
|
||||||
|
|
||||||
|
###### Install
|
||||||
|
`go get github.com/google/uuid`
|
||||||
|
|
||||||
|
###### Documentation
|
||||||
|
[](http://godoc.org/github.com/google/uuid)
|
||||||
|
|
||||||
|
Full `go doc` style documentation for the package can be viewed online without
|
||||||
|
installing this package by using the GoDoc site here:
|
||||||
|
http://godoc.org/github.com/google/uuid
|
||||||
80
vendor/github.com/google/uuid/dce.go
generated
vendored
Normal file
80
vendor/github.com/google/uuid/dce.go
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A Domain represents a Version 2 domain
|
||||||
|
type Domain byte
|
||||||
|
|
||||||
|
// Domain constants for DCE Security (Version 2) UUIDs.
|
||||||
|
const (
|
||||||
|
Person = Domain(0)
|
||||||
|
Group = Domain(1)
|
||||||
|
Org = Domain(2)
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewDCESecurity returns a DCE Security (Version 2) UUID.
|
||||||
|
//
|
||||||
|
// The domain should be one of Person, Group or Org.
|
||||||
|
// On a POSIX system the id should be the users UID for the Person
|
||||||
|
// domain and the users GID for the Group. The meaning of id for
|
||||||
|
// the domain Org or on non-POSIX systems is site defined.
|
||||||
|
//
|
||||||
|
// For a given domain/id pair the same token may be returned for up to
|
||||||
|
// 7 minutes and 10 seconds.
|
||||||
|
func NewDCESecurity(domain Domain, id uint32) (UUID, error) {
|
||||||
|
uuid, err := NewUUID()
|
||||||
|
if err == nil {
|
||||||
|
uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2
|
||||||
|
uuid[9] = byte(domain)
|
||||||
|
binary.BigEndian.PutUint32(uuid[0:], id)
|
||||||
|
}
|
||||||
|
return uuid, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDCEPerson returns a DCE Security (Version 2) UUID in the person
|
||||||
|
// domain with the id returned by os.Getuid.
|
||||||
|
//
|
||||||
|
// NewDCESecurity(Person, uint32(os.Getuid()))
|
||||||
|
func NewDCEPerson() (UUID, error) {
|
||||||
|
return NewDCESecurity(Person, uint32(os.Getuid()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDCEGroup returns a DCE Security (Version 2) UUID in the group
|
||||||
|
// domain with the id returned by os.Getgid.
|
||||||
|
//
|
||||||
|
// NewDCESecurity(Group, uint32(os.Getgid()))
|
||||||
|
func NewDCEGroup() (UUID, error) {
|
||||||
|
return NewDCESecurity(Group, uint32(os.Getgid()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Domain returns the domain for a Version 2 UUID. Domains are only defined
|
||||||
|
// for Version 2 UUIDs.
|
||||||
|
func (uuid UUID) Domain() Domain {
|
||||||
|
return Domain(uuid[9])
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID returns the id for a Version 2 UUID. IDs are only defined for Version 2
|
||||||
|
// UUIDs.
|
||||||
|
func (uuid UUID) ID() uint32 {
|
||||||
|
return binary.BigEndian.Uint32(uuid[0:4])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d Domain) String() string {
|
||||||
|
switch d {
|
||||||
|
case Person:
|
||||||
|
return "Person"
|
||||||
|
case Group:
|
||||||
|
return "Group"
|
||||||
|
case Org:
|
||||||
|
return "Org"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Domain%d", int(d))
|
||||||
|
}
|
||||||
12
vendor/github.com/google/uuid/doc.go
generated
vendored
Normal file
12
vendor/github.com/google/uuid/doc.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Package uuid generates and inspects UUIDs.
|
||||||
|
//
|
||||||
|
// UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security
|
||||||
|
// Services.
|
||||||
|
//
|
||||||
|
// A UUID is a 16 byte (128 bit) array. UUIDs may be used as keys to
|
||||||
|
// maps or compared directly.
|
||||||
|
package uuid
|
||||||
1
vendor/github.com/google/uuid/go.mod
generated
vendored
Normal file
1
vendor/github.com/google/uuid/go.mod
generated
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module github.com/google/uuid
|
||||||
53
vendor/github.com/google/uuid/hash.go
generated
vendored
Normal file
53
vendor/github.com/google/uuid/hash.go
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/sha1"
|
||||||
|
"hash"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Well known namespace IDs and UUIDs
|
||||||
|
var (
|
||||||
|
NameSpaceDNS = Must(Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8"))
|
||||||
|
NameSpaceURL = Must(Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8"))
|
||||||
|
NameSpaceOID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
|
||||||
|
NameSpaceX500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
|
||||||
|
Nil UUID // empty UUID, all zeros
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewHash returns a new UUID derived from the hash of space concatenated with
|
||||||
|
// data generated by h. The hash should be at least 16 byte in length. The
|
||||||
|
// first 16 bytes of the hash are used to form the UUID. The version of the
|
||||||
|
// UUID will be the lower 4 bits of version. NewHash is used to implement
|
||||||
|
// NewMD5 and NewSHA1.
|
||||||
|
func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID {
|
||||||
|
h.Reset()
|
||||||
|
h.Write(space[:])
|
||||||
|
h.Write(data)
|
||||||
|
s := h.Sum(nil)
|
||||||
|
var uuid UUID
|
||||||
|
copy(uuid[:], s)
|
||||||
|
uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4)
|
||||||
|
uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant
|
||||||
|
return uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMD5 returns a new MD5 (Version 3) UUID based on the
|
||||||
|
// supplied name space and data. It is the same as calling:
|
||||||
|
//
|
||||||
|
// NewHash(md5.New(), space, data, 3)
|
||||||
|
func NewMD5(space UUID, data []byte) UUID {
|
||||||
|
return NewHash(md5.New(), space, data, 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSHA1 returns a new SHA1 (Version 5) UUID based on the
|
||||||
|
// supplied name space and data. It is the same as calling:
|
||||||
|
//
|
||||||
|
// NewHash(sha1.New(), space, data, 5)
|
||||||
|
func NewSHA1(space UUID, data []byte) UUID {
|
||||||
|
return NewHash(sha1.New(), space, data, 5)
|
||||||
|
}
|
||||||
37
vendor/github.com/google/uuid/marshal.go
generated
vendored
Normal file
37
vendor/github.com/google/uuid/marshal.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// MarshalText implements encoding.TextMarshaler.
|
||||||
|
func (uuid UUID) MarshalText() ([]byte, error) {
|
||||||
|
var js [36]byte
|
||||||
|
encodeHex(js[:], uuid)
|
||||||
|
return js[:], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||||
|
func (uuid *UUID) UnmarshalText(data []byte) error {
|
||||||
|
id, err := ParseBytes(data)
|
||||||
|
if err == nil {
|
||||||
|
*uuid = id
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalBinary implements encoding.BinaryMarshaler.
|
||||||
|
func (uuid UUID) MarshalBinary() ([]byte, error) {
|
||||||
|
return uuid[:], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalBinary implements encoding.BinaryUnmarshaler.
|
||||||
|
func (uuid *UUID) UnmarshalBinary(data []byte) error {
|
||||||
|
if len(data) != 16 {
|
||||||
|
return fmt.Errorf("invalid UUID (got %d bytes)", len(data))
|
||||||
|
}
|
||||||
|
copy(uuid[:], data)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
90
vendor/github.com/google/uuid/node.go
generated
vendored
Normal file
90
vendor/github.com/google/uuid/node.go
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
nodeMu sync.Mutex
|
||||||
|
ifname string // name of interface being used
|
||||||
|
nodeID [6]byte // hardware for version 1 UUIDs
|
||||||
|
zeroID [6]byte // nodeID with only 0's
|
||||||
|
)
|
||||||
|
|
||||||
|
// NodeInterface returns the name of the interface from which the NodeID was
|
||||||
|
// derived. The interface "user" is returned if the NodeID was set by
|
||||||
|
// SetNodeID.
|
||||||
|
func NodeInterface() string {
|
||||||
|
defer nodeMu.Unlock()
|
||||||
|
nodeMu.Lock()
|
||||||
|
return ifname
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNodeInterface selects the hardware address to be used for Version 1 UUIDs.
|
||||||
|
// If name is "" then the first usable interface found will be used or a random
|
||||||
|
// Node ID will be generated. If a named interface cannot be found then false
|
||||||
|
// is returned.
|
||||||
|
//
|
||||||
|
// SetNodeInterface never fails when name is "".
|
||||||
|
func SetNodeInterface(name string) bool {
|
||||||
|
defer nodeMu.Unlock()
|
||||||
|
nodeMu.Lock()
|
||||||
|
return setNodeInterface(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setNodeInterface(name string) bool {
|
||||||
|
iname, addr := getHardwareInterface(name) // null implementation for js
|
||||||
|
if iname != "" && addr != nil {
|
||||||
|
ifname = iname
|
||||||
|
copy(nodeID[:], addr)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// We found no interfaces with a valid hardware address. If name
|
||||||
|
// does not specify a specific interface generate a random Node ID
|
||||||
|
// (section 4.1.6)
|
||||||
|
if name == "" {
|
||||||
|
ifname = "random"
|
||||||
|
randomBits(nodeID[:])
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// NodeID returns a slice of a copy of the current Node ID, setting the Node ID
|
||||||
|
// if not already set.
|
||||||
|
func NodeID() []byte {
|
||||||
|
defer nodeMu.Unlock()
|
||||||
|
nodeMu.Lock()
|
||||||
|
if nodeID == zeroID {
|
||||||
|
setNodeInterface("")
|
||||||
|
}
|
||||||
|
nid := nodeID
|
||||||
|
return nid[:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNodeID sets the Node ID to be used for Version 1 UUIDs. The first 6 bytes
|
||||||
|
// of id are used. If id is less than 6 bytes then false is returned and the
|
||||||
|
// Node ID is not set.
|
||||||
|
func SetNodeID(id []byte) bool {
|
||||||
|
if len(id) < 6 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer nodeMu.Unlock()
|
||||||
|
nodeMu.Lock()
|
||||||
|
copy(nodeID[:], id)
|
||||||
|
ifname = "user"
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// NodeID returns the 6 byte node id encoded in uuid. It returns nil if uuid is
|
||||||
|
// not valid. The NodeID is only well defined for version 1 and 2 UUIDs.
|
||||||
|
func (uuid UUID) NodeID() []byte {
|
||||||
|
var node [6]byte
|
||||||
|
copy(node[:], uuid[10:])
|
||||||
|
return node[:]
|
||||||
|
}
|
||||||
12
vendor/github.com/google/uuid/node_js.go
generated
vendored
Normal file
12
vendor/github.com/google/uuid/node_js.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2017 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build js
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
// getHardwareInterface returns nil values for the JS version of the code.
|
||||||
|
// This remvoves the "net" dependency, because it is not used in the browser.
|
||||||
|
// Using the "net" library inflates the size of the transpiled JS code by 673k bytes.
|
||||||
|
func getHardwareInterface(name string) (string, []byte) { return "", nil }
|
||||||
33
vendor/github.com/google/uuid/node_net.go
generated
vendored
Normal file
33
vendor/github.com/google/uuid/node_net.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// Copyright 2017 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build !js
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import "net"
|
||||||
|
|
||||||
|
var interfaces []net.Interface // cached list of interfaces
|
||||||
|
|
||||||
|
// getHardwareInterface returns the name and hardware address of interface name.
|
||||||
|
// If name is "" then the name and hardware address of one of the system's
|
||||||
|
// interfaces is returned. If no interfaces are found (name does not exist or
|
||||||
|
// there are no interfaces) then "", nil is returned.
|
||||||
|
//
|
||||||
|
// Only addresses of at least 6 bytes are returned.
|
||||||
|
func getHardwareInterface(name string) (string, []byte) {
|
||||||
|
if interfaces == nil {
|
||||||
|
var err error
|
||||||
|
interfaces, err = net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, ifs := range interfaces {
|
||||||
|
if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
|
||||||
|
return ifs.Name, ifs.HardwareAddr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
59
vendor/github.com/google/uuid/sql.go
generated
vendored
Normal file
59
vendor/github.com/google/uuid/sql.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Scan implements sql.Scanner so UUIDs can be read from databases transparently
|
||||||
|
// Currently, database types that map to string and []byte are supported. Please
|
||||||
|
// consult database-specific driver documentation for matching types.
|
||||||
|
func (uuid *UUID) Scan(src interface{}) error {
|
||||||
|
switch src := src.(type) {
|
||||||
|
case nil:
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case string:
|
||||||
|
// if an empty UUID comes from a table, we return a null UUID
|
||||||
|
if src == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// see Parse for required string format
|
||||||
|
u, err := Parse(src)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Scan: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*uuid = u
|
||||||
|
|
||||||
|
case []byte:
|
||||||
|
// if an empty UUID comes from a table, we return a null UUID
|
||||||
|
if len(src) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assumes a simple slice of bytes if 16 bytes
|
||||||
|
// otherwise attempts to parse
|
||||||
|
if len(src) != 16 {
|
||||||
|
return uuid.Scan(string(src))
|
||||||
|
}
|
||||||
|
copy((*uuid)[:], src)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Scan: unable to scan type %T into UUID", src)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value implements sql.Valuer so that UUIDs can be written to databases
|
||||||
|
// transparently. Currently, UUIDs map to strings. Please consult
|
||||||
|
// database-specific driver documentation for matching types.
|
||||||
|
func (uuid UUID) Value() (driver.Value, error) {
|
||||||
|
return uuid.String(), nil
|
||||||
|
}
|
||||||
123
vendor/github.com/google/uuid/time.go
generated
vendored
Normal file
123
vendor/github.com/google/uuid/time.go
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A Time represents a time as the number of 100's of nanoseconds since 15 Oct
|
||||||
|
// 1582.
|
||||||
|
type Time int64
|
||||||
|
|
||||||
|
const (
|
||||||
|
lillian = 2299160 // Julian day of 15 Oct 1582
|
||||||
|
unix = 2440587 // Julian day of 1 Jan 1970
|
||||||
|
epoch = unix - lillian // Days between epochs
|
||||||
|
g1582 = epoch * 86400 // seconds between epochs
|
||||||
|
g1582ns100 = g1582 * 10000000 // 100s of a nanoseconds between epochs
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
timeMu sync.Mutex
|
||||||
|
lasttime uint64 // last time we returned
|
||||||
|
clockSeq uint16 // clock sequence for this run
|
||||||
|
|
||||||
|
timeNow = time.Now // for testing
|
||||||
|
)
|
||||||
|
|
||||||
|
// UnixTime converts t the number of seconds and nanoseconds using the Unix
|
||||||
|
// epoch of 1 Jan 1970.
|
||||||
|
func (t Time) UnixTime() (sec, nsec int64) {
|
||||||
|
sec = int64(t - g1582ns100)
|
||||||
|
nsec = (sec % 10000000) * 100
|
||||||
|
sec /= 10000000
|
||||||
|
return sec, nsec
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and
|
||||||
|
// clock sequence as well as adjusting the clock sequence as needed. An error
|
||||||
|
// is returned if the current time cannot be determined.
|
||||||
|
func GetTime() (Time, uint16, error) {
|
||||||
|
defer timeMu.Unlock()
|
||||||
|
timeMu.Lock()
|
||||||
|
return getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTime() (Time, uint16, error) {
|
||||||
|
t := timeNow()
|
||||||
|
|
||||||
|
// If we don't have a clock sequence already, set one.
|
||||||
|
if clockSeq == 0 {
|
||||||
|
setClockSequence(-1)
|
||||||
|
}
|
||||||
|
now := uint64(t.UnixNano()/100) + g1582ns100
|
||||||
|
|
||||||
|
// If time has gone backwards with this clock sequence then we
|
||||||
|
// increment the clock sequence
|
||||||
|
if now <= lasttime {
|
||||||
|
clockSeq = ((clockSeq + 1) & 0x3fff) | 0x8000
|
||||||
|
}
|
||||||
|
lasttime = now
|
||||||
|
return Time(now), clockSeq, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClockSequence returns the current clock sequence, generating one if not
|
||||||
|
// already set. The clock sequence is only used for Version 1 UUIDs.
|
||||||
|
//
|
||||||
|
// The uuid package does not use global static storage for the clock sequence or
|
||||||
|
// the last time a UUID was generated. Unless SetClockSequence is used, a new
|
||||||
|
// random clock sequence is generated the first time a clock sequence is
|
||||||
|
// requested by ClockSequence, GetTime, or NewUUID. (section 4.2.1.1)
|
||||||
|
func ClockSequence() int {
|
||||||
|
defer timeMu.Unlock()
|
||||||
|
timeMu.Lock()
|
||||||
|
return clockSequence()
|
||||||
|
}
|
||||||
|
|
||||||
|
func clockSequence() int {
|
||||||
|
if clockSeq == 0 {
|
||||||
|
setClockSequence(-1)
|
||||||
|
}
|
||||||
|
return int(clockSeq & 0x3fff)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetClockSequence sets the clock sequence to the lower 14 bits of seq. Setting to
|
||||||
|
// -1 causes a new sequence to be generated.
|
||||||
|
func SetClockSequence(seq int) {
|
||||||
|
defer timeMu.Unlock()
|
||||||
|
timeMu.Lock()
|
||||||
|
setClockSequence(seq)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setClockSequence(seq int) {
|
||||||
|
if seq == -1 {
|
||||||
|
var b [2]byte
|
||||||
|
randomBits(b[:]) // clock sequence
|
||||||
|
seq = int(b[0])<<8 | int(b[1])
|
||||||
|
}
|
||||||
|
oldSeq := clockSeq
|
||||||
|
clockSeq = uint16(seq&0x3fff) | 0x8000 // Set our variant
|
||||||
|
if oldSeq != clockSeq {
|
||||||
|
lasttime = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in
|
||||||
|
// uuid. The time is only defined for version 1 and 2 UUIDs.
|
||||||
|
func (uuid UUID) Time() Time {
|
||||||
|
time := int64(binary.BigEndian.Uint32(uuid[0:4]))
|
||||||
|
time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32
|
||||||
|
time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48
|
||||||
|
return Time(time)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClockSequence returns the clock sequence encoded in uuid.
|
||||||
|
// The clock sequence is only well defined for version 1 and 2 UUIDs.
|
||||||
|
func (uuid UUID) ClockSequence() int {
|
||||||
|
return int(binary.BigEndian.Uint16(uuid[8:10])) & 0x3fff
|
||||||
|
}
|
||||||
43
vendor/github.com/google/uuid/util.go
generated
vendored
Normal file
43
vendor/github.com/google/uuid/util.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// randomBits completely fills slice b with random data.
|
||||||
|
func randomBits(b []byte) {
|
||||||
|
if _, err := io.ReadFull(rander, b); err != nil {
|
||||||
|
panic(err.Error()) // rand should never fail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// xvalues returns the value of a byte as a hexadecimal digit or 255.
|
||||||
|
var xvalues = [256]byte{
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||||
|
}
|
||||||
|
|
||||||
|
// xtob converts hex characters x1 and x2 into a byte.
|
||||||
|
func xtob(x1, x2 byte) (byte, bool) {
|
||||||
|
b1 := xvalues[x1]
|
||||||
|
b2 := xvalues[x2]
|
||||||
|
return (b1 << 4) | b2, b1 != 255 && b2 != 255
|
||||||
|
}
|
||||||
245
vendor/github.com/google/uuid/uuid.go
generated
vendored
Normal file
245
vendor/github.com/google/uuid/uuid.go
generated
vendored
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
// Copyright 2018 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC
|
||||||
|
// 4122.
|
||||||
|
type UUID [16]byte
|
||||||
|
|
||||||
|
// A Version represents a UUID's version.
|
||||||
|
type Version byte
|
||||||
|
|
||||||
|
// A Variant represents a UUID's variant.
|
||||||
|
type Variant byte
|
||||||
|
|
||||||
|
// Constants returned by Variant.
|
||||||
|
const (
|
||||||
|
Invalid = Variant(iota) // Invalid UUID
|
||||||
|
RFC4122 // The variant specified in RFC4122
|
||||||
|
Reserved // Reserved, NCS backward compatibility.
|
||||||
|
Microsoft // Reserved, Microsoft Corporation backward compatibility.
|
||||||
|
Future // Reserved for future definition.
|
||||||
|
)
|
||||||
|
|
||||||
|
var rander = rand.Reader // random function
|
||||||
|
|
||||||
|
// Parse decodes s into a UUID or returns an error. Both the standard UUID
|
||||||
|
// forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and
|
||||||
|
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the
|
||||||
|
// Microsoft encoding {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} and the raw hex
|
||||||
|
// encoding: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
|
||||||
|
func Parse(s string) (UUID, error) {
|
||||||
|
var uuid UUID
|
||||||
|
switch len(s) {
|
||||||
|
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
case 36:
|
||||||
|
|
||||||
|
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
case 36 + 9:
|
||||||
|
if strings.ToLower(s[:9]) != "urn:uuid:" {
|
||||||
|
return uuid, fmt.Errorf("invalid urn prefix: %q", s[:9])
|
||||||
|
}
|
||||||
|
s = s[9:]
|
||||||
|
|
||||||
|
// {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
||||||
|
case 36 + 2:
|
||||||
|
s = s[1:]
|
||||||
|
|
||||||
|
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
case 32:
|
||||||
|
var ok bool
|
||||||
|
for i := range uuid {
|
||||||
|
uuid[i], ok = xtob(s[i*2], s[i*2+1])
|
||||||
|
if !ok {
|
||||||
|
return uuid, errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uuid, nil
|
||||||
|
default:
|
||||||
|
return uuid, fmt.Errorf("invalid UUID length: %d", len(s))
|
||||||
|
}
|
||||||
|
// s is now at least 36 bytes long
|
||||||
|
// it must be of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
|
||||||
|
return uuid, errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
for i, x := range [16]int{
|
||||||
|
0, 2, 4, 6,
|
||||||
|
9, 11,
|
||||||
|
14, 16,
|
||||||
|
19, 21,
|
||||||
|
24, 26, 28, 30, 32, 34} {
|
||||||
|
v, ok := xtob(s[x], s[x+1])
|
||||||
|
if !ok {
|
||||||
|
return uuid, errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
uuid[i] = v
|
||||||
|
}
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseBytes is like Parse, except it parses a byte slice instead of a string.
|
||||||
|
func ParseBytes(b []byte) (UUID, error) {
|
||||||
|
var uuid UUID
|
||||||
|
switch len(b) {
|
||||||
|
case 36: // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
case 36 + 9: // urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
if !bytes.Equal(bytes.ToLower(b[:9]), []byte("urn:uuid:")) {
|
||||||
|
return uuid, fmt.Errorf("invalid urn prefix: %q", b[:9])
|
||||||
|
}
|
||||||
|
b = b[9:]
|
||||||
|
case 36 + 2: // {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
||||||
|
b = b[1:]
|
||||||
|
case 32: // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
var ok bool
|
||||||
|
for i := 0; i < 32; i += 2 {
|
||||||
|
uuid[i/2], ok = xtob(b[i], b[i+1])
|
||||||
|
if !ok {
|
||||||
|
return uuid, errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uuid, nil
|
||||||
|
default:
|
||||||
|
return uuid, fmt.Errorf("invalid UUID length: %d", len(b))
|
||||||
|
}
|
||||||
|
// s is now at least 36 bytes long
|
||||||
|
// it must be of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
if b[8] != '-' || b[13] != '-' || b[18] != '-' || b[23] != '-' {
|
||||||
|
return uuid, errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
for i, x := range [16]int{
|
||||||
|
0, 2, 4, 6,
|
||||||
|
9, 11,
|
||||||
|
14, 16,
|
||||||
|
19, 21,
|
||||||
|
24, 26, 28, 30, 32, 34} {
|
||||||
|
v, ok := xtob(b[x], b[x+1])
|
||||||
|
if !ok {
|
||||||
|
return uuid, errors.New("invalid UUID format")
|
||||||
|
}
|
||||||
|
uuid[i] = v
|
||||||
|
}
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustParse is like Parse but panics if the string cannot be parsed.
|
||||||
|
// It simplifies safe initialization of global variables holding compiled UUIDs.
|
||||||
|
func MustParse(s string) UUID {
|
||||||
|
uuid, err := Parse(s)
|
||||||
|
if err != nil {
|
||||||
|
panic(`uuid: Parse(` + s + `): ` + err.Error())
|
||||||
|
}
|
||||||
|
return uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromBytes creates a new UUID from a byte slice. Returns an error if the slice
|
||||||
|
// does not have a length of 16. The bytes are copied from the slice.
|
||||||
|
func FromBytes(b []byte) (uuid UUID, err error) {
|
||||||
|
err = uuid.UnmarshalBinary(b)
|
||||||
|
return uuid, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Must returns uuid if err is nil and panics otherwise.
|
||||||
|
func Must(uuid UUID, err error) UUID {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
|
// , or "" if uuid is invalid.
|
||||||
|
func (uuid UUID) String() string {
|
||||||
|
var buf [36]byte
|
||||||
|
encodeHex(buf[:], uuid)
|
||||||
|
return string(buf[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// URN returns the RFC 2141 URN form of uuid,
|
||||||
|
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, or "" if uuid is invalid.
|
||||||
|
func (uuid UUID) URN() string {
|
||||||
|
var buf [36 + 9]byte
|
||||||
|
copy(buf[:], "urn:uuid:")
|
||||||
|
encodeHex(buf[9:], uuid)
|
||||||
|
return string(buf[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeHex(dst []byte, uuid UUID) {
|
||||||
|
hex.Encode(dst, uuid[:4])
|
||||||
|
dst[8] = '-'
|
||||||
|
hex.Encode(dst[9:13], uuid[4:6])
|
||||||
|
dst[13] = '-'
|
||||||
|
hex.Encode(dst[14:18], uuid[6:8])
|
||||||
|
dst[18] = '-'
|
||||||
|
hex.Encode(dst[19:23], uuid[8:10])
|
||||||
|
dst[23] = '-'
|
||||||
|
hex.Encode(dst[24:], uuid[10:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Variant returns the variant encoded in uuid.
|
||||||
|
func (uuid UUID) Variant() Variant {
|
||||||
|
switch {
|
||||||
|
case (uuid[8] & 0xc0) == 0x80:
|
||||||
|
return RFC4122
|
||||||
|
case (uuid[8] & 0xe0) == 0xc0:
|
||||||
|
return Microsoft
|
||||||
|
case (uuid[8] & 0xe0) == 0xe0:
|
||||||
|
return Future
|
||||||
|
default:
|
||||||
|
return Reserved
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version returns the version of uuid.
|
||||||
|
func (uuid UUID) Version() Version {
|
||||||
|
return Version(uuid[6] >> 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Version) String() string {
|
||||||
|
if v > 15 {
|
||||||
|
return fmt.Sprintf("BAD_VERSION_%d", v)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("VERSION_%d", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Variant) String() string {
|
||||||
|
switch v {
|
||||||
|
case RFC4122:
|
||||||
|
return "RFC4122"
|
||||||
|
case Reserved:
|
||||||
|
return "Reserved"
|
||||||
|
case Microsoft:
|
||||||
|
return "Microsoft"
|
||||||
|
case Future:
|
||||||
|
return "Future"
|
||||||
|
case Invalid:
|
||||||
|
return "Invalid"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("BadVariant%d", int(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRand sets the random number generator to r, which implements io.Reader.
|
||||||
|
// If r.Read returns an error when the package requests random data then
|
||||||
|
// a panic will be issued.
|
||||||
|
//
|
||||||
|
// Calling SetRand with nil sets the random number generator to the default
|
||||||
|
// generator.
|
||||||
|
func SetRand(r io.Reader) {
|
||||||
|
if r == nil {
|
||||||
|
rander = rand.Reader
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rander = r
|
||||||
|
}
|
||||||
44
vendor/github.com/google/uuid/version1.go
generated
vendored
Normal file
44
vendor/github.com/google/uuid/version1.go
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewUUID returns a Version 1 UUID based on the current NodeID and clock
|
||||||
|
// sequence, and the current time. If the NodeID has not been set by SetNodeID
|
||||||
|
// or SetNodeInterface then it will be set automatically. If the NodeID cannot
|
||||||
|
// be set NewUUID returns nil. If clock sequence has not been set by
|
||||||
|
// SetClockSequence then it will be set automatically. If GetTime fails to
|
||||||
|
// return the current NewUUID returns nil and an error.
|
||||||
|
//
|
||||||
|
// In most cases, New should be used.
|
||||||
|
func NewUUID() (UUID, error) {
|
||||||
|
nodeMu.Lock()
|
||||||
|
if nodeID == zeroID {
|
||||||
|
setNodeInterface("")
|
||||||
|
}
|
||||||
|
nodeMu.Unlock()
|
||||||
|
|
||||||
|
var uuid UUID
|
||||||
|
now, seq, err := GetTime()
|
||||||
|
if err != nil {
|
||||||
|
return uuid, err
|
||||||
|
}
|
||||||
|
|
||||||
|
timeLow := uint32(now & 0xffffffff)
|
||||||
|
timeMid := uint16((now >> 32) & 0xffff)
|
||||||
|
timeHi := uint16((now >> 48) & 0x0fff)
|
||||||
|
timeHi |= 0x1000 // Version 1
|
||||||
|
|
||||||
|
binary.BigEndian.PutUint32(uuid[0:], timeLow)
|
||||||
|
binary.BigEndian.PutUint16(uuid[4:], timeMid)
|
||||||
|
binary.BigEndian.PutUint16(uuid[6:], timeHi)
|
||||||
|
binary.BigEndian.PutUint16(uuid[8:], seq)
|
||||||
|
copy(uuid[10:], nodeID[:])
|
||||||
|
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
38
vendor/github.com/google/uuid/version4.go
generated
vendored
Normal file
38
vendor/github.com/google/uuid/version4.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2016 Google Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import "io"
|
||||||
|
|
||||||
|
// New creates a new random UUID or panics. New is equivalent to
|
||||||
|
// the expression
|
||||||
|
//
|
||||||
|
// uuid.Must(uuid.NewRandom())
|
||||||
|
func New() UUID {
|
||||||
|
return Must(NewRandom())
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRandom returns a Random (Version 4) UUID.
|
||||||
|
//
|
||||||
|
// The strength of the UUIDs is based on the strength of the crypto/rand
|
||||||
|
// package.
|
||||||
|
//
|
||||||
|
// A note about uniqueness derived from the UUID Wikipedia entry:
|
||||||
|
//
|
||||||
|
// Randomly generated UUIDs have 122 random bits. One's annual risk of being
|
||||||
|
// hit by a meteorite is estimated to be one chance in 17 billion, that
|
||||||
|
// means the probability is about 0.00000000006 (6 × 10−11),
|
||||||
|
// equivalent to the odds of creating a few tens of trillions of UUIDs in a
|
||||||
|
// year and having one duplicate.
|
||||||
|
func NewRandom() (UUID, error) {
|
||||||
|
var uuid UUID
|
||||||
|
_, err := io.ReadFull(rander, uuid[:])
|
||||||
|
if err != nil {
|
||||||
|
return Nil, err
|
||||||
|
}
|
||||||
|
uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
|
||||||
|
uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10
|
||||||
|
return uuid, nil
|
||||||
|
}
|
||||||
0
vendor/github.com/gorilla/feeds/AUTHORS
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/AUTHORS
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/atom.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/atom.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/doc.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/doc.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/feed.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/feed.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/json.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/json.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/rss.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/rss.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/test.atom
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/test.atom
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/test.rss
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/test.rss
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/to-implement.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/to-implement.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/uuid.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/gorilla/feeds/uuid.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/atom/feed.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/atom/feed.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/atom/parser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/atom/parser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/detector.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/detector.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/extensions/dublincore.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/extensions/dublincore.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/extensions/extensions.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/extensions/extensions.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/extensions/itunes.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/extensions/itunes.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/feed.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/feed.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/go.mod
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/go.mod
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/go.sum
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/go.sum
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/charsetconv.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/charsetconv.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/dateparser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/dateparser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/extparser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/extparser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/parseutils.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/parseutils.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/xmlbase.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/xmlbase.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/xmlsanitizer.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/internal/shared/xmlsanitizer.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/parser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/parser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/rss/feed.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/rss/feed.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/rss/parser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/rss/parser.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/translator.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/gofeed/translator.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/goxpp/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/goxpp/LICENSE
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/goxpp/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/goxpp/README.md
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/goxpp/xpp.go
generated
vendored
Normal file → Executable file
0
vendor/github.com/mmcdole/goxpp/xpp.go
generated
vendored
Normal file → Executable file
22
vendor/golang.org/x/text/PATENTS
generated
vendored
22
vendor/golang.org/x/text/PATENTS
generated
vendored
@@ -1,22 +0,0 @@
|
|||||||
Additional IP Rights Grant (Patents)
|
|
||||||
|
|
||||||
"This implementation" means the copyrightable works distributed by
|
|
||||||
Google as part of the Go project.
|
|
||||||
|
|
||||||
Google hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
||||||
no-charge, royalty-free, irrevocable (except as stated in this section)
|
|
||||||
patent license to make, have made, use, offer to sell, sell, import,
|
|
||||||
transfer and otherwise run, modify and propagate the contents of this
|
|
||||||
implementation of Go, where such license applies only to those patent
|
|
||||||
claims, both currently owned or controlled by Google and acquired in
|
|
||||||
the future, licensable by Google that are necessarily infringed by this
|
|
||||||
implementation of Go. This grant does not include claims that would be
|
|
||||||
infringed only as a consequence of further modification of this
|
|
||||||
implementation. If you or your agent or exclusive licensee institute or
|
|
||||||
order or agree to the institution of patent litigation against any
|
|
||||||
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
|
||||||
that this implementation of Go or any code incorporated within this
|
|
||||||
implementation of Go constitutes direct or contributory patent
|
|
||||||
infringement, or inducement of patent infringement, then any patent
|
|
||||||
rights granted to you under this License for this implementation of Go
|
|
||||||
shall terminate as of the date such litigation is filed.
|
|
||||||
249
vendor/golang.org/x/text/encoding/charmap/charmap.go
generated
vendored
249
vendor/golang.org/x/text/encoding/charmap/charmap.go
generated
vendored
@@ -1,249 +0,0 @@
|
|||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:generate go run maketables.go
|
|
||||||
|
|
||||||
// Package charmap provides simple character encodings such as IBM Code Page 437
|
|
||||||
// and Windows 1252.
|
|
||||||
package charmap // import "golang.org/x/text/encoding/charmap"
|
|
||||||
|
|
||||||
import (
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"golang.org/x/text/encoding"
|
|
||||||
"golang.org/x/text/encoding/internal"
|
|
||||||
"golang.org/x/text/encoding/internal/identifier"
|
|
||||||
"golang.org/x/text/transform"
|
|
||||||
)
|
|
||||||
|
|
||||||
// These encodings vary only in the way clients should interpret them. Their
|
|
||||||
// coded character set is identical and a single implementation can be shared.
|
|
||||||
var (
|
|
||||||
// ISO8859_6E is the ISO 8859-6E encoding.
|
|
||||||
ISO8859_6E encoding.Encoding = &iso8859_6E
|
|
||||||
|
|
||||||
// ISO8859_6I is the ISO 8859-6I encoding.
|
|
||||||
ISO8859_6I encoding.Encoding = &iso8859_6I
|
|
||||||
|
|
||||||
// ISO8859_8E is the ISO 8859-8E encoding.
|
|
||||||
ISO8859_8E encoding.Encoding = &iso8859_8E
|
|
||||||
|
|
||||||
// ISO8859_8I is the ISO 8859-8I encoding.
|
|
||||||
ISO8859_8I encoding.Encoding = &iso8859_8I
|
|
||||||
|
|
||||||
iso8859_6E = internal.Encoding{
|
|
||||||
Encoding: ISO8859_6,
|
|
||||||
Name: "ISO-8859-6E",
|
|
||||||
MIB: identifier.ISO88596E,
|
|
||||||
}
|
|
||||||
|
|
||||||
iso8859_6I = internal.Encoding{
|
|
||||||
Encoding: ISO8859_6,
|
|
||||||
Name: "ISO-8859-6I",
|
|
||||||
MIB: identifier.ISO88596I,
|
|
||||||
}
|
|
||||||
|
|
||||||
iso8859_8E = internal.Encoding{
|
|
||||||
Encoding: ISO8859_8,
|
|
||||||
Name: "ISO-8859-8E",
|
|
||||||
MIB: identifier.ISO88598E,
|
|
||||||
}
|
|
||||||
|
|
||||||
iso8859_8I = internal.Encoding{
|
|
||||||
Encoding: ISO8859_8,
|
|
||||||
Name: "ISO-8859-8I",
|
|
||||||
MIB: identifier.ISO88598I,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// All is a list of all defined encodings in this package.
|
|
||||||
var All []encoding.Encoding = listAll
|
|
||||||
|
|
||||||
// TODO: implement these encodings, in order of importance.
|
|
||||||
// ASCII, ISO8859_1: Rather common. Close to Windows 1252.
|
|
||||||
// ISO8859_9: Close to Windows 1254.
|
|
||||||
|
|
||||||
// utf8Enc holds a rune's UTF-8 encoding in data[:len].
|
|
||||||
type utf8Enc struct {
|
|
||||||
len uint8
|
|
||||||
data [3]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// Charmap is an 8-bit character set encoding.
|
|
||||||
type Charmap struct {
|
|
||||||
// name is the encoding's name.
|
|
||||||
name string
|
|
||||||
// mib is the encoding type of this encoder.
|
|
||||||
mib identifier.MIB
|
|
||||||
// asciiSuperset states whether the encoding is a superset of ASCII.
|
|
||||||
asciiSuperset bool
|
|
||||||
// low is the lower bound of the encoded byte for a non-ASCII rune. If
|
|
||||||
// Charmap.asciiSuperset is true then this will be 0x80, otherwise 0x00.
|
|
||||||
low uint8
|
|
||||||
// replacement is the encoded replacement character.
|
|
||||||
replacement byte
|
|
||||||
// decode is the map from encoded byte to UTF-8.
|
|
||||||
decode [256]utf8Enc
|
|
||||||
// encoding is the map from runes to encoded bytes. Each entry is a
|
|
||||||
// uint32: the high 8 bits are the encoded byte and the low 24 bits are
|
|
||||||
// the rune. The table entries are sorted by ascending rune.
|
|
||||||
encode [256]uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDecoder implements the encoding.Encoding interface.
|
|
||||||
func (m *Charmap) NewDecoder() *encoding.Decoder {
|
|
||||||
return &encoding.Decoder{Transformer: charmapDecoder{charmap: m}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewEncoder implements the encoding.Encoding interface.
|
|
||||||
func (m *Charmap) NewEncoder() *encoding.Encoder {
|
|
||||||
return &encoding.Encoder{Transformer: charmapEncoder{charmap: m}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the Charmap's name.
|
|
||||||
func (m *Charmap) String() string {
|
|
||||||
return m.name
|
|
||||||
}
|
|
||||||
|
|
||||||
// ID implements an internal interface.
|
|
||||||
func (m *Charmap) ID() (mib identifier.MIB, other string) {
|
|
||||||
return m.mib, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// charmapDecoder implements transform.Transformer by decoding to UTF-8.
|
|
||||||
type charmapDecoder struct {
|
|
||||||
transform.NopResetter
|
|
||||||
charmap *Charmap
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m charmapDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
|
|
||||||
for i, c := range src {
|
|
||||||
if m.charmap.asciiSuperset && c < utf8.RuneSelf {
|
|
||||||
if nDst >= len(dst) {
|
|
||||||
err = transform.ErrShortDst
|
|
||||||
break
|
|
||||||
}
|
|
||||||
dst[nDst] = c
|
|
||||||
nDst++
|
|
||||||
nSrc = i + 1
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
decode := &m.charmap.decode[c]
|
|
||||||
n := int(decode.len)
|
|
||||||
if nDst+n > len(dst) {
|
|
||||||
err = transform.ErrShortDst
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// It's 15% faster to avoid calling copy for these tiny slices.
|
|
||||||
for j := 0; j < n; j++ {
|
|
||||||
dst[nDst] = decode.data[j]
|
|
||||||
nDst++
|
|
||||||
}
|
|
||||||
nSrc = i + 1
|
|
||||||
}
|
|
||||||
return nDst, nSrc, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeByte returns the Charmap's rune decoding of the byte b.
|
|
||||||
func (m *Charmap) DecodeByte(b byte) rune {
|
|
||||||
switch x := &m.decode[b]; x.len {
|
|
||||||
case 1:
|
|
||||||
return rune(x.data[0])
|
|
||||||
case 2:
|
|
||||||
return rune(x.data[0]&0x1f)<<6 | rune(x.data[1]&0x3f)
|
|
||||||
default:
|
|
||||||
return rune(x.data[0]&0x0f)<<12 | rune(x.data[1]&0x3f)<<6 | rune(x.data[2]&0x3f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// charmapEncoder implements transform.Transformer by encoding from UTF-8.
|
|
||||||
type charmapEncoder struct {
|
|
||||||
transform.NopResetter
|
|
||||||
charmap *Charmap
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m charmapEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
|
|
||||||
r, size := rune(0), 0
|
|
||||||
loop:
|
|
||||||
for nSrc < len(src) {
|
|
||||||
if nDst >= len(dst) {
|
|
||||||
err = transform.ErrShortDst
|
|
||||||
break
|
|
||||||
}
|
|
||||||
r = rune(src[nSrc])
|
|
||||||
|
|
||||||
// Decode a 1-byte rune.
|
|
||||||
if r < utf8.RuneSelf {
|
|
||||||
if m.charmap.asciiSuperset {
|
|
||||||
nSrc++
|
|
||||||
dst[nDst] = uint8(r)
|
|
||||||
nDst++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
size = 1
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Decode a multi-byte rune.
|
|
||||||
r, size = utf8.DecodeRune(src[nSrc:])
|
|
||||||
if size == 1 {
|
|
||||||
// All valid runes of size 1 (those below utf8.RuneSelf) were
|
|
||||||
// handled above. We have invalid UTF-8 or we haven't seen the
|
|
||||||
// full character yet.
|
|
||||||
if !atEOF && !utf8.FullRune(src[nSrc:]) {
|
|
||||||
err = transform.ErrShortSrc
|
|
||||||
} else {
|
|
||||||
err = internal.RepertoireError(m.charmap.replacement)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Binary search in [low, high) for that rune in the m.charmap.encode table.
|
|
||||||
for low, high := int(m.charmap.low), 0x100; ; {
|
|
||||||
if low >= high {
|
|
||||||
err = internal.RepertoireError(m.charmap.replacement)
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
mid := (low + high) / 2
|
|
||||||
got := m.charmap.encode[mid]
|
|
||||||
gotRune := rune(got & (1<<24 - 1))
|
|
||||||
if gotRune < r {
|
|
||||||
low = mid + 1
|
|
||||||
} else if gotRune > r {
|
|
||||||
high = mid
|
|
||||||
} else {
|
|
||||||
dst[nDst] = byte(got >> 24)
|
|
||||||
nDst++
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nSrc += size
|
|
||||||
}
|
|
||||||
return nDst, nSrc, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeRune returns the Charmap's byte encoding of the rune r. ok is whether
|
|
||||||
// r is in the Charmap's repertoire. If not, b is set to the Charmap's
|
|
||||||
// replacement byte. This is often the ASCII substitute character '\x1a'.
|
|
||||||
func (m *Charmap) EncodeRune(r rune) (b byte, ok bool) {
|
|
||||||
if r < utf8.RuneSelf && m.asciiSuperset {
|
|
||||||
return byte(r), true
|
|
||||||
}
|
|
||||||
for low, high := int(m.low), 0x100; ; {
|
|
||||||
if low >= high {
|
|
||||||
return m.replacement, false
|
|
||||||
}
|
|
||||||
mid := (low + high) / 2
|
|
||||||
got := m.encode[mid]
|
|
||||||
gotRune := rune(got & (1<<24 - 1))
|
|
||||||
if gotRune < r {
|
|
||||||
low = mid + 1
|
|
||||||
} else if gotRune > r {
|
|
||||||
high = mid
|
|
||||||
} else {
|
|
||||||
return byte(got >> 24), true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
556
vendor/golang.org/x/text/encoding/charmap/maketables.go
generated
vendored
556
vendor/golang.org/x/text/encoding/charmap/maketables.go
generated
vendored
@@ -1,556 +0,0 @@
|
|||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"golang.org/x/text/encoding"
|
|
||||||
"golang.org/x/text/internal/gen"
|
|
||||||
)
|
|
||||||
|
|
||||||
const ascii = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" +
|
|
||||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
|
|
||||||
` !"#$%&'()*+,-./0123456789:;<=>?` +
|
|
||||||
`@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_` +
|
|
||||||
"`abcdefghijklmnopqrstuvwxyz{|}~\u007f"
|
|
||||||
|
|
||||||
var encodings = []struct {
|
|
||||||
name string
|
|
||||||
mib string
|
|
||||||
comment string
|
|
||||||
varName string
|
|
||||||
replacement byte
|
|
||||||
mapping string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
"IBM Code Page 037",
|
|
||||||
"IBM037",
|
|
||||||
"",
|
|
||||||
"CodePage037",
|
|
||||||
0x3f,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM037-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 437",
|
|
||||||
"PC8CodePage437",
|
|
||||||
"",
|
|
||||||
"CodePage437",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM437-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 850",
|
|
||||||
"PC850Multilingual",
|
|
||||||
"",
|
|
||||||
"CodePage850",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM850-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 852",
|
|
||||||
"PCp852",
|
|
||||||
"",
|
|
||||||
"CodePage852",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM852-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 855",
|
|
||||||
"IBM855",
|
|
||||||
"",
|
|
||||||
"CodePage855",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM855-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows Code Page 858", // PC latin1 with Euro
|
|
||||||
"IBM00858",
|
|
||||||
"",
|
|
||||||
"CodePage858",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/windows-858-2000.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 860",
|
|
||||||
"IBM860",
|
|
||||||
"",
|
|
||||||
"CodePage860",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM860-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 862",
|
|
||||||
"PC862LatinHebrew",
|
|
||||||
"",
|
|
||||||
"CodePage862",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM862-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 863",
|
|
||||||
"IBM863",
|
|
||||||
"",
|
|
||||||
"CodePage863",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM863-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 865",
|
|
||||||
"IBM865",
|
|
||||||
"",
|
|
||||||
"CodePage865",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM865-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 866",
|
|
||||||
"IBM866",
|
|
||||||
"",
|
|
||||||
"CodePage866",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-ibm866.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 1047",
|
|
||||||
"IBM1047",
|
|
||||||
"",
|
|
||||||
"CodePage1047",
|
|
||||||
0x3f,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM1047-2.1.2.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IBM Code Page 1140",
|
|
||||||
"IBM01140",
|
|
||||||
"",
|
|
||||||
"CodePage1140",
|
|
||||||
0x3f,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/ibm-1140_P100-1997.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-1",
|
|
||||||
"ISOLatin1",
|
|
||||||
"",
|
|
||||||
"ISO8859_1",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/iso-8859_1-1998.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-2",
|
|
||||||
"ISOLatin2",
|
|
||||||
"",
|
|
||||||
"ISO8859_2",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-2.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-3",
|
|
||||||
"ISOLatin3",
|
|
||||||
"",
|
|
||||||
"ISO8859_3",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-3.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-4",
|
|
||||||
"ISOLatin4",
|
|
||||||
"",
|
|
||||||
"ISO8859_4",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-4.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-5",
|
|
||||||
"ISOLatinCyrillic",
|
|
||||||
"",
|
|
||||||
"ISO8859_5",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-5.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-6",
|
|
||||||
"ISOLatinArabic",
|
|
||||||
"",
|
|
||||||
"ISO8859_6,ISO8859_6E,ISO8859_6I",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-6.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-7",
|
|
||||||
"ISOLatinGreek",
|
|
||||||
"",
|
|
||||||
"ISO8859_7",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-7.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-8",
|
|
||||||
"ISOLatinHebrew",
|
|
||||||
"",
|
|
||||||
"ISO8859_8,ISO8859_8E,ISO8859_8I",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-8.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-9",
|
|
||||||
"ISOLatin5",
|
|
||||||
"",
|
|
||||||
"ISO8859_9",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/iso-8859_9-1999.ucm",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-10",
|
|
||||||
"ISOLatin6",
|
|
||||||
"",
|
|
||||||
"ISO8859_10",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-10.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-13",
|
|
||||||
"ISO885913",
|
|
||||||
"",
|
|
||||||
"ISO8859_13",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-13.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-14",
|
|
||||||
"ISO885914",
|
|
||||||
"",
|
|
||||||
"ISO8859_14",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-14.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-15",
|
|
||||||
"ISO885915",
|
|
||||||
"",
|
|
||||||
"ISO8859_15",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-15.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ISO 8859-16",
|
|
||||||
"ISO885916",
|
|
||||||
"",
|
|
||||||
"ISO8859_16",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-iso-8859-16.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"KOI8-R",
|
|
||||||
"KOI8R",
|
|
||||||
"",
|
|
||||||
"KOI8R",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-koi8-r.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"KOI8-U",
|
|
||||||
"KOI8U",
|
|
||||||
"",
|
|
||||||
"KOI8U",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-koi8-u.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Macintosh",
|
|
||||||
"Macintosh",
|
|
||||||
"",
|
|
||||||
"Macintosh",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-macintosh.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Macintosh Cyrillic",
|
|
||||||
"MacintoshCyrillic",
|
|
||||||
"",
|
|
||||||
"MacintoshCyrillic",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-x-mac-cyrillic.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 874",
|
|
||||||
"Windows874",
|
|
||||||
"",
|
|
||||||
"Windows874",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-874.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1250",
|
|
||||||
"Windows1250",
|
|
||||||
"",
|
|
||||||
"Windows1250",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1250.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1251",
|
|
||||||
"Windows1251",
|
|
||||||
"",
|
|
||||||
"Windows1251",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1251.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1252",
|
|
||||||
"Windows1252",
|
|
||||||
"",
|
|
||||||
"Windows1252",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1252.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1253",
|
|
||||||
"Windows1253",
|
|
||||||
"",
|
|
||||||
"Windows1253",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1253.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1254",
|
|
||||||
"Windows1254",
|
|
||||||
"",
|
|
||||||
"Windows1254",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1254.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1255",
|
|
||||||
"Windows1255",
|
|
||||||
"",
|
|
||||||
"Windows1255",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1255.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1256",
|
|
||||||
"Windows1256",
|
|
||||||
"",
|
|
||||||
"Windows1256",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1256.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1257",
|
|
||||||
"Windows1257",
|
|
||||||
"",
|
|
||||||
"Windows1257",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1257.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Windows 1258",
|
|
||||||
"Windows1258",
|
|
||||||
"",
|
|
||||||
"Windows1258",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
"http://encoding.spec.whatwg.org/index-windows-1258.txt",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"X-User-Defined",
|
|
||||||
"XUserDefined",
|
|
||||||
"It is defined at http://encoding.spec.whatwg.org/#x-user-defined",
|
|
||||||
"XUserDefined",
|
|
||||||
encoding.ASCIISub,
|
|
||||||
ascii +
|
|
||||||
"\uf780\uf781\uf782\uf783\uf784\uf785\uf786\uf787" +
|
|
||||||
"\uf788\uf789\uf78a\uf78b\uf78c\uf78d\uf78e\uf78f" +
|
|
||||||
"\uf790\uf791\uf792\uf793\uf794\uf795\uf796\uf797" +
|
|
||||||
"\uf798\uf799\uf79a\uf79b\uf79c\uf79d\uf79e\uf79f" +
|
|
||||||
"\uf7a0\uf7a1\uf7a2\uf7a3\uf7a4\uf7a5\uf7a6\uf7a7" +
|
|
||||||
"\uf7a8\uf7a9\uf7aa\uf7ab\uf7ac\uf7ad\uf7ae\uf7af" +
|
|
||||||
"\uf7b0\uf7b1\uf7b2\uf7b3\uf7b4\uf7b5\uf7b6\uf7b7" +
|
|
||||||
"\uf7b8\uf7b9\uf7ba\uf7bb\uf7bc\uf7bd\uf7be\uf7bf" +
|
|
||||||
"\uf7c0\uf7c1\uf7c2\uf7c3\uf7c4\uf7c5\uf7c6\uf7c7" +
|
|
||||||
"\uf7c8\uf7c9\uf7ca\uf7cb\uf7cc\uf7cd\uf7ce\uf7cf" +
|
|
||||||
"\uf7d0\uf7d1\uf7d2\uf7d3\uf7d4\uf7d5\uf7d6\uf7d7" +
|
|
||||||
"\uf7d8\uf7d9\uf7da\uf7db\uf7dc\uf7dd\uf7de\uf7df" +
|
|
||||||
"\uf7e0\uf7e1\uf7e2\uf7e3\uf7e4\uf7e5\uf7e6\uf7e7" +
|
|
||||||
"\uf7e8\uf7e9\uf7ea\uf7eb\uf7ec\uf7ed\uf7ee\uf7ef" +
|
|
||||||
"\uf7f0\uf7f1\uf7f2\uf7f3\uf7f4\uf7f5\uf7f6\uf7f7" +
|
|
||||||
"\uf7f8\uf7f9\uf7fa\uf7fb\uf7fc\uf7fd\uf7fe\uf7ff",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func getWHATWG(url string) string {
|
|
||||||
res, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("%q: Get: %v", url, err)
|
|
||||||
}
|
|
||||||
defer res.Body.Close()
|
|
||||||
|
|
||||||
mapping := make([]rune, 128)
|
|
||||||
for i := range mapping {
|
|
||||||
mapping[i] = '\ufffd'
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(res.Body)
|
|
||||||
for scanner.Scan() {
|
|
||||||
s := strings.TrimSpace(scanner.Text())
|
|
||||||
if s == "" || s[0] == '#' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
x, y := 0, 0
|
|
||||||
if _, err := fmt.Sscanf(s, "%d\t0x%x", &x, &y); err != nil {
|
|
||||||
log.Fatalf("could not parse %q", s)
|
|
||||||
}
|
|
||||||
if x < 0 || 128 <= x {
|
|
||||||
log.Fatalf("code %d is out of range", x)
|
|
||||||
}
|
|
||||||
if 0x80 <= y && y < 0xa0 {
|
|
||||||
// We diverge from the WHATWG spec by mapping control characters
|
|
||||||
// in the range [0x80, 0xa0) to U+FFFD.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
mapping[x] = rune(y)
|
|
||||||
}
|
|
||||||
return ascii + string(mapping)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getUCM(url string) string {
|
|
||||||
res, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("%q: Get: %v", url, err)
|
|
||||||
}
|
|
||||||
defer res.Body.Close()
|
|
||||||
|
|
||||||
mapping := make([]rune, 256)
|
|
||||||
for i := range mapping {
|
|
||||||
mapping[i] = '\ufffd'
|
|
||||||
}
|
|
||||||
|
|
||||||
charsFound := 0
|
|
||||||
scanner := bufio.NewScanner(res.Body)
|
|
||||||
for scanner.Scan() {
|
|
||||||
s := strings.TrimSpace(scanner.Text())
|
|
||||||
if s == "" || s[0] == '#' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var c byte
|
|
||||||
var r rune
|
|
||||||
if _, err := fmt.Sscanf(s, `<U%x> \x%x |0`, &r, &c); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
mapping[c] = r
|
|
||||||
charsFound++
|
|
||||||
}
|
|
||||||
|
|
||||||
if charsFound < 200 {
|
|
||||||
log.Fatalf("%q: only %d characters found (wrong page format?)", url, charsFound)
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(mapping)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
mibs := map[string]bool{}
|
|
||||||
all := []string{}
|
|
||||||
|
|
||||||
w := gen.NewCodeWriter()
|
|
||||||
defer w.WriteGoFile("tables.go", "charmap")
|
|
||||||
|
|
||||||
printf := func(s string, a ...interface{}) { fmt.Fprintf(w, s, a...) }
|
|
||||||
|
|
||||||
printf("import (\n")
|
|
||||||
printf("\t\"golang.org/x/text/encoding\"\n")
|
|
||||||
printf("\t\"golang.org/x/text/encoding/internal/identifier\"\n")
|
|
||||||
printf(")\n\n")
|
|
||||||
for _, e := range encodings {
|
|
||||||
varNames := strings.Split(e.varName, ",")
|
|
||||||
all = append(all, varNames...)
|
|
||||||
varName := varNames[0]
|
|
||||||
switch {
|
|
||||||
case strings.HasPrefix(e.mapping, "http://encoding.spec.whatwg.org/"):
|
|
||||||
e.mapping = getWHATWG(e.mapping)
|
|
||||||
case strings.HasPrefix(e.mapping, "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/"):
|
|
||||||
e.mapping = getUCM(e.mapping)
|
|
||||||
}
|
|
||||||
|
|
||||||
asciiSuperset, low := strings.HasPrefix(e.mapping, ascii), 0x00
|
|
||||||
if asciiSuperset {
|
|
||||||
low = 0x80
|
|
||||||
}
|
|
||||||
lvn := 1
|
|
||||||
if strings.HasPrefix(varName, "ISO") || strings.HasPrefix(varName, "KOI") {
|
|
||||||
lvn = 3
|
|
||||||
}
|
|
||||||
lowerVarName := strings.ToLower(varName[:lvn]) + varName[lvn:]
|
|
||||||
printf("// %s is the %s encoding.\n", varName, e.name)
|
|
||||||
if e.comment != "" {
|
|
||||||
printf("//\n// %s\n", e.comment)
|
|
||||||
}
|
|
||||||
printf("var %s *Charmap = &%s\n\nvar %s = Charmap{\nname: %q,\n",
|
|
||||||
varName, lowerVarName, lowerVarName, e.name)
|
|
||||||
if mibs[e.mib] {
|
|
||||||
log.Fatalf("MIB type %q declared multiple times.", e.mib)
|
|
||||||
}
|
|
||||||
printf("mib: identifier.%s,\n", e.mib)
|
|
||||||
printf("asciiSuperset: %t,\n", asciiSuperset)
|
|
||||||
printf("low: 0x%02x,\n", low)
|
|
||||||
printf("replacement: 0x%02x,\n", e.replacement)
|
|
||||||
|
|
||||||
printf("decode: [256]utf8Enc{\n")
|
|
||||||
i, backMapping := 0, map[rune]byte{}
|
|
||||||
for _, c := range e.mapping {
|
|
||||||
if _, ok := backMapping[c]; !ok && c != utf8.RuneError {
|
|
||||||
backMapping[c] = byte(i)
|
|
||||||
}
|
|
||||||
var buf [8]byte
|
|
||||||
n := utf8.EncodeRune(buf[:], c)
|
|
||||||
if n > 3 {
|
|
||||||
panic(fmt.Sprintf("rune %q (%U) is too long", c, c))
|
|
||||||
}
|
|
||||||
printf("{%d,[3]byte{0x%02x,0x%02x,0x%02x}},", n, buf[0], buf[1], buf[2])
|
|
||||||
if i%2 == 1 {
|
|
||||||
printf("\n")
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
printf("},\n")
|
|
||||||
|
|
||||||
printf("encode: [256]uint32{\n")
|
|
||||||
encode := make([]uint32, 0, 256)
|
|
||||||
for c, i := range backMapping {
|
|
||||||
encode = append(encode, uint32(i)<<24|uint32(c))
|
|
||||||
}
|
|
||||||
sort.Sort(byRune(encode))
|
|
||||||
for len(encode) < cap(encode) {
|
|
||||||
encode = append(encode, encode[len(encode)-1])
|
|
||||||
}
|
|
||||||
for i, enc := range encode {
|
|
||||||
printf("0x%08x,", enc)
|
|
||||||
if i%8 == 7 {
|
|
||||||
printf("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("},\n}\n")
|
|
||||||
|
|
||||||
// Add an estimate of the size of a single Charmap{} struct value, which
|
|
||||||
// includes two 256 elem arrays of 4 bytes and some extra fields, which
|
|
||||||
// align to 3 uint64s on 64-bit architectures.
|
|
||||||
w.Size += 2*4*256 + 3*8
|
|
||||||
}
|
|
||||||
// TODO: add proper line breaking.
|
|
||||||
printf("var listAll = []encoding.Encoding{\n%s,\n}\n\n", strings.Join(all, ",\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type byRune []uint32
|
|
||||||
|
|
||||||
func (b byRune) Len() int { return len(b) }
|
|
||||||
func (b byRune) Less(i, j int) bool { return b[i]&0xffffff < b[j]&0xffffff }
|
|
||||||
func (b byRune) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
|
||||||
335
vendor/golang.org/x/text/encoding/encoding.go
generated
vendored
335
vendor/golang.org/x/text/encoding/encoding.go
generated
vendored
@@ -1,335 +0,0 @@
|
|||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package encoding defines an interface for character encodings, such as Shift
|
|
||||||
// JIS and Windows 1252, that can convert to and from UTF-8.
|
|
||||||
//
|
|
||||||
// Encoding implementations are provided in other packages, such as
|
|
||||||
// golang.org/x/text/encoding/charmap and
|
|
||||||
// golang.org/x/text/encoding/japanese.
|
|
||||||
package encoding // import "golang.org/x/text/encoding"
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"strconv"
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"golang.org/x/text/encoding/internal/identifier"
|
|
||||||
"golang.org/x/text/transform"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// - There seems to be some inconsistency in when decoders return errors
|
|
||||||
// and when not. Also documentation seems to suggest they shouldn't return
|
|
||||||
// errors at all (except for UTF-16).
|
|
||||||
// - Encoders seem to rely on or at least benefit from the input being in NFC
|
|
||||||
// normal form. Perhaps add an example how users could prepare their output.
|
|
||||||
|
|
||||||
// Encoding is a character set encoding that can be transformed to and from
|
|
||||||
// UTF-8.
|
|
||||||
type Encoding interface {
|
|
||||||
// NewDecoder returns a Decoder.
|
|
||||||
NewDecoder() *Decoder
|
|
||||||
|
|
||||||
// NewEncoder returns an Encoder.
|
|
||||||
NewEncoder() *Encoder
|
|
||||||
}
|
|
||||||
|
|
||||||
// A Decoder converts bytes to UTF-8. It implements transform.Transformer.
|
|
||||||
//
|
|
||||||
// Transforming source bytes that are not of that encoding will not result in an
|
|
||||||
// error per se. Each byte that cannot be transcoded will be represented in the
|
|
||||||
// output by the UTF-8 encoding of '\uFFFD', the replacement rune.
|
|
||||||
type Decoder struct {
|
|
||||||
transform.Transformer
|
|
||||||
|
|
||||||
// This forces external creators of Decoders to use names in struct
|
|
||||||
// initializers, allowing for future extendibility without having to break
|
|
||||||
// code.
|
|
||||||
_ struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bytes converts the given encoded bytes to UTF-8. It returns the converted
|
|
||||||
// bytes or nil, err if any error occurred.
|
|
||||||
func (d *Decoder) Bytes(b []byte) ([]byte, error) {
|
|
||||||
b, _, err := transform.Bytes(d, b)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// String converts the given encoded string to UTF-8. It returns the converted
|
|
||||||
// string or "", err if any error occurred.
|
|
||||||
func (d *Decoder) String(s string) (string, error) {
|
|
||||||
s, _, err := transform.String(d, s)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reader wraps another Reader to decode its bytes.
|
|
||||||
//
|
|
||||||
// The Decoder may not be used for any other operation as long as the returned
|
|
||||||
// Reader is in use.
|
|
||||||
func (d *Decoder) Reader(r io.Reader) io.Reader {
|
|
||||||
return transform.NewReader(r, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
// An Encoder converts bytes from UTF-8. It implements transform.Transformer.
|
|
||||||
//
|
|
||||||
// Each rune that cannot be transcoded will result in an error. In this case,
|
|
||||||
// the transform will consume all source byte up to, not including the offending
|
|
||||||
// rune. Transforming source bytes that are not valid UTF-8 will be replaced by
|
|
||||||
// `\uFFFD`. To return early with an error instead, use transform.Chain to
|
|
||||||
// preprocess the data with a UTF8Validator.
|
|
||||||
type Encoder struct {
|
|
||||||
transform.Transformer
|
|
||||||
|
|
||||||
// This forces external creators of Encoders to use names in struct
|
|
||||||
// initializers, allowing for future extendibility without having to break
|
|
||||||
// code.
|
|
||||||
_ struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bytes converts bytes from UTF-8. It returns the converted bytes or nil, err if
|
|
||||||
// any error occurred.
|
|
||||||
func (e *Encoder) Bytes(b []byte) ([]byte, error) {
|
|
||||||
b, _, err := transform.Bytes(e, b)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// String converts a string from UTF-8. It returns the converted string or
|
|
||||||
// "", err if any error occurred.
|
|
||||||
func (e *Encoder) String(s string) (string, error) {
|
|
||||||
s, _, err := transform.String(e, s)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Writer wraps another Writer to encode its UTF-8 output.
|
|
||||||
//
|
|
||||||
// The Encoder may not be used for any other operation as long as the returned
|
|
||||||
// Writer is in use.
|
|
||||||
func (e *Encoder) Writer(w io.Writer) io.Writer {
|
|
||||||
return transform.NewWriter(w, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ASCIISub is the ASCII substitute character, as recommended by
|
|
||||||
// https://unicode.org/reports/tr36/#Text_Comparison
|
|
||||||
const ASCIISub = '\x1a'
|
|
||||||
|
|
||||||
// Nop is the nop encoding. Its transformed bytes are the same as the source
|
|
||||||
// bytes; it does not replace invalid UTF-8 sequences.
|
|
||||||
var Nop Encoding = nop{}
|
|
||||||
|
|
||||||
type nop struct{}
|
|
||||||
|
|
||||||
func (nop) NewDecoder() *Decoder {
|
|
||||||
return &Decoder{Transformer: transform.Nop}
|
|
||||||
}
|
|
||||||
func (nop) NewEncoder() *Encoder {
|
|
||||||
return &Encoder{Transformer: transform.Nop}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replacement is the replacement encoding. Decoding from the replacement
|
|
||||||
// encoding yields a single '\uFFFD' replacement rune. Encoding from UTF-8 to
|
|
||||||
// the replacement encoding yields the same as the source bytes except that
|
|
||||||
// invalid UTF-8 is converted to '\uFFFD'.
|
|
||||||
//
|
|
||||||
// It is defined at http://encoding.spec.whatwg.org/#replacement
|
|
||||||
var Replacement Encoding = replacement{}
|
|
||||||
|
|
||||||
type replacement struct{}
|
|
||||||
|
|
||||||
func (replacement) NewDecoder() *Decoder {
|
|
||||||
return &Decoder{Transformer: replacementDecoder{}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (replacement) NewEncoder() *Encoder {
|
|
||||||
return &Encoder{Transformer: replacementEncoder{}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (replacement) ID() (mib identifier.MIB, other string) {
|
|
||||||
return identifier.Replacement, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
type replacementDecoder struct{ transform.NopResetter }
|
|
||||||
|
|
||||||
func (replacementDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
|
|
||||||
if len(dst) < 3 {
|
|
||||||
return 0, 0, transform.ErrShortDst
|
|
||||||
}
|
|
||||||
if atEOF {
|
|
||||||
const fffd = "\ufffd"
|
|
||||||
dst[0] = fffd[0]
|
|
||||||
dst[1] = fffd[1]
|
|
||||||
dst[2] = fffd[2]
|
|
||||||
nDst = 3
|
|
||||||
}
|
|
||||||
return nDst, len(src), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type replacementEncoder struct{ transform.NopResetter }
|
|
||||||
|
|
||||||
func (replacementEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
|
|
||||||
r, size := rune(0), 0
|
|
||||||
|
|
||||||
for ; nSrc < len(src); nSrc += size {
|
|
||||||
r = rune(src[nSrc])
|
|
||||||
|
|
||||||
// Decode a 1-byte rune.
|
|
||||||
if r < utf8.RuneSelf {
|
|
||||||
size = 1
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Decode a multi-byte rune.
|
|
||||||
r, size = utf8.DecodeRune(src[nSrc:])
|
|
||||||
if size == 1 {
|
|
||||||
// All valid runes of size 1 (those below utf8.RuneSelf) were
|
|
||||||
// handled above. We have invalid UTF-8 or we haven't seen the
|
|
||||||
// full character yet.
|
|
||||||
if !atEOF && !utf8.FullRune(src[nSrc:]) {
|
|
||||||
err = transform.ErrShortSrc
|
|
||||||
break
|
|
||||||
}
|
|
||||||
r = '\ufffd'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if nDst+utf8.RuneLen(r) > len(dst) {
|
|
||||||
err = transform.ErrShortDst
|
|
||||||
break
|
|
||||||
}
|
|
||||||
nDst += utf8.EncodeRune(dst[nDst:], r)
|
|
||||||
}
|
|
||||||
return nDst, nSrc, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTMLEscapeUnsupported wraps encoders to replace source runes outside the
|
|
||||||
// repertoire of the destination encoding with HTML escape sequences.
|
|
||||||
//
|
|
||||||
// This wrapper exists to comply to URL and HTML forms requiring a
|
|
||||||
// non-terminating legacy encoder. The produced sequences may lead to data
|
|
||||||
// loss as they are indistinguishable from legitimate input. To avoid this
|
|
||||||
// issue, use UTF-8 encodings whenever possible.
|
|
||||||
func HTMLEscapeUnsupported(e *Encoder) *Encoder {
|
|
||||||
return &Encoder{Transformer: &errorHandler{e, errorToHTML}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReplaceUnsupported wraps encoders to replace source runes outside the
|
|
||||||
// repertoire of the destination encoding with an encoding-specific
|
|
||||||
// replacement.
|
|
||||||
//
|
|
||||||
// This wrapper is only provided for backwards compatibility and legacy
|
|
||||||
// handling. Its use is strongly discouraged. Use UTF-8 whenever possible.
|
|
||||||
func ReplaceUnsupported(e *Encoder) *Encoder {
|
|
||||||
return &Encoder{Transformer: &errorHandler{e, errorToReplacement}}
|
|
||||||
}
|
|
||||||
|
|
||||||
type errorHandler struct {
|
|
||||||
*Encoder
|
|
||||||
handler func(dst []byte, r rune, err repertoireError) (n int, ok bool)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: consider making this error public in some form.
|
|
||||||
type repertoireError interface {
|
|
||||||
Replacement() byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h errorHandler) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
|
|
||||||
nDst, nSrc, err = h.Transformer.Transform(dst, src, atEOF)
|
|
||||||
for err != nil {
|
|
||||||
rerr, ok := err.(repertoireError)
|
|
||||||
if !ok {
|
|
||||||
return nDst, nSrc, err
|
|
||||||
}
|
|
||||||
r, sz := utf8.DecodeRune(src[nSrc:])
|
|
||||||
n, ok := h.handler(dst[nDst:], r, rerr)
|
|
||||||
if !ok {
|
|
||||||
return nDst, nSrc, transform.ErrShortDst
|
|
||||||
}
|
|
||||||
err = nil
|
|
||||||
nDst += n
|
|
||||||
if nSrc += sz; nSrc < len(src) {
|
|
||||||
var dn, sn int
|
|
||||||
dn, sn, err = h.Transformer.Transform(dst[nDst:], src[nSrc:], atEOF)
|
|
||||||
nDst += dn
|
|
||||||
nSrc += sn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nDst, nSrc, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func errorToHTML(dst []byte, r rune, err repertoireError) (n int, ok bool) {
|
|
||||||
buf := [8]byte{}
|
|
||||||
b := strconv.AppendUint(buf[:0], uint64(r), 10)
|
|
||||||
if n = len(b) + len("&#;"); n >= len(dst) {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
dst[0] = '&'
|
|
||||||
dst[1] = '#'
|
|
||||||
dst[copy(dst[2:], b)+2] = ';'
|
|
||||||
return n, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func errorToReplacement(dst []byte, r rune, err repertoireError) (n int, ok bool) {
|
|
||||||
if len(dst) == 0 {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
dst[0] = err.Replacement()
|
|
||||||
return 1, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrInvalidUTF8 means that a transformer encountered invalid UTF-8.
|
|
||||||
var ErrInvalidUTF8 = errors.New("encoding: invalid UTF-8")
|
|
||||||
|
|
||||||
// UTF8Validator is a transformer that returns ErrInvalidUTF8 on the first
|
|
||||||
// input byte that is not valid UTF-8.
|
|
||||||
var UTF8Validator transform.Transformer = utf8Validator{}
|
|
||||||
|
|
||||||
type utf8Validator struct{ transform.NopResetter }
|
|
||||||
|
|
||||||
func (utf8Validator) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
|
|
||||||
n := len(src)
|
|
||||||
if n > len(dst) {
|
|
||||||
n = len(dst)
|
|
||||||
}
|
|
||||||
for i := 0; i < n; {
|
|
||||||
if c := src[i]; c < utf8.RuneSelf {
|
|
||||||
dst[i] = c
|
|
||||||
i++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, size := utf8.DecodeRune(src[i:])
|
|
||||||
if size == 1 {
|
|
||||||
// All valid runes of size 1 (those below utf8.RuneSelf) were
|
|
||||||
// handled above. We have invalid UTF-8 or we haven't seen the
|
|
||||||
// full character yet.
|
|
||||||
err = ErrInvalidUTF8
|
|
||||||
if !atEOF && !utf8.FullRune(src[i:]) {
|
|
||||||
err = transform.ErrShortSrc
|
|
||||||
}
|
|
||||||
return i, i, err
|
|
||||||
}
|
|
||||||
if i+size > len(dst) {
|
|
||||||
return i, i, transform.ErrShortDst
|
|
||||||
}
|
|
||||||
for ; size > 0; size-- {
|
|
||||||
dst[i] = src[i]
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(src) > len(dst) {
|
|
||||||
err = transform.ErrShortDst
|
|
||||||
}
|
|
||||||
return n, n, err
|
|
||||||
}
|
|
||||||
173
vendor/golang.org/x/text/encoding/htmlindex/gen.go
generated
vendored
173
vendor/golang.org/x/text/encoding/htmlindex/gen.go
generated
vendored
@@ -1,173 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"golang.org/x/text/internal/gen"
|
|
||||||
)
|
|
||||||
|
|
||||||
type group struct {
|
|
||||||
Encodings []struct {
|
|
||||||
Labels []string
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
gen.Init()
|
|
||||||
|
|
||||||
r := gen.Open("https://encoding.spec.whatwg.org", "whatwg", "encodings.json")
|
|
||||||
var groups []group
|
|
||||||
if err := json.NewDecoder(r).Decode(&groups); err != nil {
|
|
||||||
log.Fatalf("Error reading encodings.json: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
w := &bytes.Buffer{}
|
|
||||||
fmt.Fprintln(w, "type htmlEncoding byte")
|
|
||||||
fmt.Fprintln(w, "const (")
|
|
||||||
for i, g := range groups {
|
|
||||||
for _, e := range g.Encodings {
|
|
||||||
key := strings.ToLower(e.Name)
|
|
||||||
name := consts[key]
|
|
||||||
if name == "" {
|
|
||||||
log.Fatalf("No const defined for %s.", key)
|
|
||||||
}
|
|
||||||
if i == 0 {
|
|
||||||
fmt.Fprintf(w, "%s htmlEncoding = iota\n", name)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(w, "%s\n", name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprintln(w, "numEncodings")
|
|
||||||
fmt.Fprint(w, ")\n\n")
|
|
||||||
|
|
||||||
fmt.Fprintln(w, "var canonical = [numEncodings]string{")
|
|
||||||
for _, g := range groups {
|
|
||||||
for _, e := range g.Encodings {
|
|
||||||
fmt.Fprintf(w, "%q,\n", strings.ToLower(e.Name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprint(w, "}\n\n")
|
|
||||||
|
|
||||||
fmt.Fprintln(w, "var nameMap = map[string]htmlEncoding{")
|
|
||||||
for _, g := range groups {
|
|
||||||
for _, e := range g.Encodings {
|
|
||||||
for _, l := range e.Labels {
|
|
||||||
key := strings.ToLower(e.Name)
|
|
||||||
name := consts[key]
|
|
||||||
fmt.Fprintf(w, "%q: %s,\n", l, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprint(w, "}\n\n")
|
|
||||||
|
|
||||||
var tags []string
|
|
||||||
fmt.Fprintln(w, "var localeMap = []htmlEncoding{")
|
|
||||||
for _, loc := range locales {
|
|
||||||
tags = append(tags, loc.tag)
|
|
||||||
fmt.Fprintf(w, "%s, // %s \n", consts[loc.name], loc.tag)
|
|
||||||
}
|
|
||||||
fmt.Fprint(w, "}\n\n")
|
|
||||||
|
|
||||||
fmt.Fprintf(w, "const locales = %q\n", strings.Join(tags, " "))
|
|
||||||
|
|
||||||
gen.WriteGoFile("tables.go", "htmlindex", w.Bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
// consts maps canonical encoding name to internal constant.
|
|
||||||
var consts = map[string]string{
|
|
||||||
"utf-8": "utf8",
|
|
||||||
"ibm866": "ibm866",
|
|
||||||
"iso-8859-2": "iso8859_2",
|
|
||||||
"iso-8859-3": "iso8859_3",
|
|
||||||
"iso-8859-4": "iso8859_4",
|
|
||||||
"iso-8859-5": "iso8859_5",
|
|
||||||
"iso-8859-6": "iso8859_6",
|
|
||||||
"iso-8859-7": "iso8859_7",
|
|
||||||
"iso-8859-8": "iso8859_8",
|
|
||||||
"iso-8859-8-i": "iso8859_8I",
|
|
||||||
"iso-8859-10": "iso8859_10",
|
|
||||||
"iso-8859-13": "iso8859_13",
|
|
||||||
"iso-8859-14": "iso8859_14",
|
|
||||||
"iso-8859-15": "iso8859_15",
|
|
||||||
"iso-8859-16": "iso8859_16",
|
|
||||||
"koi8-r": "koi8r",
|
|
||||||
"koi8-u": "koi8u",
|
|
||||||
"macintosh": "macintosh",
|
|
||||||
"windows-874": "windows874",
|
|
||||||
"windows-1250": "windows1250",
|
|
||||||
"windows-1251": "windows1251",
|
|
||||||
"windows-1252": "windows1252",
|
|
||||||
"windows-1253": "windows1253",
|
|
||||||
"windows-1254": "windows1254",
|
|
||||||
"windows-1255": "windows1255",
|
|
||||||
"windows-1256": "windows1256",
|
|
||||||
"windows-1257": "windows1257",
|
|
||||||
"windows-1258": "windows1258",
|
|
||||||
"x-mac-cyrillic": "macintoshCyrillic",
|
|
||||||
"gbk": "gbk",
|
|
||||||
"gb18030": "gb18030",
|
|
||||||
// "hz-gb-2312": "hzgb2312", // Was removed from WhatWG
|
|
||||||
"big5": "big5",
|
|
||||||
"euc-jp": "eucjp",
|
|
||||||
"iso-2022-jp": "iso2022jp",
|
|
||||||
"shift_jis": "shiftJIS",
|
|
||||||
"euc-kr": "euckr",
|
|
||||||
"replacement": "replacement",
|
|
||||||
"utf-16be": "utf16be",
|
|
||||||
"utf-16le": "utf16le",
|
|
||||||
"x-user-defined": "xUserDefined",
|
|
||||||
}
|
|
||||||
|
|
||||||
// locales is taken from
|
|
||||||
// https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm.
|
|
||||||
var locales = []struct{ tag, name string }{
|
|
||||||
// The default value. Explicitly state latin to benefit from the exact
|
|
||||||
// script option, while still making 1252 the default encoding for languages
|
|
||||||
// written in Latin script.
|
|
||||||
{"und_Latn", "windows-1252"},
|
|
||||||
{"ar", "windows-1256"},
|
|
||||||
{"ba", "windows-1251"},
|
|
||||||
{"be", "windows-1251"},
|
|
||||||
{"bg", "windows-1251"},
|
|
||||||
{"cs", "windows-1250"},
|
|
||||||
{"el", "iso-8859-7"},
|
|
||||||
{"et", "windows-1257"},
|
|
||||||
{"fa", "windows-1256"},
|
|
||||||
{"he", "windows-1255"},
|
|
||||||
{"hr", "windows-1250"},
|
|
||||||
{"hu", "iso-8859-2"},
|
|
||||||
{"ja", "shift_jis"},
|
|
||||||
{"kk", "windows-1251"},
|
|
||||||
{"ko", "euc-kr"},
|
|
||||||
{"ku", "windows-1254"},
|
|
||||||
{"ky", "windows-1251"},
|
|
||||||
{"lt", "windows-1257"},
|
|
||||||
{"lv", "windows-1257"},
|
|
||||||
{"mk", "windows-1251"},
|
|
||||||
{"pl", "iso-8859-2"},
|
|
||||||
{"ru", "windows-1251"},
|
|
||||||
{"sah", "windows-1251"},
|
|
||||||
{"sk", "windows-1250"},
|
|
||||||
{"sl", "iso-8859-2"},
|
|
||||||
{"sr", "windows-1251"},
|
|
||||||
{"tg", "windows-1251"},
|
|
||||||
{"th", "windows-874"},
|
|
||||||
{"tr", "windows-1254"},
|
|
||||||
{"tt", "windows-1251"},
|
|
||||||
{"uk", "windows-1251"},
|
|
||||||
{"vi", "windows-1258"},
|
|
||||||
{"zh-hans", "gb18030"},
|
|
||||||
{"zh-hant", "big5"},
|
|
||||||
}
|
|
||||||
86
vendor/golang.org/x/text/encoding/htmlindex/htmlindex.go
generated
vendored
86
vendor/golang.org/x/text/encoding/htmlindex/htmlindex.go
generated
vendored
@@ -1,86 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:generate go run gen.go
|
|
||||||
|
|
||||||
// Package htmlindex maps character set encoding names to Encodings as
|
|
||||||
// recommended by the W3C for use in HTML 5. See http://www.w3.org/TR/encoding.
|
|
||||||
package htmlindex
|
|
||||||
|
|
||||||
// TODO: perhaps have a "bare" version of the index (used by this package) that
|
|
||||||
// is not pre-loaded with all encodings. Global variables in encodings prevent
|
|
||||||
// the linker from being able to purge unneeded tables. This means that
|
|
||||||
// referencing all encodings, as this package does for the default index, links
|
|
||||||
// in all encodings unconditionally.
|
|
||||||
//
|
|
||||||
// This issue can be solved by either solving the linking issue (see
|
|
||||||
// https://github.com/golang/go/issues/6330) or refactoring the encoding tables
|
|
||||||
// (e.g. moving the tables to internal packages that do not use global
|
|
||||||
// variables).
|
|
||||||
|
|
||||||
// TODO: allow canonicalizing names
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"golang.org/x/text/encoding"
|
|
||||||
"golang.org/x/text/encoding/internal/identifier"
|
|
||||||
"golang.org/x/text/language"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errInvalidName = errors.New("htmlindex: invalid encoding name")
|
|
||||||
errUnknown = errors.New("htmlindex: unknown Encoding")
|
|
||||||
errUnsupported = errors.New("htmlindex: this encoding is not supported")
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
matcherOnce sync.Once
|
|
||||||
matcher language.Matcher
|
|
||||||
)
|
|
||||||
|
|
||||||
// LanguageDefault returns the canonical name of the default encoding for a
|
|
||||||
// given language.
|
|
||||||
func LanguageDefault(tag language.Tag) string {
|
|
||||||
matcherOnce.Do(func() {
|
|
||||||
tags := []language.Tag{}
|
|
||||||
for _, t := range strings.Split(locales, " ") {
|
|
||||||
tags = append(tags, language.MustParse(t))
|
|
||||||
}
|
|
||||||
matcher = language.NewMatcher(tags, language.PreferSameScript(true))
|
|
||||||
})
|
|
||||||
_, i, _ := matcher.Match(tag)
|
|
||||||
return canonical[localeMap[i]] // Default is Windows-1252.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get returns an Encoding for one of the names listed in
|
|
||||||
// http://www.w3.org/TR/encoding using the Default Index. Matching is case-
|
|
||||||
// insensitive.
|
|
||||||
func Get(name string) (encoding.Encoding, error) {
|
|
||||||
x, ok := nameMap[strings.ToLower(strings.TrimSpace(name))]
|
|
||||||
if !ok {
|
|
||||||
return nil, errInvalidName
|
|
||||||
}
|
|
||||||
return encodings[x], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name reports the canonical name of the given Encoding. It will return
|
|
||||||
// an error if e is not associated with a supported encoding scheme.
|
|
||||||
func Name(e encoding.Encoding) (string, error) {
|
|
||||||
id, ok := e.(identifier.Interface)
|
|
||||||
if !ok {
|
|
||||||
return "", errUnknown
|
|
||||||
}
|
|
||||||
mib, _ := id.ID()
|
|
||||||
if mib == 0 {
|
|
||||||
return "", errUnknown
|
|
||||||
}
|
|
||||||
v, ok := mibMap[mib]
|
|
||||||
if !ok {
|
|
||||||
return "", errUnsupported
|
|
||||||
}
|
|
||||||
return canonical[v], nil
|
|
||||||
}
|
|
||||||
105
vendor/golang.org/x/text/encoding/htmlindex/map.go
generated
vendored
105
vendor/golang.org/x/text/encoding/htmlindex/map.go
generated
vendored
@@ -1,105 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package htmlindex
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/x/text/encoding"
|
|
||||||
"golang.org/x/text/encoding/charmap"
|
|
||||||
"golang.org/x/text/encoding/internal/identifier"
|
|
||||||
"golang.org/x/text/encoding/japanese"
|
|
||||||
"golang.org/x/text/encoding/korean"
|
|
||||||
"golang.org/x/text/encoding/simplifiedchinese"
|
|
||||||
"golang.org/x/text/encoding/traditionalchinese"
|
|
||||||
"golang.org/x/text/encoding/unicode"
|
|
||||||
)
|
|
||||||
|
|
||||||
// mibMap maps a MIB identifier to an htmlEncoding index.
|
|
||||||
var mibMap = map[identifier.MIB]htmlEncoding{
|
|
||||||
identifier.UTF8: utf8,
|
|
||||||
identifier.UTF16BE: utf16be,
|
|
||||||
identifier.UTF16LE: utf16le,
|
|
||||||
identifier.IBM866: ibm866,
|
|
||||||
identifier.ISOLatin2: iso8859_2,
|
|
||||||
identifier.ISOLatin3: iso8859_3,
|
|
||||||
identifier.ISOLatin4: iso8859_4,
|
|
||||||
identifier.ISOLatinCyrillic: iso8859_5,
|
|
||||||
identifier.ISOLatinArabic: iso8859_6,
|
|
||||||
identifier.ISOLatinGreek: iso8859_7,
|
|
||||||
identifier.ISOLatinHebrew: iso8859_8,
|
|
||||||
identifier.ISO88598I: iso8859_8I,
|
|
||||||
identifier.ISOLatin6: iso8859_10,
|
|
||||||
identifier.ISO885913: iso8859_13,
|
|
||||||
identifier.ISO885914: iso8859_14,
|
|
||||||
identifier.ISO885915: iso8859_15,
|
|
||||||
identifier.ISO885916: iso8859_16,
|
|
||||||
identifier.KOI8R: koi8r,
|
|
||||||
identifier.KOI8U: koi8u,
|
|
||||||
identifier.Macintosh: macintosh,
|
|
||||||
identifier.MacintoshCyrillic: macintoshCyrillic,
|
|
||||||
identifier.Windows874: windows874,
|
|
||||||
identifier.Windows1250: windows1250,
|
|
||||||
identifier.Windows1251: windows1251,
|
|
||||||
identifier.Windows1252: windows1252,
|
|
||||||
identifier.Windows1253: windows1253,
|
|
||||||
identifier.Windows1254: windows1254,
|
|
||||||
identifier.Windows1255: windows1255,
|
|
||||||
identifier.Windows1256: windows1256,
|
|
||||||
identifier.Windows1257: windows1257,
|
|
||||||
identifier.Windows1258: windows1258,
|
|
||||||
identifier.XUserDefined: xUserDefined,
|
|
||||||
identifier.GBK: gbk,
|
|
||||||
identifier.GB18030: gb18030,
|
|
||||||
identifier.Big5: big5,
|
|
||||||
identifier.EUCPkdFmtJapanese: eucjp,
|
|
||||||
identifier.ISO2022JP: iso2022jp,
|
|
||||||
identifier.ShiftJIS: shiftJIS,
|
|
||||||
identifier.EUCKR: euckr,
|
|
||||||
identifier.Replacement: replacement,
|
|
||||||
}
|
|
||||||
|
|
||||||
// encodings maps the internal htmlEncoding to an Encoding.
|
|
||||||
// TODO: consider using a reusable index in encoding/internal.
|
|
||||||
var encodings = [numEncodings]encoding.Encoding{
|
|
||||||
utf8: unicode.UTF8,
|
|
||||||
ibm866: charmap.CodePage866,
|
|
||||||
iso8859_2: charmap.ISO8859_2,
|
|
||||||
iso8859_3: charmap.ISO8859_3,
|
|
||||||
iso8859_4: charmap.ISO8859_4,
|
|
||||||
iso8859_5: charmap.ISO8859_5,
|
|
||||||
iso8859_6: charmap.ISO8859_6,
|
|
||||||
iso8859_7: charmap.ISO8859_7,
|
|
||||||
iso8859_8: charmap.ISO8859_8,
|
|
||||||
iso8859_8I: charmap.ISO8859_8I,
|
|
||||||
iso8859_10: charmap.ISO8859_10,
|
|
||||||
iso8859_13: charmap.ISO8859_13,
|
|
||||||
iso8859_14: charmap.ISO8859_14,
|
|
||||||
iso8859_15: charmap.ISO8859_15,
|
|
||||||
iso8859_16: charmap.ISO8859_16,
|
|
||||||
koi8r: charmap.KOI8R,
|
|
||||||
koi8u: charmap.KOI8U,
|
|
||||||
macintosh: charmap.Macintosh,
|
|
||||||
windows874: charmap.Windows874,
|
|
||||||
windows1250: charmap.Windows1250,
|
|
||||||
windows1251: charmap.Windows1251,
|
|
||||||
windows1252: charmap.Windows1252,
|
|
||||||
windows1253: charmap.Windows1253,
|
|
||||||
windows1254: charmap.Windows1254,
|
|
||||||
windows1255: charmap.Windows1255,
|
|
||||||
windows1256: charmap.Windows1256,
|
|
||||||
windows1257: charmap.Windows1257,
|
|
||||||
windows1258: charmap.Windows1258,
|
|
||||||
macintoshCyrillic: charmap.MacintoshCyrillic,
|
|
||||||
gbk: simplifiedchinese.GBK,
|
|
||||||
gb18030: simplifiedchinese.GB18030,
|
|
||||||
big5: traditionalchinese.Big5,
|
|
||||||
eucjp: japanese.EUCJP,
|
|
||||||
iso2022jp: japanese.ISO2022JP,
|
|
||||||
shiftJIS: japanese.ShiftJIS,
|
|
||||||
euckr: korean.EUCKR,
|
|
||||||
replacement: encoding.Replacement,
|
|
||||||
utf16be: unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM),
|
|
||||||
utf16le: unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM),
|
|
||||||
xUserDefined: charmap.XUserDefined,
|
|
||||||
}
|
|
||||||
353
vendor/golang.org/x/text/encoding/htmlindex/tables.go
generated
vendored
353
vendor/golang.org/x/text/encoding/htmlindex/tables.go
generated
vendored
@@ -1,353 +0,0 @@
|
|||||||
// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
|
|
||||||
|
|
||||||
package htmlindex
|
|
||||||
|
|
||||||
type htmlEncoding byte
|
|
||||||
|
|
||||||
const (
|
|
||||||
utf8 htmlEncoding = iota
|
|
||||||
ibm866
|
|
||||||
iso8859_2
|
|
||||||
iso8859_3
|
|
||||||
iso8859_4
|
|
||||||
iso8859_5
|
|
||||||
iso8859_6
|
|
||||||
iso8859_7
|
|
||||||
iso8859_8
|
|
||||||
iso8859_8I
|
|
||||||
iso8859_10
|
|
||||||
iso8859_13
|
|
||||||
iso8859_14
|
|
||||||
iso8859_15
|
|
||||||
iso8859_16
|
|
||||||
koi8r
|
|
||||||
koi8u
|
|
||||||
macintosh
|
|
||||||
windows874
|
|
||||||
windows1250
|
|
||||||
windows1251
|
|
||||||
windows1252
|
|
||||||
windows1253
|
|
||||||
windows1254
|
|
||||||
windows1255
|
|
||||||
windows1256
|
|
||||||
windows1257
|
|
||||||
windows1258
|
|
||||||
macintoshCyrillic
|
|
||||||
gbk
|
|
||||||
gb18030
|
|
||||||
big5
|
|
||||||
eucjp
|
|
||||||
iso2022jp
|
|
||||||
shiftJIS
|
|
||||||
euckr
|
|
||||||
replacement
|
|
||||||
utf16be
|
|
||||||
utf16le
|
|
||||||
xUserDefined
|
|
||||||
numEncodings
|
|
||||||
)
|
|
||||||
|
|
||||||
var canonical = [numEncodings]string{
|
|
||||||
"utf-8",
|
|
||||||
"ibm866",
|
|
||||||
"iso-8859-2",
|
|
||||||
"iso-8859-3",
|
|
||||||
"iso-8859-4",
|
|
||||||
"iso-8859-5",
|
|
||||||
"iso-8859-6",
|
|
||||||
"iso-8859-7",
|
|
||||||
"iso-8859-8",
|
|
||||||
"iso-8859-8-i",
|
|
||||||
"iso-8859-10",
|
|
||||||
"iso-8859-13",
|
|
||||||
"iso-8859-14",
|
|
||||||
"iso-8859-15",
|
|
||||||
"iso-8859-16",
|
|
||||||
"koi8-r",
|
|
||||||
"koi8-u",
|
|
||||||
"macintosh",
|
|
||||||
"windows-874",
|
|
||||||
"windows-1250",
|
|
||||||
"windows-1251",
|
|
||||||
"windows-1252",
|
|
||||||
"windows-1253",
|
|
||||||
"windows-1254",
|
|
||||||
"windows-1255",
|
|
||||||
"windows-1256",
|
|
||||||
"windows-1257",
|
|
||||||
"windows-1258",
|
|
||||||
"x-mac-cyrillic",
|
|
||||||
"gbk",
|
|
||||||
"gb18030",
|
|
||||||
"big5",
|
|
||||||
"euc-jp",
|
|
||||||
"iso-2022-jp",
|
|
||||||
"shift_jis",
|
|
||||||
"euc-kr",
|
|
||||||
"replacement",
|
|
||||||
"utf-16be",
|
|
||||||
"utf-16le",
|
|
||||||
"x-user-defined",
|
|
||||||
}
|
|
||||||
|
|
||||||
var nameMap = map[string]htmlEncoding{
|
|
||||||
"unicode-1-1-utf-8": utf8,
|
|
||||||
"utf-8": utf8,
|
|
||||||
"utf8": utf8,
|
|
||||||
"866": ibm866,
|
|
||||||
"cp866": ibm866,
|
|
||||||
"csibm866": ibm866,
|
|
||||||
"ibm866": ibm866,
|
|
||||||
"csisolatin2": iso8859_2,
|
|
||||||
"iso-8859-2": iso8859_2,
|
|
||||||
"iso-ir-101": iso8859_2,
|
|
||||||
"iso8859-2": iso8859_2,
|
|
||||||
"iso88592": iso8859_2,
|
|
||||||
"iso_8859-2": iso8859_2,
|
|
||||||
"iso_8859-2:1987": iso8859_2,
|
|
||||||
"l2": iso8859_2,
|
|
||||||
"latin2": iso8859_2,
|
|
||||||
"csisolatin3": iso8859_3,
|
|
||||||
"iso-8859-3": iso8859_3,
|
|
||||||
"iso-ir-109": iso8859_3,
|
|
||||||
"iso8859-3": iso8859_3,
|
|
||||||
"iso88593": iso8859_3,
|
|
||||||
"iso_8859-3": iso8859_3,
|
|
||||||
"iso_8859-3:1988": iso8859_3,
|
|
||||||
"l3": iso8859_3,
|
|
||||||
"latin3": iso8859_3,
|
|
||||||
"csisolatin4": iso8859_4,
|
|
||||||
"iso-8859-4": iso8859_4,
|
|
||||||
"iso-ir-110": iso8859_4,
|
|
||||||
"iso8859-4": iso8859_4,
|
|
||||||
"iso88594": iso8859_4,
|
|
||||||
"iso_8859-4": iso8859_4,
|
|
||||||
"iso_8859-4:1988": iso8859_4,
|
|
||||||
"l4": iso8859_4,
|
|
||||||
"latin4": iso8859_4,
|
|
||||||
"csisolatincyrillic": iso8859_5,
|
|
||||||
"cyrillic": iso8859_5,
|
|
||||||
"iso-8859-5": iso8859_5,
|
|
||||||
"iso-ir-144": iso8859_5,
|
|
||||||
"iso8859-5": iso8859_5,
|
|
||||||
"iso88595": iso8859_5,
|
|
||||||
"iso_8859-5": iso8859_5,
|
|
||||||
"iso_8859-5:1988": iso8859_5,
|
|
||||||
"arabic": iso8859_6,
|
|
||||||
"asmo-708": iso8859_6,
|
|
||||||
"csiso88596e": iso8859_6,
|
|
||||||
"csiso88596i": iso8859_6,
|
|
||||||
"csisolatinarabic": iso8859_6,
|
|
||||||
"ecma-114": iso8859_6,
|
|
||||||
"iso-8859-6": iso8859_6,
|
|
||||||
"iso-8859-6-e": iso8859_6,
|
|
||||||
"iso-8859-6-i": iso8859_6,
|
|
||||||
"iso-ir-127": iso8859_6,
|
|
||||||
"iso8859-6": iso8859_6,
|
|
||||||
"iso88596": iso8859_6,
|
|
||||||
"iso_8859-6": iso8859_6,
|
|
||||||
"iso_8859-6:1987": iso8859_6,
|
|
||||||
"csisolatingreek": iso8859_7,
|
|
||||||
"ecma-118": iso8859_7,
|
|
||||||
"elot_928": iso8859_7,
|
|
||||||
"greek": iso8859_7,
|
|
||||||
"greek8": iso8859_7,
|
|
||||||
"iso-8859-7": iso8859_7,
|
|
||||||
"iso-ir-126": iso8859_7,
|
|
||||||
"iso8859-7": iso8859_7,
|
|
||||||
"iso88597": iso8859_7,
|
|
||||||
"iso_8859-7": iso8859_7,
|
|
||||||
"iso_8859-7:1987": iso8859_7,
|
|
||||||
"sun_eu_greek": iso8859_7,
|
|
||||||
"csiso88598e": iso8859_8,
|
|
||||||
"csisolatinhebrew": iso8859_8,
|
|
||||||
"hebrew": iso8859_8,
|
|
||||||
"iso-8859-8": iso8859_8,
|
|
||||||
"iso-8859-8-e": iso8859_8,
|
|
||||||
"iso-ir-138": iso8859_8,
|
|
||||||
"iso8859-8": iso8859_8,
|
|
||||||
"iso88598": iso8859_8,
|
|
||||||
"iso_8859-8": iso8859_8,
|
|
||||||
"iso_8859-8:1988": iso8859_8,
|
|
||||||
"visual": iso8859_8,
|
|
||||||
"csiso88598i": iso8859_8I,
|
|
||||||
"iso-8859-8-i": iso8859_8I,
|
|
||||||
"logical": iso8859_8I,
|
|
||||||
"csisolatin6": iso8859_10,
|
|
||||||
"iso-8859-10": iso8859_10,
|
|
||||||
"iso-ir-157": iso8859_10,
|
|
||||||
"iso8859-10": iso8859_10,
|
|
||||||
"iso885910": iso8859_10,
|
|
||||||
"l6": iso8859_10,
|
|
||||||
"latin6": iso8859_10,
|
|
||||||
"iso-8859-13": iso8859_13,
|
|
||||||
"iso8859-13": iso8859_13,
|
|
||||||
"iso885913": iso8859_13,
|
|
||||||
"iso-8859-14": iso8859_14,
|
|
||||||
"iso8859-14": iso8859_14,
|
|
||||||
"iso885914": iso8859_14,
|
|
||||||
"csisolatin9": iso8859_15,
|
|
||||||
"iso-8859-15": iso8859_15,
|
|
||||||
"iso8859-15": iso8859_15,
|
|
||||||
"iso885915": iso8859_15,
|
|
||||||
"iso_8859-15": iso8859_15,
|
|
||||||
"l9": iso8859_15,
|
|
||||||
"iso-8859-16": iso8859_16,
|
|
||||||
"cskoi8r": koi8r,
|
|
||||||
"koi": koi8r,
|
|
||||||
"koi8": koi8r,
|
|
||||||
"koi8-r": koi8r,
|
|
||||||
"koi8_r": koi8r,
|
|
||||||
"koi8-ru": koi8u,
|
|
||||||
"koi8-u": koi8u,
|
|
||||||
"csmacintosh": macintosh,
|
|
||||||
"mac": macintosh,
|
|
||||||
"macintosh": macintosh,
|
|
||||||
"x-mac-roman": macintosh,
|
|
||||||
"dos-874": windows874,
|
|
||||||
"iso-8859-11": windows874,
|
|
||||||
"iso8859-11": windows874,
|
|
||||||
"iso885911": windows874,
|
|
||||||
"tis-620": windows874,
|
|
||||||
"windows-874": windows874,
|
|
||||||
"cp1250": windows1250,
|
|
||||||
"windows-1250": windows1250,
|
|
||||||
"x-cp1250": windows1250,
|
|
||||||
"cp1251": windows1251,
|
|
||||||
"windows-1251": windows1251,
|
|
||||||
"x-cp1251": windows1251,
|
|
||||||
"ansi_x3.4-1968": windows1252,
|
|
||||||
"ascii": windows1252,
|
|
||||||
"cp1252": windows1252,
|
|
||||||
"cp819": windows1252,
|
|
||||||
"csisolatin1": windows1252,
|
|
||||||
"ibm819": windows1252,
|
|
||||||
"iso-8859-1": windows1252,
|
|
||||||
"iso-ir-100": windows1252,
|
|
||||||
"iso8859-1": windows1252,
|
|
||||||
"iso88591": windows1252,
|
|
||||||
"iso_8859-1": windows1252,
|
|
||||||
"iso_8859-1:1987": windows1252,
|
|
||||||
"l1": windows1252,
|
|
||||||
"latin1": windows1252,
|
|
||||||
"us-ascii": windows1252,
|
|
||||||
"windows-1252": windows1252,
|
|
||||||
"x-cp1252": windows1252,
|
|
||||||
"cp1253": windows1253,
|
|
||||||
"windows-1253": windows1253,
|
|
||||||
"x-cp1253": windows1253,
|
|
||||||
"cp1254": windows1254,
|
|
||||||
"csisolatin5": windows1254,
|
|
||||||
"iso-8859-9": windows1254,
|
|
||||||
"iso-ir-148": windows1254,
|
|
||||||
"iso8859-9": windows1254,
|
|
||||||
"iso88599": windows1254,
|
|
||||||
"iso_8859-9": windows1254,
|
|
||||||
"iso_8859-9:1989": windows1254,
|
|
||||||
"l5": windows1254,
|
|
||||||
"latin5": windows1254,
|
|
||||||
"windows-1254": windows1254,
|
|
||||||
"x-cp1254": windows1254,
|
|
||||||
"cp1255": windows1255,
|
|
||||||
"windows-1255": windows1255,
|
|
||||||
"x-cp1255": windows1255,
|
|
||||||
"cp1256": windows1256,
|
|
||||||
"windows-1256": windows1256,
|
|
||||||
"x-cp1256": windows1256,
|
|
||||||
"cp1257": windows1257,
|
|
||||||
"windows-1257": windows1257,
|
|
||||||
"x-cp1257": windows1257,
|
|
||||||
"cp1258": windows1258,
|
|
||||||
"windows-1258": windows1258,
|
|
||||||
"x-cp1258": windows1258,
|
|
||||||
"x-mac-cyrillic": macintoshCyrillic,
|
|
||||||
"x-mac-ukrainian": macintoshCyrillic,
|
|
||||||
"chinese": gbk,
|
|
||||||
"csgb2312": gbk,
|
|
||||||
"csiso58gb231280": gbk,
|
|
||||||
"gb2312": gbk,
|
|
||||||
"gb_2312": gbk,
|
|
||||||
"gb_2312-80": gbk,
|
|
||||||
"gbk": gbk,
|
|
||||||
"iso-ir-58": gbk,
|
|
||||||
"x-gbk": gbk,
|
|
||||||
"gb18030": gb18030,
|
|
||||||
"big5": big5,
|
|
||||||
"big5-hkscs": big5,
|
|
||||||
"cn-big5": big5,
|
|
||||||
"csbig5": big5,
|
|
||||||
"x-x-big5": big5,
|
|
||||||
"cseucpkdfmtjapanese": eucjp,
|
|
||||||
"euc-jp": eucjp,
|
|
||||||
"x-euc-jp": eucjp,
|
|
||||||
"csiso2022jp": iso2022jp,
|
|
||||||
"iso-2022-jp": iso2022jp,
|
|
||||||
"csshiftjis": shiftJIS,
|
|
||||||
"ms932": shiftJIS,
|
|
||||||
"ms_kanji": shiftJIS,
|
|
||||||
"shift-jis": shiftJIS,
|
|
||||||
"shift_jis": shiftJIS,
|
|
||||||
"sjis": shiftJIS,
|
|
||||||
"windows-31j": shiftJIS,
|
|
||||||
"x-sjis": shiftJIS,
|
|
||||||
"cseuckr": euckr,
|
|
||||||
"csksc56011987": euckr,
|
|
||||||
"euc-kr": euckr,
|
|
||||||
"iso-ir-149": euckr,
|
|
||||||
"korean": euckr,
|
|
||||||
"ks_c_5601-1987": euckr,
|
|
||||||
"ks_c_5601-1989": euckr,
|
|
||||||
"ksc5601": euckr,
|
|
||||||
"ksc_5601": euckr,
|
|
||||||
"windows-949": euckr,
|
|
||||||
"csiso2022kr": replacement,
|
|
||||||
"hz-gb-2312": replacement,
|
|
||||||
"iso-2022-cn": replacement,
|
|
||||||
"iso-2022-cn-ext": replacement,
|
|
||||||
"iso-2022-kr": replacement,
|
|
||||||
"replacement": replacement,
|
|
||||||
"utf-16be": utf16be,
|
|
||||||
"utf-16": utf16le,
|
|
||||||
"utf-16le": utf16le,
|
|
||||||
"x-user-defined": xUserDefined,
|
|
||||||
}
|
|
||||||
|
|
||||||
var localeMap = []htmlEncoding{
|
|
||||||
windows1252, // und_Latn
|
|
||||||
windows1256, // ar
|
|
||||||
windows1251, // ba
|
|
||||||
windows1251, // be
|
|
||||||
windows1251, // bg
|
|
||||||
windows1250, // cs
|
|
||||||
iso8859_7, // el
|
|
||||||
windows1257, // et
|
|
||||||
windows1256, // fa
|
|
||||||
windows1255, // he
|
|
||||||
windows1250, // hr
|
|
||||||
iso8859_2, // hu
|
|
||||||
shiftJIS, // ja
|
|
||||||
windows1251, // kk
|
|
||||||
euckr, // ko
|
|
||||||
windows1254, // ku
|
|
||||||
windows1251, // ky
|
|
||||||
windows1257, // lt
|
|
||||||
windows1257, // lv
|
|
||||||
windows1251, // mk
|
|
||||||
iso8859_2, // pl
|
|
||||||
windows1251, // ru
|
|
||||||
windows1251, // sah
|
|
||||||
windows1250, // sk
|
|
||||||
iso8859_2, // sl
|
|
||||||
windows1251, // sr
|
|
||||||
windows1251, // tg
|
|
||||||
windows874, // th
|
|
||||||
windows1254, // tr
|
|
||||||
windows1251, // tt
|
|
||||||
windows1251, // uk
|
|
||||||
windows1258, // vi
|
|
||||||
gb18030, // zh-hans
|
|
||||||
big5, // zh-hant
|
|
||||||
}
|
|
||||||
|
|
||||||
const locales = "und_Latn ar ba be bg cs el et fa he hr hu ja kk ko ku ky lt lv mk pl ru sah sk sl sr tg th tr tt uk vi zh-hans zh-hant"
|
|
||||||
142
vendor/golang.org/x/text/encoding/internal/identifier/gen.go
generated
vendored
142
vendor/golang.org/x/text/encoding/internal/identifier/gen.go
generated
vendored
@@ -1,142 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/xml"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"golang.org/x/text/internal/gen"
|
|
||||||
)
|
|
||||||
|
|
||||||
type registry struct {
|
|
||||||
XMLName xml.Name `xml:"registry"`
|
|
||||||
Updated string `xml:"updated"`
|
|
||||||
Registry []struct {
|
|
||||||
ID string `xml:"id,attr"`
|
|
||||||
Record []struct {
|
|
||||||
Name string `xml:"name"`
|
|
||||||
Xref []struct {
|
|
||||||
Type string `xml:"type,attr"`
|
|
||||||
Data string `xml:"data,attr"`
|
|
||||||
} `xml:"xref"`
|
|
||||||
Desc struct {
|
|
||||||
Data string `xml:",innerxml"`
|
|
||||||
// Any []struct {
|
|
||||||
// Data string `xml:",chardata"`
|
|
||||||
// } `xml:",any"`
|
|
||||||
// Data string `xml:",chardata"`
|
|
||||||
} `xml:"description,"`
|
|
||||||
MIB string `xml:"value"`
|
|
||||||
Alias []string `xml:"alias"`
|
|
||||||
MIME string `xml:"preferred_alias"`
|
|
||||||
} `xml:"record"`
|
|
||||||
} `xml:"registry"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
r := gen.OpenIANAFile("assignments/character-sets/character-sets.xml")
|
|
||||||
reg := ®istry{}
|
|
||||||
if err := xml.NewDecoder(r).Decode(®); err != nil && err != io.EOF {
|
|
||||||
log.Fatalf("Error decoding charset registry: %v", err)
|
|
||||||
}
|
|
||||||
if len(reg.Registry) == 0 || reg.Registry[0].ID != "character-sets-1" {
|
|
||||||
log.Fatalf("Unexpected ID %s", reg.Registry[0].ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
w := &bytes.Buffer{}
|
|
||||||
fmt.Fprintf(w, "const (\n")
|
|
||||||
for _, rec := range reg.Registry[0].Record {
|
|
||||||
constName := ""
|
|
||||||
for _, a := range rec.Alias {
|
|
||||||
if strings.HasPrefix(a, "cs") && strings.IndexByte(a, '-') == -1 {
|
|
||||||
// Some of the constant definitions have comments in them. Strip those.
|
|
||||||
constName = strings.Title(strings.SplitN(a[2:], "\n", 2)[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if constName == "" {
|
|
||||||
switch rec.MIB {
|
|
||||||
case "2085":
|
|
||||||
constName = "HZGB2312" // Not listed as alias for some reason.
|
|
||||||
default:
|
|
||||||
log.Fatalf("No cs alias defined for %s.", rec.MIB)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if rec.MIME != "" {
|
|
||||||
rec.MIME = fmt.Sprintf(" (MIME: %s)", rec.MIME)
|
|
||||||
}
|
|
||||||
fmt.Fprintf(w, "// %s is the MIB identifier with IANA name %s%s.\n//\n", constName, rec.Name, rec.MIME)
|
|
||||||
if len(rec.Desc.Data) > 0 {
|
|
||||||
fmt.Fprint(w, "// ")
|
|
||||||
d := xml.NewDecoder(strings.NewReader(rec.Desc.Data))
|
|
||||||
inElem := true
|
|
||||||
attr := ""
|
|
||||||
for {
|
|
||||||
t, err := d.Token()
|
|
||||||
if err != nil {
|
|
||||||
if err != io.EOF {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
switch x := t.(type) {
|
|
||||||
case xml.CharData:
|
|
||||||
attr = "" // Don't need attribute info.
|
|
||||||
a := bytes.Split([]byte(x), []byte("\n"))
|
|
||||||
for i, b := range a {
|
|
||||||
if b = bytes.TrimSpace(b); len(b) != 0 {
|
|
||||||
if !inElem && i > 0 {
|
|
||||||
fmt.Fprint(w, "\n// ")
|
|
||||||
}
|
|
||||||
inElem = false
|
|
||||||
fmt.Fprintf(w, "%s ", string(b))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case xml.StartElement:
|
|
||||||
if x.Name.Local == "xref" {
|
|
||||||
inElem = true
|
|
||||||
use := false
|
|
||||||
for _, a := range x.Attr {
|
|
||||||
if a.Name.Local == "type" {
|
|
||||||
use = use || a.Value != "person"
|
|
||||||
}
|
|
||||||
if a.Name.Local == "data" && use {
|
|
||||||
// Patch up URLs to use https. From some links, the
|
|
||||||
// https version is different from the http one.
|
|
||||||
s := a.Value
|
|
||||||
s = strings.Replace(s, "http://", "https://", -1)
|
|
||||||
s = strings.Replace(s, "/unicode/", "/", -1)
|
|
||||||
attr = s + " "
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case xml.EndElement:
|
|
||||||
inElem = false
|
|
||||||
fmt.Fprint(w, attr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprint(w, "\n")
|
|
||||||
}
|
|
||||||
for _, x := range rec.Xref {
|
|
||||||
switch x.Type {
|
|
||||||
case "rfc":
|
|
||||||
fmt.Fprintf(w, "// Reference: %s\n", strings.ToUpper(x.Data))
|
|
||||||
case "uri":
|
|
||||||
fmt.Fprintf(w, "// Reference: %s\n", x.Data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprintf(w, "%s MIB = %s\n", constName, rec.MIB)
|
|
||||||
fmt.Fprintln(w)
|
|
||||||
}
|
|
||||||
fmt.Fprintln(w, ")")
|
|
||||||
|
|
||||||
gen.WriteGoFile("mib.go", "identifier", w.Bytes())
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user