Return a character given its unicode code point or unicode name.
345853
def character(code_point_or_name)
      if code_point_or_name.is_a?(Symbol)
        require "erector/unicode"
        found = Erector::CHARACTERS[code_point_or_name]
        if found.nil?
          raise "Unrecognized character #{code_point_or_name}"
        end
        raw("&#x#{sprintf '%x', found};")
      elsif code_point_or_name.is_a?(Integer)
        raw("&#x#{sprintf '%x', code_point_or_name};")
      else
        raise "Unrecognized argument to character: #{code_point_or_name}"
      end
    end
805608
def replace_unicode(self, m):
        """"""

        groups = m.groupdict()
        esc = m.group(0)
        if groups.get('fesc'):
            value = m.group(0)
        elif groups.get('format'):
            value = ' '
        elif groups.get('special'):
            value = BACK_SLASH_TRANSLATION[esc]
        elif groups.get('char'):
            try:
                value = chr(int(esc[2:], 16))
            except Exception:
                value = esc
        elif groups.get('oct'):
            value = chr(int(esc[1:], 8))
        elif groups.get('name'):
            try:
                value = unicodedata.lookup(esc[3:-1])
            except Exception:
                value = esc
        return value.replace('\x00', '\n')
1265676
private static Charset getCharset(String charset)
    {
        try
        {
            return Charset.forName(charset);
        }
        catch (final UnsupportedCharsetException exception)
        {
            Verbose.exception(exception);
            return Charset.defaultCharset();
        }
    }
652960
def unicoder(p):
    
    if isinstance(p, unicode):
        return p
    if isinstance(p, str):
        return decoder(p)
    else:
        return unicode(decoder(p))
346650
public int getCharFromName(int choice, String name)
    {
        // checks for illegal arguments
        if (choice >= UCharacterNameChoice.CHAR_NAME_CHOICE_COUNT ||
            name == null || name.length() == 0) {
            return -1;
        }

        // try extended names first
        int result = getExtendedChar(name.toLowerCase(Locale.ENGLISH), choice);
        if (result >= -1) {
            return result;
        }

        String upperCaseName = name.toUpperCase(Locale.ENGLISH);
        // try algorithmic names first, if fails then try group names
        // int result = getAlgorithmChar(choice, uppercasename);

        if (choice == UCharacterNameChoice.UNICODE_CHAR_NAME ||
            choice == UCharacterNameChoice.EXTENDED_CHAR_NAME
        ) {
            int count = 0;
            if (m_algorithm_ != null) {
                count = m_algorithm_.length;
            }
            for (count --; count >= 0; count --) {
                result = m_algorithm_[count].getChar(upperCaseName);
                if (result >= 0) {
                    return result;
                }
            }
        }

        if (choice == UCharacterNameChoice.EXTENDED_CHAR_NAME) {
            result = getGroupChar(upperCaseName,
                                  UCharacterNameChoice.UNICODE_CHAR_NAME);
            if (result == -1) {
                result = getGroupChar(upperCaseName,
                                      UCharacterNameChoice.CHAR_NAME_ALIAS);
            }
        }
        else {
            result = getGroupChar(upperCaseName, choice);
        }
        return result;
    }
890975
def digit(uni_char, default_value=None):
    """"""
    uni_char = unicod(uni_char)  # Force to Unicode.
    if default_value is not None:
        return unicodedata.digit(uni_char, default_value)
    else:
        return unicodedata.digit(uni_char)
558310
def code_to_unicode(code):
    """
    def utf32chr(n):
        """utf32char for narrow build python"""
        return eval("u\'\\U%08X\'" % n)
    def lazy_unichr(n):
        try:
            return unichr(n)
        except ValueError:
            warnings.warn("Your python it built as narrow python. Make with "
                "'--enable-unicode=ucs4' configure option to build wide python")
            return utf32chr(n)
    if code and isinstance(code, basestring):
        clean_code = code.replace('>', '')
        if clean_code:
            return u''.join([lazy_unichr(int(code_char, 16)) for code_char in clean_code.split('+') if code_char])
    return None
1040921
public static char getCorrespondingSymbol(String name) {
        Character symbol = (Character) map.get(name);
        if (symbol == null) {
            return (char)0;
        }
        return symbol.charValue();
    }
385231
def unicode_char(ignored_chars=None):
        """"""
        return lambda e: e.unicode if e.type == pygame.KEYDOWN \
            and ((ignored_chars is None) 
                  or (e.unicode not in ignored_chars))\
            else EventConsumerInfo.DONT_CARE
329377
def encode_unicode_codepoints(str):
    
    """
    codepoint_format = '\\u{0:04x}'.format

    def codepoint(m):
        return codepoint_format(ord(m.group(0)))

    return re.sub('[^\x00-\x7f]', codepoint, str)
