def storeConvert(unic, escapeSpace=True, escapeUnicode=True):
    """
    Converts unicodes to encoded \\uxxxx and escapes
    special characters with a preceding slash

    Note: the return is unicode type if the input is.

    @param  unic            input string
    @param  escapeSpace     True for key, False for value (true is OK)
    @param  escapeUnicode   (boolean)
    @return                 processed string
    """
    outBuffer = []
    for x in range(len(unic)):
        aChar = unic[x]
        if ord(aChar) > 61 and ord(aChar) < 127:
            if aChar == '\\':
                outBuffer.append('\\\\')
                continue
            outBuffer.append(aChar)
            continue
        if aChar == ' ':
            if x == 0 or escapeSpace:
                outBuffer.append('\\')
            outBuffer.append(' ')
        elif aChar == '\t':
            outBuffer.append('\\t')
        elif aChar == '\n':
            outBuffer.append('\\n')
        elif aChar == '\r':
            outBuffer.append('\\r')
        elif aChar == '\x0c':
            outBuffer.append('\\f')
        elif aChar == '=' or aChar == ':' or aChar == '#' or aChar == '!':
            outBuffer.append('\\' + aChar)
        elif (ord(aChar) < 32 or ord(aChar) > 126) and escapeUnicode:
            outBuffer.append('\\u%04x' % ord(aChar))
        else:
            outBuffer.append(aChar)
    return ''.join(outBuffer)
