encode & decode different  romanization systems
    :param mode:
    :param string:
    :param ignore:
    :param reverse:
    :return:
165832
def transliterate(mode, string, ignore = '', reverse = False ):
    # @todo: arabtex and iso8859-6 need individual handling because in some cases using one-two mapping
    

    if mode in available_transliterate_systems():
        MAPPING = ROMANIZATION_SYSTEMS_MAPPINGS[mode]
    else:
        print(mode+"  not supported! \n")
        MAPPING = {}

    if reverse:
        mapping = {}
        for k, v in MAPPING.items():
            # reverse the mapping buckwalter <-> unicode
            mapping[v] = k
    else:
        mapping = MAPPING

    result = ""
    for char in string:
        if char in mapping.keys() and char not in ignore:
            result += mapping[char]
        else:
            result += char
    return result
1173988
def handle_decode_replace(e):
    
    count = e.end - e.start
    #return "." * count, e.end

    global ENCODING_REPLACE_CHAR
    return ENCODING_REPLACE_CHAR * count, e.end
758604
def str_lexer(mode):
    
    cast_to_const = ConstStrPool.cast_to_const

    def f_raw(inp_str, pos):
        return cast_to_const(mode) if inp_str.startswith(mode, pos) else None

    def f_collection(inp_str, pos):
        for each in mode:
            if inp_str.startswith(each, pos):
                return cast_to_const(each)
        return None

    if isinstance(mode, str):
        return f_raw

    if len(mode) is 1:
        mode = mode[0]
        return f_raw

    return f_collection
690766
def encoding(encoding=True):
    """"""
    if isinstance(encoding, str):
        encoding = True

    def dec(f):
        f._nvim_decode = encoding
        return f
    return dec