691587
private static function getCodePoint($char)
    {
        if ($char !== htmlspecialchars_decode(htmlspecialchars($char, ENT_COMPAT, 'UTF-8'))) {
            return 0xFFFD;
        }

        $x = ord($char[0]);

        if ($x < 0x80) {
            return $x;
        } elseif ($x < 0xE0) {
            $y = ord($char[1]);

            return (($x & 0x1F) << 6) | ($y & 0x3F);
        } elseif ($x < 0xF0) {
            $y = ord($char[1]);
            $z = ord($char[2]);

            return (($x & 0xF) << 12) | (($y & 0x3F) << 6) | ($z & 0x3F);
        }

        $y = ord($char[1]);
        $z = ord($char[2]);
        $w = ord($char[3]);

        return (($x & 0x7) << 18) | (($y & 0x3F) << 12) | (($z & 0x3F) << 6) | ($w & 0x3F);
    }
19849
def ensure_str(text):
    """
    if isinstance(text, unicode):
        try:
            return text.encode(pyreadline_codepage, u"replace")
        except (LookupError, TypeError):
            return text.encode(u"ascii", u"replace")
    return text
607704
def _getChar(self, char_spec):
        
        if len(char_spec) >= 4 and all(c in string.hexdigits for c in char_spec):
            char_number = int(char_spec, 16)
            if char_number not in range(0x110000):
                raise ValueError('No such character')
            return chr(char_number)
        elif len(char_spec) == 1:
            return char_spec
        else:
            raise ValueError('No such character')
204647
def evaluate_unicode(self, value):
        """"""

        if value.startswith('u8'):
            length = 1
            value = value[3:-1]
            encoding = 'utf-8'
        elif value.startswith('u'):
            length = 2
            value = value[2:-1]
            encoding = 'utf-16'
        else:
            length = 4
            value = value[2:-1]
            encoding = 'utf-32'

        def replace_unicode(m):
            """Replace Unicode."""

            groups = m.groupdict()
            esc = m.group(0)
            value = esc
            if groups.get('special'):
                # Handle basic string escapes.
                value = BACK_SLASH_TRANSLATION[esc]
            elif groups.get('char') or groups.get('oct'):
                # Handle character escapes.
                integer = int(esc[2:], 16) if groups.get('char') else int(esc[1:], 8)
                if (
                    (length < 2 and integer <= 0xFF) or
                    (length < 4 and integer <= 0xFFFF) or
                    (length >= 4 and integer <= 0x10FFFF)
                ):
                    try:
                        value = chr(integer)
                    except Exception:
                        value = ' '
            return value

        return self.norm_nl(RE_UESC.sub(replace_unicode, value).replace('\x00', '\n')), encoding
751084
def cli_char(name, tibiadata, json):
    """"""
    name = " ".join(name)
    char = _fetch_and_parse(Character.get_url, Character.from_content,
                            Character.get_url_tibiadata, Character.from_tibiadata,
                            tibiadata, name)
    if json and char:
        print(char.to_json(indent=2))
        return
    print(get_character_string(char))
317050
def name(cls):
        """"""
        if cls.__name_length__ is None:
            column_type = UnicodeText()
        else:
            column_type = Unicode(cls.__name_length__)
        if cls.__name_blank_allowed__:
            return Column(column_type, nullable=False, unique=True)
        else:
            return Column(column_type, CheckConstraint("name <> ''"), nullable=False, unique=True)
164041
def _symbol_in(self, symbol, name):
        """"""
        lsymbol = symbol.lower()
        lname = name.lower()
        return lsymbol == lname[:len(symbol)] or "_" + lsymbol in lname