-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* enhancement for enums: 1. explicit enum conversion; 2. implicit integer conversion; 3. keep the type of the right operand of a shift operation; 3. parse escape characters.
- Loading branch information
Showing
8 changed files
with
731 additions
and
53 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
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 |
---|---|---|
@@ -1,3 +1,12 @@ | ||
package consts | ||
|
||
const Base = 1 | ||
|
||
const uintSize = 32 << (^uint(uintptr(0)) >> 63) | ||
const maxBase = 10 + ('z' - 'a' + 1) + ('Z' - 'A' + 1) | ||
const shlByLen = 1 << len("aaa") | ||
const hexnum = 0xFF | ||
const octnum = 017 | ||
const nonescapestr = `aa\nbb\u8888cc` | ||
const escapestr = "aa\nbb\u8888cc" | ||
const escapechar = '\u8888' |
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 |
---|---|---|
|
@@ -14,5 +14,4 @@ package main | |
|
||
// @BasePath /v2 | ||
func main() { | ||
|
||
} |
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,31 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package swag | ||
|
||
import ( | ||
"reflect" | ||
"unicode/utf8" | ||
) | ||
|
||
// AppendUtf8Rune appends the UTF-8 encoding of r to the end of p and | ||
// returns the extended buffer. If the rune is out of range, | ||
// it appends the encoding of RuneError. | ||
func AppendUtf8Rune(p []byte, r rune) []byte { | ||
return utf8.AppendRune(p, r) | ||
} | ||
|
||
// CanIntegerValue a wrapper of reflect.Value | ||
type CanIntegerValue struct { | ||
reflect.Value | ||
} | ||
|
||
// CanInt reports whether Uint can be used without panicking. | ||
func (v CanIntegerValue) CanInt() bool { | ||
return v.Value.CanInt() | ||
} | ||
|
||
// CanUint reports whether Uint can be used without panicking. | ||
func (v CanIntegerValue) CanUint() bool { | ||
return v.Value.CanUint() | ||
} |
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,47 @@ | ||
//go:build !go1.18 | ||
// +build !go1.18 | ||
|
||
package swag | ||
|
||
import ( | ||
"reflect" | ||
"unicode/utf8" | ||
) | ||
|
||
// AppendUtf8Rune appends the UTF-8 encoding of r to the end of p and | ||
// returns the extended buffer. If the rune is out of range, | ||
// it appends the encoding of RuneError. | ||
func AppendUtf8Rune(p []byte, r rune) []byte { | ||
length := utf8.RuneLen(rune(r)) | ||
if length > 0 { | ||
utf8Slice := make([]byte, length) | ||
utf8.EncodeRune(utf8Slice, rune(r)) | ||
p = append(p, utf8Slice...) | ||
} | ||
return p | ||
} | ||
|
||
// CanIntegerValue a wrapper of reflect.Value | ||
type CanIntegerValue struct { | ||
reflect.Value | ||
} | ||
|
||
// CanInt reports whether Uint can be used without panicking. | ||
func (v CanIntegerValue) CanInt() bool { | ||
switch v.Kind() { | ||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// CanUint reports whether Uint can be used without panicking. | ||
func (v CanIntegerValue) CanUint() bool { | ||
switch v.Kind() { | ||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: | ||
return true | ||
default: | ||
return false | ||
} | ||
} |