Get the display length of a unicode character.
168896
def char_width(char):
    
    if ord(char) < 128:
        return 1
    elif unicodedata.east_asian_width(char) in ('F', 'W'):
        return 2
    elif unicodedata.category(char) in ('Mn',):
        return 0
    else:
        return 1
350788
def get_margin(length):
    """"""
    if length > 23:
        margin_left = "\t"
        chars = 1
    elif length > 15:
        margin_left = "\t\t"
        chars = 2
    elif length > 7:
        margin_left = "\t\t\t"
        chars = 3
    else:
        margin_left = "\t\t\t\t"
        chars = 4
    return margin_left
18246
def read_long(self, signed=True):
        """"""
        return int.from_bytes(self.read(8), byteorder='little', signed=signed)
281748
def unicode_right(s, width):
    """"""
    i = len(s)
    j = 0
    for ch in reversed(s):
        j += __unicode_width_mapping[east_asian_width(ch)]
        if width < j:
            break
        i -= 1
    return s[i:]
153310
def get_length(self, length, trim=0, offset=0):
        
        if trim and not self.has_space(offset + length):
            return self.string[self.pos + offset:]
        elif self.has_space(offset + length):
            return self.string[self.pos + offset:self.pos + offset + length]
        else:
            return ''
1131664
def get_stats_display_width(self, curse_msg, without_option=False):
        """"""
        try:
            if without_option:
                # Size without options
                c = len(max(''.join([(u(u(nativestr(i['msg'])).encode('ascii', 'replace')) if not i['optional'] else "")
                                     for i in curse_msg['msgdict']]).split('\n'), key=len))
            else:
                # Size with all options
                c = len(max(''.join([u(u(nativestr(i['msg'])).encode('ascii', 'replace'))
                                     for i in curse_msg['msgdict']]).split('\n'), key=len))
        except Exception as e:
            logger.debug('ERROR: Can not compute plugin width ({})'.format(e))
            return 0
        else:
            return c
327770
public int getWidth(String whatchars) {
		int totalwidth = 0;
		IntObject intObject = null;
		int currentChar = 0;
		for (int i = 0; i < whatchars.length(); i++) {
			currentChar = whatchars.charAt(i);
			if (currentChar < 256) {
				intObject = charArray[currentChar];
			} else {
				intObject = (IntObject)customChars.get( new Character( (char) currentChar ) );
			}
			
			if( intObject != null )
				totalwidth += intObject.width;
		}
		return totalwidth;
	}
391320
def get_wide_unicode(self, i):
        """"""

        value = []
        for x in range(3):
            c = next(i)
            if c == '0':
                value.append(c)
            else:  # pragma: no cover
                raise SyntaxError('Invalid wide Unicode character at %d!' % (i.index - 1))

        c = next(i)
        if c in ('0', '1'):
            value.append(c)
        else:  # pragma: no cover
            raise SyntaxError('Invalid wide Unicode character at %d!' % (i.index - 1))

        for x in range(4):
            c = next(i)
            if c.lower() in _HEX:
                value.append(c)
            else:  # pragma: no cover
                raise SyntaxError('Invalid wide Unicode character at %d!' % (i.index - 1))
        return ''.join(value)
767531
def _content_length(line):
        """"""
        if line.startswith(b'Content-Length: '):
            _, value = line.split(b'Content-Length: ')
            value = value.strip()
            try:
                return int(value)
            except ValueError:
                raise ValueError("Invalid Content-Length header: {}".format(value))

        return None
417686
def get_string_length(self):
        """"""
        try:
            return self.get_array_size()
        except:
            match = re.search(r"(?<=\.)\d+", self.get_address())
            try:
                return int(match.group(0))
            except Exception as ex:
                raise Exception('Could not get string size of {0} address {1}'
                                .format(
                                    self.name,
                                    self.get_address()),
                                ex)
1205614
def get_len(self, key):
        """"""
        data = self.model.get_data()
        return len(data[key])
1221802
def hexdigest(self):
        """"""
        if not self._final:
            if self._buf_len >= self._MIN_LEN:
                self._tlsh.final()
                self._final = True
            else:
                raise ValueError("tlsh requires buffer with length >= %d "
                                 "for mode where force = %s" % \
                                 (self._MIN_LEN, False))
        return self._tlsh.hexdigest()
670795
def _get_char_x(self, charno):
        
        return charno * self.fontw + self.image_pad + self.line_number_width
456455
def get_string_width(self, s):
        ""
        s = self.normalize_text(s)
        cw=self.current_font['cw']
        w=0
        l=len(s)
        if self.unifontsubset:
            for char in s:
                char = ord(char)
                if len(cw) > char:
                    w += cw[char] # ord(cw[2*char])<<8 + ord(cw[2*char+1])
                #elif (char>0 and char<128 and isset($cw[chr($char)])) { $w += $cw[chr($char)]; }
                elif (self.current_font['desc']['MissingWidth']) :
                    w += self.current_font['desc']['MissingWidth']
                #elif (isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
                else:
                    w += 500
        else:
            for i in range(0, l):
                w += cw.get(s[i],0)
        return w*self.font_size/1000.0
190903
float width(int character) {
        if (image == null)
            return font.getWidthPoint(character, size) * hScale;
        else
            return image.getScaledWidth();
    }
809188
def strsize (b):
    """"""
    if b < 0:
        raise ValueError("Invalid negative byte number")
    if b < 1024:
        return "%dB" % b
    if b < 1024 * 10:
        return "%dKB" % (b // 1024)
    if b < 1024 * 1024:
        return "%.2fKB" % (float(b) / 1024)
    if b < 1024 * 1024 * 10:
        return "%.2fMB" % (float(b) / (1024*1024))
    if b < 1024 * 1024 * 1024:
        return "%.1fMB" % (float(b) / (1024*1024))
    if b < 1024 * 1024 * 1024 * 10:
        return "%.2fGB" % (float(b) / (1024*1024*1024))
    return "%.1fGB" % (float(b) / (1024*1024*1024))
677088
function () {
        bytes = str.substr(u, 45).split('')
        for (i in bytes) {
          bytes[i] = bytes[i].charCodeAt(0)
        }
        return bytes.length || 0
      }