Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: lib/src/hex/encoder.dart

Issue 1393003003: Add a percent-encoding converter. (Closed) Base URL: git@github.com:dart-lang/convert.git@master
Patch Set: Code review changes Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/hex/decoder.dart ('k') | lib/src/percent.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library convert.hex.encoder; 5 library convert.hex.encoder;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import 'package:charcode/ascii.dart'; 10 import 'package:charcode/ascii.dart';
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 buffer[bufferIndex++] = _codeUnitForDigit((byte & 0xF0) >> 4); 68 buffer[bufferIndex++] = _codeUnitForDigit((byte & 0xF0) >> 4);
69 buffer[bufferIndex++] = _codeUnitForDigit(byte & 0x0F); 69 buffer[bufferIndex++] = _codeUnitForDigit(byte & 0x0F);
70 } 70 }
71 71
72 if (byteOr >= 0 && byteOr <= 255) return new String.fromCharCodes(buffer); 72 if (byteOr >= 0 && byteOr <= 255) return new String.fromCharCodes(buffer);
73 73
74 // If there was an invalid byte, find it and throw an exception. 74 // If there was an invalid byte, find it and throw an exception.
75 for (var i = start; i < end; i++) { 75 for (var i = start; i < end; i++) {
76 var byte = bytes[i]; 76 var byte = bytes[i];
77 if (byte >= 0 && byte <= 0xff) continue; 77 if (byte >= 0 && byte <= 0xff) continue;
78 throw new FormatException("Invalid byte 0x${byte.toRadixString(16)}.", 78 throw new FormatException(
79 "Invalid byte ${byte < 0 ? "-" : ""}0x${byte.abs().toRadixString(16)}.",
79 bytes, i); 80 bytes, i);
80 } 81 }
81 82
82 throw 'unreachable'; 83 throw 'unreachable';
83 } 84 }
84 85
85 /// Returns the ASCII/Unicode code unit corresponding to the hexadecimal digit 86 /// Returns the ASCII/Unicode code unit corresponding to the hexadecimal digit
86 /// [digit]. 87 /// [digit].
87 int _codeUnitForDigit(int digit) => digit < 10 ? digit + $0 : digit + $a - 10; 88 int _codeUnitForDigit(int digit) => digit < 10 ? digit + $0 : digit + $a - 10;
OLDNEW
« no previous file with comments | « lib/src/hex/decoder.dart ('k') | lib/src/percent.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698