Created
April 28, 2011 16:54
-
-
Save gregworley/946746 to your computer and use it in GitHub Desktop.
From Gary Burd's Oauth.go package
This file contains hidden or 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
var noEscape = [256]bool{ | |
'A': true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, | |
'a': true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, | |
'0': true, true, true, true, true, true, true, true, true, true, | |
'-': true, | |
'.': true, | |
'_': true, | |
'~': true, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Gary Burd's oauth.go package
This is declaring an array, but why isn't it {'A':true, 'B':true,...'Z':true,...}
Thanks to Gary for explaining this. When initializing Go's composite literals
for array and slice literals the following rules apply:
Each element has an associated integer index marking its position in the array.
An element with a key uses the key as its index; the key must be a constant integer expression.
An element without a key uses the previous element's index plus one. If the first element has no key, its index is zero.
so, since the second true has no key it uses the previous element's index plus one, which in this case is 'B'. Pretty cool, and lots faster than writing everything out.