Decode a message from an IRC connection, modifying it in place.
 @param [String] string The IRC string you want to decode.
 @param [Symbol] encoding The source encoding.
 @return [String] A UTF-8 Ruby string.
765112
def decode_irc!(string, encoding = :irc)
      if encoding == :irc
        # If incoming text is valid UTF-8, it will be interpreted as
        # such. If it fails validation, a CP1252 -> UTF-8 conversion
        # is performed. This allows you to see non-ASCII from mIRC
        # users (non-UTF-8) and other users sending you UTF-8.
        #
        # (from http://xchat.org/encoding/#hybrid)
        string.force_encoding("UTF-8")
        if !string.valid_encoding?
          string.force_encoding("CP1252").encode!("UTF-8", {:invalid => :replace, :undef => :replace})
        end
      else
        string.force_encoding(encoding).encode!({:invalid => :replace, :undef => :replace})
        string = string.chars.select { |c| c.valid_encoding? }.join
      end

      return string
    end
57111
def from_irc(cls, text):
        
        from .grammars.irc import parse as parse_irc
        if isinstance(text, bytes):
            original_bytes = text
            text = text.decode('utf8')
        else:
            original_bytes = text.encode('utf8')
        instance = parse_irc(text)
        instance.original_type = 'irc'
        instance.original_bytes = original_bytes
        return instance
250398
def decode_params_utf8(params):
    
    decoded = []
    for k, v in params:
        decoded.append((
            k.decode('utf-8') if isinstance(k, bytes) else k,
            v.decode('utf-8') if isinstance(v, bytes) else v))
    return decoded
826234
def decode(data, encoding='utf-8', errors='strict'):
    
    data_type = type(data)

    if data_type == bytes:
        return bytes2unicode(data, encoding, errors)
    if data_type in (dict, list, tuple):
        if data_type == dict:
            data = data.items()
        return data_type(map(decode, data))
    return data
218956
def decode(object)
      return unless object
      
      if defined? Yajl
        begin
          Yajl::Parser.parse(object, :check_utf8 => false)
        rescue Yajl::ParseError
        end
      else
        begin
          JSON.parse(object)
        rescue JSON::ParserError
        end
      end
    end
984551
def decode(text):
    
    try:
        if text.startswith(BOM_UTF8):
            # UTF-8 with BOM
            return to_text_string(text[len(BOM_UTF8):], 'utf-8'), 'utf-8-bom'
        elif text.startswith(BOM_UTF16):
            # UTF-16 with BOM
            return to_text_string(text[len(BOM_UTF16):], 'utf-16'), 'utf-16'
        elif text.startswith(BOM_UTF32):
            # UTF-32 with BOM
            return to_text_string(text[len(BOM_UTF32):], 'utf-32'), 'utf-32'
        coding = get_coding(text)
        if coding:
            return to_text_string(text, coding), coding
    except (UnicodeError, LookupError):
        pass
    # Assume UTF-8
    try:
        return to_text_string(text, 'utf-8'), 'utf-8-guessed'
    except (UnicodeError, LookupError):
        pass
    # Assume Latin-1 (behaviour before 3.7.1)
    return to_text_string(text, "latin-1"), 'latin-1-guessed'
827086
def encode(text, orig_coding):
    
    if orig_coding == 'utf-8-bom':
        return BOM_UTF8 + text.encode("utf-8"), 'utf-8-bom'

    # Try declared coding spec
    coding = get_coding(text)
    if coding:
        try:
            return text.encode(coding), coding
        except (UnicodeError, LookupError):
            raise RuntimeError("Incorrect encoding (%s)" % coding)
    if (orig_coding and orig_coding.endswith('-default') or
       orig_coding.endswith('-guessed')):
        coding = orig_coding.replace("-default", "")
        coding = orig_coding.replace("-guessed", "")
        try:
            return text.encode(coding), coding
        except (UnicodeError, LookupError):
            pass

    # Try saving as ASCII
    try:
        return text.encode('ascii'), 'ascii'
    except UnicodeError:
        pass

    # Save as UTF-8 without BOM
    return text.encode('utf-8'), 'utf-8'
1261268
def decode(query)
      return nil if query.nil?

      params = {}
      query.split('&').each do |pair|
        next if pair.empty?

        key, value = pair.split('=', 2)
        key = unescape(key)
        value = unescape(value.tr('+', ' ')) if value
        decode_pair(key, value, params)
      end

      dehash(params, 0)
    end
461384
def decode_sent_msg(pref, message, pretty=False):
    
    newline = "\n" if pretty else " "
    indent = "    " if pretty else ""
    start = newline + indent

    out = []
    out.append("%s%s{%sSEQNUM: %d," % (pref, newline, start, message[Const.W_SEQ]))
    out.append("%sCOMPRESSION: %d," % (start, message[Const.W_COMPRESSION]))
    out.append("%sHASH: %s...," % (start, str(binascii.b2a_hex(message[Const.W_HASH]).decode('ascii'))[:10]))
    out.append("%sMESSAGE:%s{%sCLIENTREF: %s," % (start, start, start + indent,
                                                  message[Const.W_MESSAGE][Const.M_CLIENTREF]))
    out.append("%sRESOURCE: %s," % (start + indent, R_TYPES[message[Const.W_MESSAGE][Const.M_RESOURCE]]))
    out.append("%sTYPE: %s," % (start + indent, C_TYPES[message[Const.W_MESSAGE][Const.M_TYPE]]))
    out.append("%sACTION: %s," % (start + indent, message[Const.W_MESSAGE][Const.M_ACTION]))
    if Const.M_RANGE in message[Const.W_MESSAGE]:
        out.append("%sRANGE: %s," % (start + indent, message[Const.W_MESSAGE][Const.M_RANGE]))
    out.append("%sPAYLOAD: %s%s}%s}" % (start + indent, message[Const.W_MESSAGE][Const.M_PAYLOAD], start, newline))

    return ''.join(out)
649748
function decode(buffer, encoding) {
		validateEncoding(encoding);
		if (encoding === null || encoding === 'buffer') return [buffer, new Buffer(0)];
		var decoder = new StringDecoder(encoding);
		var str = decoder.write(buffer);
		var leftover = decoder.charBuffer.slice(0, decoder.charReceived);
		return [str, leftover];
	}
1212864
def decode_source(source_bytes):
    
    # source_bytes_readline = io.BytesIO(source_bytes).readline
    # encoding, _ = detect_encoding(source_bytes_readline)
    newline_decoder = io.IncrementalNewlineDecoder(None, True)
    return newline_decoder.decode(source_to_unicode(source_bytes))
496827
def content_encoding
      if content_type = headers["content-type"]
        mime_type, charset = content_type.split(SEMICOLON, 2)
        charset = charset[CHARSET_OFFSET] if charset
        charset ||= EMPTY

        if charset.empty? and mime_type.start_with?("text/")
          Encoding::UTF_8
        elsif charset.empty?
          Encoding::BINARY
        else
          ENCODINGS[charset] or raise StompParser::InvalidEncodingError, "invalid encoding #{charset.inspect}"
        end
      else
        Encoding::BINARY
      end
    end
349568
def decode(s)
    ts = lex(s)
    v, ts = textparse(ts)
    if ts.length > 0
      raise Error, 'trailing garbage'
    end
    v
  end
794870
def _decode(value):
        
        if value.isdigit():
            return int(value)
        if isinstance(value, bytes):
            return value.decode('utf-8')
        else:
            return value
295021
def to_utf8
            detect_encoding

            utf16 = self.encoding.to_utf16be(self.value)
            utf16.slice!(0, Encoding::UTF16BE::BOM.size)

            utf16.encode("utf-8", "utf-16be")
        end
1331515
public static String decodeString(String encoded,int offset,int length,String charset)
    {
        if (charset==null)
            charset=StringUtil.__ISO_8859_1;
        byte[] bytes=null;
        int n=0;
        
        for (int i=0;i<length;i++)
        {
            char c = encoded.charAt(offset+i);
            if (c<0||c>0xff)
                throw new IllegalArgumentException("Not encoded");
            
            if (c=='+')
            {
                if (bytes==null)
                {
                    bytes=new byte[length*2];
                    encoded.getBytes(offset, offset+i, bytes, 0);
                    n=i;
                }
                bytes[n++] = (byte) ' ';
            }
            else if (c=='%' && (i+2)<length)
            {
                byte b;
                char cn = encoded.charAt(offset+i+1);
                if (cn>='a' && cn<='z')
                    b=(byte)(10+cn-'a');
                else if (cn>='A' && cn<='Z')
                    b=(byte)(10+cn-'A');
                else
                    b=(byte)(cn-'0');
                cn = encoded.charAt(offset+i+2);
                if (cn>='a' && cn<='z')
                    b=(byte)(b*16+10+cn-'a');
                else if (cn>='A' && cn<='Z')
                    b=(byte)(b*16+10+cn-'A');
                else
                    b=(byte)(b*16+cn-'0');

                if (bytes==null)
                {
                    bytes=new byte[length*2];
                    encoded.getBytes(offset, offset+i, bytes, 0);
                    n=i;
                }
                i+=2;
                bytes[n++]=b;
            }
            else if (n>0)
                bytes[n++] = (byte) c;
        }

        if (bytes==null)
        {
            if (offset==0 && encoded.length()==length)
                return encoded;
            return encoded.substring(offset,offset+length);
        }
        
        try
        {
            return new String(bytes,0,n,charset);
        }
        catch (UnsupportedEncodingException e)
        {
            return new String(bytes,0,n);
        }
        
    }
801398
def try_utf8_decode(value):
    
    if not value or not is_string(value):
        return value
    elif PYTHON3 and not isinstance(value, bytes):
        return value
    elif not PYTHON3 and not isinstance(value, unicode):
        return value

    try:
        return value.decode('utf-8')
    except UnicodeDecodeError:
        pass

    return value