enumerated-media-types: add some Android values

This commit is contained in:
Nigel Tao committed 2026-06-23 11:30:07 +10:00
1 parent e0a44a0c40
commit 15a1cbf055
2 files changed
+69 -10

No files matched your search

+63 -10
View File
@@ -15,7 +15,7 @@ package main
// base38-encode.go prints the base38 encoding of each argument.
//
// Usage: go run base38-encode.go gif json
// Usage: go run base38-encode.go gif json text/html/..
import (
"fmt"
@@ -36,23 +36,76 @@ func main1() error {
args := os.Args
if len(args) > 1 {
for _, arg := range args[1:] {
arg := (strings.ToLower(arg) + "....")[:4]
if code, ok := base38.Encode(arg); ok {
code0 := fmt.Sprintf("0x%06X", code)
code1 := fmt.Sprintf("0x%08X", code<<10)
fmt.Printf("%s code: %s %s code<<10: %s %s\n",
arg, code0, underscore(code0), code1, underscore(code1))
} else {
fmt.Printf("%s -\n", arg)
if len(arg) <= 4 {
arg := (strings.ToLower(arg) + "....")[:4]
if code, ok := base38.Encode(arg); ok {
code0 := fmt.Sprintf("0x%06X", code)
code1 := fmt.Sprintf("0x%08X", code<<10)
fmt.Printf("%s code: %s %s code<<10: %s %s\n",
arg, code0, underscore4(code0), code1, underscore4(code1))
continue
}
} else if len(arg) == 7 {
// Assume that arg is of the form "aaaa/bb".
arg0 := arg[0:4]
arg1 := ".." + arg[5:7]
c0, ok0 := base38.Encode(arg0)
c1, ok1 := base38.Encode(arg1)
if ok0 && ok1 {
c := (c0 << 11) | c1
code := fmt.Sprintf("0x%08X", c)
fmt.Printf("%s\t%10d\t%s\n", underscore4(code), c, arg)
continue
}
} else if len(arg) == 12 {
// Assume that arg is of the form "aaaa/bbbb/cc".
arg0 := arg[0:4]
arg1 := arg[5:9]
arg2 := ".." + arg[10:12]
c0, ok0 := base38.Encode(arg0)
c1, ok1 := base38.Encode(arg1)
c2, ok2 := base38.Encode(arg2)
if ok0 && ok1 && ok2 {
c := (uint64(c0) << 32) | (uint64(c1) << 11) | uint64(c2)
code := fmt.Sprintf("0x%014X", c)
fmt.Printf("%s\t%16d\t%s\n", underscore8(code), c, arg)
continue
}
} else if len(arg) == 14 {
// Assume that arg is of the form "aaaa/bbbb/cccc".
arg0 := arg[0:4]
arg1 := arg[5:9]
arg2 := arg[10:14]
c0, ok0 := base38.Encode(arg0)
c1, ok1 := base38.Encode(arg1)
c2, ok2 := base38.Encode(arg2)
if ok0 && ok1 && ok2 {
c := (uint64(c0) << 42) | (uint64(c1) << 21) | uint64(c2)
code := fmt.Sprintf("0x%016X", c)
fmt.Printf("%s\t%19d\t%s\n", underscore8(code), c, arg)
continue
}
}
fmt.Printf("%s -\n", arg)
}
}
return nil
}
func underscore(s string) string {
func underscore4(s string) string {
if n := len(s) - 4; n > 0 {
return s[:n] + "_" + s[n:]
}
return s
}
func underscore8(s string) string {
if n := len(s) - 8; n > 0 {
return s[:n] + "_" + s[n:]
}
return s
}