Created
March 23, 2012 04:39
-
-
Save yutopp/2166853 to your computer and use it in GitHub Desktop.
ぐぬぬ
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
#import("dart:utf",prefix:"utf"); | |
class Url { | |
static String encodeUtf8( final String src ) => _encode( src, (s)=>utf.encodeUtf8(s) ); | |
static String _encode( final String rawSrc, List f(final String) ) | |
=> new String.fromCharCodes( ( final List src, List dst ) { | |
src.forEach( | |
(c) => | |
dst.addAll( | |
( ( c >= 65/*'A'*/ && c <= 90/*'Z'*/ ) || ( c >= 97/*'a'*/ && c <= 122/*'z'*/ ) || ( c >= 48/*'0'*/ && c <= 57/*'9'*/ ) || c == 45/*'-'*/ || c == 95/*'_'*/ || c == 46/*'.'*/ || c == 126/*'~'*/ ) | |
? [c] | |
: [ 37/*%*/, c.toRadixString(16).charCodes()[0], c.toRadixString(16).charCodes()[1] ] | |
) | |
); | |
return dst; | |
}( f( rawSrc ), new List() ) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment