Get an ASCII string from data.
968759
def get_string_from_data(self, offset, data):
        """"""
        s = self.get_bytes_from_data(offset, data)
        end = s.find(b'\0')
        if end >= 0:
            s = s[:end]
        return s
1233823
def _get_unicode(data, force=False):
    """"""
    if isinstance(data, binary_type):
        return data.decode('utf-8')
    elif data is None:
        return ''
    elif force:
        if PY2:
            return unicode(data)
        else:
            return str(data)
    else:
        return data
987059
public static AsciiString readAsciiString(DataInput in) throws IOException {
        short len=in.readShort();
        if(len < 0)
            return null;
        AsciiString retval=new AsciiString(len);
        in.readFully(retval.chars());
        return retval;
    }
556429
def string(self, *args):
        
        data = self.bytes(*args)
        if data is not None:
            return data.rstrip(b"\x00").decode('utf-8')
670974
private static byte[] decodeInternal(byte[] data)
    {
        int tail = data.length;
        while (data[tail-1] == '=')  tail--;
        byte dest[] = new byte[tail - data.length/4];

        // ascii printable to 0-63 conversion
        for (int idx = 0; idx <data.length; idx++)
        {
            if (data[idx] == '=')    data[idx] = 0;
            else if (data[idx] == '/') data[idx] = 63;
            else if (data[idx] == '+') data[idx] = 62;
            else if (data[idx] >= '0'  &&  data[idx] <= '9')
                data[idx] = (byte)(data[idx] - ('0' - 52));
            else if (data[idx] >= 'a'  &&  data[idx] <= 'z')
                data[idx] = (byte)(data[idx] - ('a' - 26));
            else if (data[idx] >= 'A'  &&  data[idx] <= 'Z')
                data[idx] = (byte)(data[idx] - 'A');
        }

        // 4-byte to 3-byte conversion
        int sidx, didx;
        for (sidx = 0, didx=0; didx < dest.length-2; sidx += 4, didx += 3)
        {
            dest[didx]   = (byte) ( ((data[sidx] << 2) & 255) |
                    ((data[sidx+1] >>> 4) & 3) );
            dest[didx+1] = (byte) ( ((data[sidx+1] << 4) & 255) |
                    ((data[sidx+2] >>> 2) & 017) );
            dest[didx+2] = (byte) ( ((data[sidx+2] << 6) & 255) |
                    (data[sidx+3] & 077) );
        }
        if (didx < dest.length)
        {
            dest[didx]   = (byte) ( ((data[sidx] << 2) & 255) |
                    ((data[sidx+1] >>> 4) & 3) );
        }
        if (++didx < dest.length)
        {
            dest[didx]   = (byte) ( ((data[sidx+1] << 4) & 255) |
                    ((data[sidx+2] >>> 2) & 017) );
        }
        return dest;
    }
1196735
def raw_encode(data):
    """"""
    content_type = 'application/data'
    payload = data
    if isinstance(payload, unicode):
        content_encoding = 'utf-8'
        payload = payload.encode(content_encoding)
    else:
        content_encoding = 'binary'
    return content_type, content_encoding, payload
164423
def c_str(string):
    """""""
    if not isinstance(string, str):
        string = string.decode('ascii')
    return ctypes.c_char_p(string.encode('utf-8'))
150570
def encode(data, checksum=True):
    """"""

    if checksum:
        data = data + utils.hash256(data)[:4]
    v, prefix = to_long(256, lambda x: x, iter(data))
    data = from_long(v, prefix, BASE58_BASE, lambda v: BASE58_ALPHABET[v])
    return data.decode("utf8")
328431
def data_to_uuid(data):
    """"""
    string = data_to_hexstring(data)
    return string[0:8]+'-'+string[8:12]+'-'+string[12:16]+'-'+string[16:20]+'-'+string[20:32]
976033
static public byte[] getEnglishBytes(String data) {
        if (null == data) {
            return null;
        }
        char[] chars = data.toCharArray();
        byte[] bytes = new byte[chars.length];
        for (int i = 0; i < chars.length; i++) {
            bytes[i] = (byte) chars[i];
        }
        return bytes;
    }
701134
def get_string(self, offset=0):
        """"""
        if not self.has_space(offset=offset):
            return ''

        # Get a char for each char in the current string from pos onward
        #  solong as the char is not whitespace.
        string = self.string
        pos = self.pos + offset
        for i, char in enumerate(string[pos:]):
            if char.isspace():
                return string[pos:pos + i]
        else:
            return string[pos:]
243299
def _str(self, indent=""):
        """"""
        if self.ndim <= 1:
            return "[" + ", ".join(str(x) for x in self) + "]"
        elif self.ndim == 2:
            sep = ",\n" + indent
            return "[" + sep.join(x._str(indent + " ") for x in self) + "]"
        else:
            sep = ",\n\n" + indent
            return "[" + sep.join(x._str(indent + " ") for x in self) + "]"
455976
def _strify(s):
    """"""
    if s is None:
        return None
    if isinstance(s, unicode):
        return s.encode("utf-8")
    return str(s)
1092603
def _get_struct_string(self):
        """"""
        data = []
        while True:
            t = self._src.read(1)
            if t == b'\x00':
                break
            data.append(t)
        val = b''.join(data)
        return val.decode("utf8")
1105526
def ascii(text):
    
    if not isinstance(text, unicode):
        text = unicode(text)
    return unicodedata.normalize('NFKD', text).encode('ascii', 'ignore')
669035
def bytes_from_decode_data(s):
    
    if isinstance(s, (str, unicode)):
        try:
            return s.encode('ascii')
        except UnicodeEncodeError:
            raise NotValidParamError(
                'String argument should contain only ASCII characters')
    if isinstance(s, bytes_types):
        return s
    try:
        return memoryview(s).tobytes()
    except TypeError:
        raise suppress_context(
            TypeError(
                'Argument should be a bytes-like object or ASCII string, not '
                '{!r}'.format(s.__class__.__name__)))
1032934
def cast_str(s, encoding='utf8', errors='strict'):
    """"""
    if isinstance(s, bytes):
        return s.decode(encoding, errors)
    elif isinstance(s, str):
        return s
    else:
        raise TypeError("Expected unicode or bytes, got %r" % s)