342115
def romanized(locale: str = '') -> Callable:
    
    def romanized_deco(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            try:
                # String can contain ascii symbols, digits and
                # punctuation symbols.
                alphabet = {s: s for s in
                            letters + digits + punctuation}
                alphabet.update(data.ROMANIZATION_DICT[locale])
                # Add common cyrillic letters
                alphabet.update(data.COMMON_LETTERS)
            except KeyError:
                raise UnsupportedLocale(locale)
            result = func(*args, **kwargs)
            txt = ''.join([alphabet[i] for i in result if i in alphabet])
            return txt

        return wrapper

    return romanized_deco
1156107
def replace_character_sequence_with_hyphen(string, mode: "default")
      replaceable_char =
        case mode
        when "raw"
          SLUGIFY_RAW_REGEXP
        when "pretty"
          # "._~!$&'()+,;=@" is human readable (not URI-escaped) in URL
          # and is allowed in both extN and NTFS.
          SLUGIFY_PRETTY_REGEXP
        when "ascii"
          # For web servers not being able to handle Unicode, the safe
          # method is to ditch anything else but latin letters and numeric
          # digits.
          SLUGIFY_ASCII_REGEXP
        else
          SLUGIFY_DEFAULT_REGEXP
        end

      # Strip according to the mode
      string.gsub(replaceable_char, "-")
    end
755611
def parse_modes(params, mode_types=None, prefixes=''):
    
    # we don't accept bare strings because we don't want to try to do
    #   intelligent parameter splitting
    params = list(params)

    if params[0][0] not in '+-':
        raise Exception('first param must start with + or -')

    if mode_types is None:
        mode_types = ['', '', '', '']

    mode_string = params.pop(0)
    args = params

    assembled_modes = []
    direction = mode_string[0]
    for char in mode_string:
        if char in '+-':
            direction = char
            continue

        if (char in mode_types[0] or char in mode_types[1] or char in prefixes or
                (char in mode_types[2] and direction == '+') and len(args)):
            value = args.pop(0)
        else:
            value = None

        assembled_modes.append([direction, char, value])

    return assembled_modes
64619
function decodePubModes(string) {
	var decStr, mode, i, l;
	decStr = decodeString(string);
	mode = {raw : false, merge : false,	distinct : false, command : false};

	if (decStr) {
		l = decStr.length;
		for(i = 0; i < l; i++) {
			if (decStr.charAt(i) === modeValues.RAW) {
				mode.raw = true;
			} else if (decStr.charAt(i) === modeValues.MERGE) {
				mode.merge = true;
			} else if (decStr.charAt(i) === modeValues.DISTINCT) {
				mode.distinct = true;
			} else if (decStr.charAt(i) === modeValues.COMMAND) {
				mode.command = true;
			} else {
				throw new Error('Invalid mode "' + decStr.charAt(i) + '"');
			}

		}
	}
	return mode;
}
23366
def get_mode(self, old_mode=None):
        
        if self.mode is not None:
            return self.mode
        assert self.can_write, "This format does not have a supported output mode."
        if old_mode is None:
            return self.output_modes[0]
        if old_mode in self.output_modes:
            return old_mode
        # now let's get best mode available from supported
        try:
            idx = PILLOW_MODES.index(old_mode)
        except ValueError:
            # maybe some unknown or uncommon mode
            return self.output_modes[0]
        for mode in PILLOW_MODES[idx+1:]:
            if mode in self.output_modes:
                return mode
        # since there is no better one, lets' look for closest one in opposite direction
        opposite = PILLOW_MODES[:idx]
        opposite.reverse()
        for mode in opposite:
            if mode in self.output_modes:
                return mode
206943
def _process(self, envelope, session, mode, **kwargs):
		
		if mode == WMessengerOnionCoderLayerProto.Mode.encode:
			return self.encode(envelope, session, **kwargs)
		else:  # mode == WMessengerOnionCoderLayerProto.Mode.decode
			return self.decode(envelope, session, **kwargs)
417655
def recode_unicode(s, encoding='utf-8'):
    
    if isinstance(s, str):
        return s.encode().decode(encoding)
    return s
241530
private static Mode chooseMode(String content, String encoding) {
    if ("Shift_JIS".equals(encoding) && isOnlyDoubleByteKanji(content)) {
      // Choose Kanji mode if all input are double-byte characters
      return Mode.KANJI;
    }
    boolean hasNumeric = false;
    boolean hasAlphanumeric = false;
    for (int i = 0; i < content.length(); ++i) {
      char c = content.charAt(i);
      if (c >= '0' && c <= '9') {
        hasNumeric = true;
      } else if (getAlphanumericCode(c) != -1) {
        hasAlphanumeric = true;
      } else {
        return Mode.BYTE;
      }
    }
    if (hasAlphanumeric) {
      return Mode.ALPHANUMERIC;
    }
    if (hasNumeric) {
      return Mode.NUMERIC;
    }
    return Mode.BYTE;
  }
1117032
def native_decode_source(text):
    
    if ((only_python3 and isinstance(text, bytes))
            or (only_python2 and isinstance(text, str))):
        text = decode_source_to_unicode(text)
    if only_python2:
        return text.encode('ascii', 'replace')
    return text
457180
def get_decoder(libdir=None, modeldir=None, lang='en-us'):
    
    modeldir = modeldir or (os.path.join(libdir, 'model') if libdir else MODELDIR)
    libdir = os.path.dirname(modeldir)
    config = ps.Decoder.default_config()
    config.set_string('-hmm', os.path.join(modeldir, lang))
    config.set_string('-lm', os.path.join(modeldir, lang + '.lm.bin'))
    config.set_string('-dict', os.path.join(modeldir, 'cmudict-' + lang + '.dict'))
    print(config)
    return ps.Decoder(config)
1311801
def _zs_decode(self, msg):
        """"""
        status = [_status_decode(int(x, 16)) for x in msg[4:4+Max.ZONES.value]]
        return {'zone_statuses': status}
236892
def unescape(str)
      metachars_invert_re = Regexp.new(@metachars_invert.keys.collect { |key| Regexp.escape(key) }.join('|'))
      str.gsub(metachars_invert_re) { |s| @metachars_invert[s] or raise "unknown trans char: #{s}" }
    end
649884
def _reverse(components, trans):
    

    action, parameter = _get_action(trans)
    comps = list(components)
    string = utils.join(comps)

    if action == _Action.ADD_CHAR and string[-1].lower() == parameter.lower():
        if comps[2]:
            i = 2
        elif comps[1]:
            i = 1
        else:
            i = 0
        comps[i] = comps[i][:-1]
    elif action == _Action.ADD_ACCENT:
        comps = accent.add_accent(comps, Accent.NONE)
    elif action == _Action.ADD_MARK:
        if parameter == Mark.BAR:
            comps[0] = comps[0][:-1] + \
                mark.add_mark_char(comps[0][-1:], Mark.NONE)
        else:
            if mark.is_valid_mark(comps, trans):
                comps[1] = "".join([mark.add_mark_char(c, Mark.NONE)
                                    for c in comps[1]])
    return comps