forked from didi/sharingan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix gzip recorder and optimize wiki image
- Loading branch information
yufeng
committed
Apr 29, 2020
1 parent
40e4e24
commit 7d87bdc
Showing
23 changed files
with
208 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package path | ||
|
||
import ( | ||
"log" | ||
"os" | ||
) | ||
|
||
// Root current dir | ||
var Root string | ||
|
||
func init() { | ||
var err error | ||
Root, err = os.Getwd() | ||
if err != nil { | ||
log.Fatal("Initialize Root error: ", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package esmodel | ||
|
||
import ( | ||
"errors" | ||
"unicode" | ||
"unicode/utf16" | ||
"unicode/utf8" | ||
) | ||
|
||
// Unquote copy from json.unquote | ||
func Unquote(s []byte) (t string, err error) { | ||
s, ok := unquoteBytes(s) | ||
if !ok { | ||
return "", errors.New("json.unquote false") | ||
} | ||
|
||
t = string(s) | ||
return | ||
} | ||
|
||
func unquoteBytes(s []byte) (t []byte, ok bool) { | ||
if len(s) < 2 || s[0] != '"' || s[len(s)-1] != '"' { | ||
return | ||
} | ||
s = s[1 : len(s)-1] | ||
|
||
// Check for unusual characters. If there are none, | ||
// then no unquoting is needed, so return a slice of the | ||
// original bytes. | ||
r := 0 | ||
for r < len(s) { | ||
c := s[r] | ||
if c == '\\' || c == '"' || c < ' ' { | ||
break | ||
} | ||
if c < utf8.RuneSelf { | ||
r++ | ||
continue | ||
} | ||
rr, size := utf8.DecodeRune(s[r:]) | ||
if rr == utf8.RuneError && size == 1 { | ||
break | ||
} | ||
r += size | ||
} | ||
if r == len(s) { | ||
return s, true | ||
} | ||
|
||
b := make([]byte, len(s)+2*utf8.UTFMax) | ||
w := copy(b, s[0:r]) | ||
for r < len(s) { | ||
// Out of room? Can only happen if s is full of | ||
// malformed UTF-8 and we're replacing each | ||
// byte with RuneError. | ||
if w >= len(b)-2*utf8.UTFMax { | ||
nb := make([]byte, (len(b)+utf8.UTFMax)*2) | ||
copy(nb, b[0:w]) | ||
b = nb | ||
} | ||
switch c := s[r]; { | ||
case c == '\\': | ||
r++ | ||
if r >= len(s) { | ||
return | ||
} | ||
switch s[r] { | ||
default: | ||
return | ||
case '"', '\\', '/', '\'': | ||
b[w] = s[r] | ||
r++ | ||
w++ | ||
case 'b': | ||
b[w] = '\b' | ||
r++ | ||
w++ | ||
case 'f': | ||
b[w] = '\f' | ||
r++ | ||
w++ | ||
case 'n': | ||
b[w] = '\n' | ||
r++ | ||
w++ | ||
case 'r': | ||
b[w] = '\r' | ||
r++ | ||
w++ | ||
case 't': | ||
b[w] = '\t' | ||
r++ | ||
w++ | ||
case 'u': | ||
r-- | ||
rr := getu4(s[r:]) | ||
if rr < 0 { | ||
return | ||
} | ||
r += 6 | ||
if utf16.IsSurrogate(rr) { | ||
rr1 := getu4(s[r:]) | ||
if dec := utf16.DecodeRune(rr, rr1); dec != unicode.ReplacementChar { | ||
// A valid pair; consume. | ||
r += 6 | ||
w += utf8.EncodeRune(b[w:], dec) | ||
break | ||
} | ||
// Invalid surrogate; fall back to replacement rune. | ||
rr = unicode.ReplacementChar | ||
} | ||
w += utf8.EncodeRune(b[w:], rr) | ||
} | ||
|
||
// Quote, control characters are invalid. | ||
case c == '"', c < ' ': | ||
return | ||
|
||
// ASCII | ||
case c < utf8.RuneSelf: | ||
b[w] = c | ||
r++ | ||
w++ | ||
|
||
// Coerce to well-formed UTF-8. | ||
default: | ||
rr, size := utf8.DecodeRune(s[r:]) | ||
r += size | ||
w += utf8.EncodeRune(b[w:], rr) | ||
} | ||
} | ||
return b[0:w], true | ||
} | ||
|
||
func getu4(s []byte) rune { | ||
if len(s) < 6 || s[0] != '\\' || s[1] != 'u' { | ||
return -1 | ||
} | ||
var r rune | ||
for _, c := range s[2:6] { | ||
switch { | ||
case '0' <= c && c <= '9': | ||
c = c - '0' | ||
case 'a' <= c && c <= 'f': | ||
c = c - 'a' + 10 | ||
case 'A' <= c && c <= 'F': | ||
c = c - 'A' + 10 | ||
default: | ||
return -1 | ||
} | ||
r = r*16 + rune(c) | ||
} | ||
return r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package esmodel | ||
|
||
import "testing" | ||
|
||
func TestUnquote(t *testing.T) { | ||
type args struct { | ||
s []byte | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantT string | ||
}{ | ||
{"1", args{s: []byte(`"\uD925\uDFA1"`)}, ""}, | ||
{"2", args{s: []byte(`"\u4e16\u754c"`)}, "世界"}, | ||
{"3", args{s: []byte(`"abc123"`)}, "abc123"}, | ||
{"4", args{s: []byte(`""`)}, ""}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotT, _ := Unquote(tt.args.s) | ||
if gotT != tt.wantT { | ||
t.Errorf("Unquote() gotT = %v, want %v", gotT, tt.wantT) | ||
} | ||
}) | ||
} | ||
} |