Parse a DER/BER encoded string, and modify object in-place.
 @param [String] str
 @param [Boolean] ber accept BER encoding or not
 @return [Integer] number of parsed bytes
 @raise [ASN1Error] error on parsing
547342
def parse!(str, ber: false)
      @elements[@root].parse!(str.dup.force_encoding('BINARY'), ber: ber)
    end
724141
def parse!(buffer)
      offset = parse(buffer)
      return if offset.zero?

      buffer.slice!(0..offset - 1)
      buffer
    end
168651
function(str) {
            var o   = parseUri.options,
            m   = o.parser.exec(str),
            uri = {},
            i   = 14;

            while (i--) if (m[i]) uri[o.key[i]] = m[i];

            if (uri[o.key[12]]) {
                uri[o.q.name] = {};
                uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
                    if ($1) uri[o.q.name][$1] = $2;
                });
            }
            // member functions
            uri.toString = toString;
            uri.validate = validate;
            uri.normalize = normalize;
            uri.contains = contains;
            uri.originOnly = originOnly;
            return uri;
        }
161852
def encode_string(string)
      raise ArgumentError, "String must be present" if !string
      encode_varint(string.bytesize) + BTC::Data.ensure_binary_encoding(string)
    end
152812
def handle_json(json_str)
      begin
        req  = JSON::parse(json_str)
        resp = handle(req)
      rescue JSON::ParserError => e
        resp = err_resp({ }, -32700, "Unable to parse JSON: #{e.message}")
      end
      
      # Note the `:ascii_only` usage here. Important.
      return JSON::generate(resp, { :ascii_only=>true })
    end
96863
function decode(str) {
	// FIXME: Check for multiplication overflow
	if (str.length > 12) {
		throw new TypeError("Number encoded is too large");
	}

	var num = new UInt64();
	for (let i=0; i<str.length; i++) {
		let n = CHARS.indexOf(str[i]);
		if (n === -1) {
			throw new TypeError("Unknown character in string");
		}
		num.multiply(SIXTY_TWO);
		num.add(new UInt64(n));
	}

	var buf = new Buffer(8);
	num.div(UINT32_CAPACITY);
	buf.writeUInt32BE(parseInt(num.toString()), 0);
	buf.writeUInt32BE(num.remainder, 4);
	return buf;
}
966525
function decode(str) {
  const [hrp, data] = deserialize(str);

  if (data.length === 0 || data.length > 65)
    throw new Error('Invalid bech32 data length.');

  if (data[0] > 16)
    throw new Error('Invalid bech32 version.');

  const version = data[0];
  const output = data;
  const hash = convert(data, output, 5, 8, -1, 1);

  if (hash.length < 2 || hash.length > 40)
    throw new Error('Invalid bech32 data length.');

  return new AddrResult(hrp, version, hash);
}
1089864
def load_str(str=nil,format=nil)
      str = @data if str.nil?
      format = @format if format.nil?

      @value = {}
      case format
      when List::FORMAT_BINARY, List::FORMAT_XML, List::FORMAT_PLAIN then
        prsr = @@parsers[format-1].new
        @value = prsr.load({:data => str})

      when List::FORMAT_AUTO then # what we now do is ugly, but neccessary to recognize the file format
        filetype = str[0..5]
        version = str[6..7]

        prsr = nil

        if filetype == "bplist" then
          raise CFFormatError.new("Wrong file version #{version}") unless version == "00"
          prsr = Binary.new
          @format = List::FORMAT_BINARY
        else
          if str =~ /^<(\?xml|!DOCTYPE|plist)/
            prsr = CFPropertyList.xml_parser_interface.new
            @format = List::FORMAT_XML
          else
            prsr = PlainParser.new
            @format = List::FORMAT_PLAIN
          end
        end

        @value = prsr.load({:data => str})
      end
    end
767037
def parse_string(s):
    
    # Strings only please
    if not isinstance(s, (str, unicode)):
        raise ValueError("parse_string only accepts string inputs but a %s was given" %
                         type(s))

    # get the index of the first alphabetic character
    try:
        index = list([i.isalpha() for i in s]).index(True)
    except ValueError:
        # If there's no alphabetic characters we won't be able to .index(True)
        raise ValueError("No unit detected, can not parse string '%s' into a bitmath object" % s)

    # split the string into the value and the unit
    val, unit = s[:index], s[index:]

    # see if the unit exists as a type in our namespace

    if unit == "b":
        unit_class = Bit
    elif unit == "B":
        unit_class = Byte
    else:
        if not (hasattr(sys.modules[__name__], unit) and isinstance(getattr(sys.modules[__name__], unit), type)):
            raise ValueError("The unit %s is not a valid bitmath unit" % unit)
        unit_class = globals()[unit]

    try:
        val = float(val)
    except ValueError:
        raise
    try:
        return unit_class(val)
    except:  # pragma: no cover
        raise ValueError("Can't parse string %s into a bitmath object" % s)
