Spec-Zone.ru › Dart 1

dart:core

Метод contentAsBytes

List<int> contentAsBytes()

Часть содержимого URI данных в виде байтов.

Если данные закодированы в Base64, они будут декодированы в байты.

Если данные не закодированы в Base64, они будут декодированы путём разбора символов, закодированных в процентах, и возврата байтовых значений каждого разыменованного символа. Байты не будут, например, декодированы в UTF-8.

Исходный код

List<int> contentAsBytes() {
  String text = _text;
  int start = _separatorIndices.last + 1;
  if (isBase64) {
    return BASE64.decoder.convert(text, start);
  }

  // Not base64, do percent-decoding and return the remaining bytes.
  // Compute result size.
  const int percent = 0x25;
  int length = text.length - start;
  for (int i = start; i < text.length; i++) {
    var codeUnit = text.codeUnitAt(i);
    if (codeUnit == percent) {
      i += 2;
      length -= 2;
    }
  }
  // Fill result array.
  Uint8List result = new Uint8List(length);
  if (length == text.length) {
    result.setRange(0, length, text.codeUnits, start);
    return result;
  }
  int index = 0;
  for (int i = start; i < text.length; i++) {
    var codeUnit = text.codeUnitAt(i);
    if (codeUnit != percent) {
      result[index++] = codeUnit;
    } else {
      if (i + 2 < text.length) {
        int byte = parseHexByte(text, i + 1);
        if (byte >= 0) {
          result[index++] = byte;
          i += 2;
          continue;
        }
      }
      throw new FormatException("Invalid percent escape", text, i);
    }
  }
  assert(index == result.length);
  return result;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-core/UriData/contentAsBytes.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API