Skip to content

Instantly share code, notes, and snippets.

@yutopp
Created March 23, 2012 04:39
Show Gist options
  • Save yutopp/2166853 to your computer and use it in GitHub Desktop.
Save yutopp/2166853 to your computer and use it in GitHub Desktop.
ぐぬぬ
#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