1268148
public static byte[] decode(String str) throws CoderException {
	byte out[] = new byte[str.length()];
	int len = 0;
	int offset = 0;
	// int current = 0;
	byte b = 0;
	boolean stop = false;
	StringCharacterIterator it = new StringCharacterIterator(str);
	do {
	    b = _dec(it.current());
	    it.next();
	    if (b > 45) throw new CoderException("can't decode string [" + str + "]");
	    if (b < 45) stop = true;
	    len += b;
	    for (; b > 0; b -= 3) {
		decodeChars(it, out, offset);
		offset += 3;
	    }
	    it.next();
	}
	while (!stop);
	byte rtn[] = new byte[len];
	for (int i = 0; i < len; i++)
	    rtn[i] = out[i];

	return rtn;
    }
513424
function parse(str) {
  var obj = {};
  var pairs = str.split(/ *; */);
  var pair;
  if ('' == pairs[0]) return obj;
  for (var i = 0; i < pairs.length; ++i) {
    pair = pairs[i].split('=');
    obj[decode(pair[0])] = decode(pair[1]);
  }
  return obj;
}
511236
def from_str(cls, s):
        
        if not isinstance(s, str):
            raise TypeError("Expected an str instance, received %r" % (s,))
        return cls(cls.bits_from_str(s))
1237768
def call(str)
      result = [:multi]
      reset(str.split(/\r?\n/), [result])

      parse_line while next_line

      reset
      result
    end
1354906
function parse_Bes(blob) {
	var v = blob.read_shift(1), t = blob.read_shift(1);
	return t === 0x01 ? v : v === 0x01;
}
897233
def call(str)
      pos = 0
      buffers = []
      result = [:multi]
      buffers << result
      match = nil

      str.scan(ERB_EXPR) do |indicator, code, newlines|
        match = Regexp.last_match
        len  = match.begin(0) - pos

        text = str[pos, len]
        pos  = match.end(0)
        ch   = indicator ? indicator[0] : nil

        if text and !text.empty? # text
          buffers.last << [:static, text]
        end

        if ch == ?= # <%= %>
          if code =~ BLOCK_EXPR
            buffers.last << [:erb, :block, code, block = [:multi]] # picked up by our own BlockFilter.
            buffers << block
          else
            buffers.last << [:dynamic, code]
          end
        elsif ch =~ /#/ # DISCUSS: doesn't catch <% # this %>
          newlines = code.count("\n")
          buffers.last.concat  [[:newline]] * newlines if newlines > 0
        elsif code =~ /\bend\b/ # <% end %>
          buffers.pop
        elsif ch == ?@
          buffers.last << [:capture, :block, code, block = [:multi]] # picked up by our own BlockFilter. # TODO: merge with %= ?
          buffers << block
        else # <% %>
          if code =~ BLOCK_EXEC
            buffers.last << [:block, code, block = [:multi]] # picked up by Temple's ControlFlow filter.
            buffers << block
          else
            buffers.last << [:code, code]
          end
        end

        # FIXME: only adds one newline.
        # TODO: does that influence speed?
        buffers.last << [:newline] if newlines
      end

      # add text after last/none ERB tag.
      buffers.last << [:static, str[pos..str.length]] if pos < str.length

      buffers.last
    end
328521
def ensure_str(s, encoding='utf-8', errors='strict'):
    
    if not isinstance(s, (text_type, binary_type)):
        raise TypeError("not expecting type '%s'" % type(s))
    if PY2 and isinstance(s, text_type):
        s = s.encode(encoding, errors)
    elif PY3 and isinstance(s, binary_type):
        s = s.decode(encoding, errors)
    return s
64186
def encode_ber(value, ber_length=0):
    
    if not ber_length:
        if value < 127: # 1 byte case
            return bytearray([value])
        ber_length = 1
        while value >= pow(2, 8*ber_length):
            ber_length += 1
        ber_length += 1


    ber = bytearray(ber_length)
    ber[0] = 127 + ber_length #ber length byte
    for i in range(1, ber_length):
        ber[i] = (value >> (8 * (ber_length - 1 - i))) & 255
    return ber