Convert Half-width (Hankaku) Katakana to Full-width (Zenkaku) Katakana

    Params:
        <unicode> text
        <unicode> ignore
    Return:
        <unicode> converted_text
978750
def h2z(text, ignore='', kana=True, ascii=False, digit=False):
    
    def _conv_dakuten(text):
        """
        半角濁点カナを全角に変換
        """
        text = text.replace(u"ｶﾞ", u"ガ").replace(u"ｷﾞ", u"ギ")
        text = text.replace(u"ｸﾞ", u"グ").replace(u"ｹﾞ", u"ゲ")
        text = text.replace(u"ｺﾞ", u"ゴ").replace(u"ｻﾞ", u"ザ")
        text = text.replace(u"ｼﾞ", u"ジ").replace(u"ｽﾞ", u"ズ")
        text = text.replace(u"ｾﾞ", u"ゼ").replace(u"ｿﾞ", u"ゾ")
        text = text.replace(u"ﾀﾞ", u"ダ").replace(u"ﾁﾞ", u"ヂ")
        text = text.replace(u"ﾂﾞ", u"ヅ").replace(u"ﾃﾞ", u"デ")
        text = text.replace(u"ﾄﾞ", u"ド").replace(u"ﾊﾞ", u"バ")
        text = text.replace(u"ﾋﾞ", u"ビ").replace(u"ﾌﾞ", u"ブ")
        text = text.replace(u"ﾍﾞ", u"ベ").replace(u"ﾎﾞ", u"ボ")
        text = text.replace(u"ﾊﾟ", u"パ").replace(u"ﾋﾟ", u"ピ")
        text = text.replace(u"ﾌﾟ", u"プ").replace(u"ﾍﾟ", u"ペ")
        return text.replace(u"ﾎﾟ", u"ポ").replace(u"ｳﾞ", u"ヴ")

    if ascii:
        if digit:
            if kana:
                h2z_map = H2Z_ALL
            else:
                h2z_map = H2Z_AD
        elif kana:
            h2z_map = H2Z_AK
        else:
            h2z_map = H2Z_A
    elif digit:
        if kana:
            h2z_map = H2Z_DK
        else:
            h2z_map = H2Z_D
    else:
        h2z_map = H2Z_K
    if kana:
        text = _conv_dakuten(text)
    if ignore:
        h2z_map = _exclude_ignorechar(ignore, h2z_map.copy())
    return _convert(text, h2z_map)
1332655
def pare(text, size, etc='...'):
    ''''''
    size = int(size)
    text = text.strip()
    if len(text)>size:
        # strip the last word or not
        to_be_stripped = not whitespace_re.findall(text[size-1:size+2])

        text = text[:size]
        if to_be_stripped:
            half = size//2
            last = None
            for mo in whitespace_re.finditer(text[half:]):
                last = mo

            if last is not None:
                text = text[:half+last.start()+1]

        return text.rstrip() + etc
    else:
        return text
904623
def _transliterate (self, text, outFormat):
        
        result = []
        text = self._preprocess(text)
        i = 0
        while i < len(text):
            if text[i].isspace(): 
                result.append(text[i])
                i = i+1
            else: 
                chr = self._getNextChar(text, i)
                try:
                    result.append(self[chr].unichr)
                except KeyError:
                    result.append(_unrecognised(chr))
                i = i + len(chr)
        return result
915416
def text_width(text):
    """"""
    (xmin, xmax, d1, d2) = get_dimension(text)
    return xmax - xmin
654206
private void refitText() {
        if (!mSizeToFit) {
            return;
        }

        if (mMaxLines <= 0) {
            // Don't auto-size since there's no limit on lines.
            return;
        }

        String text = mTextView.getText().toString();
        int targetWidth = mTextView.getWidth() - mTextView.getPaddingLeft() - mTextView.getPaddingRight();
        if (targetWidth > 0) {
            Context context = mTextView.getContext();
            Resources r = Resources.getSystem();
            DisplayMetrics displayMetrics;

            float size = mMaxTextSize;
            float high = size;
            float low = 0;

            if (context != null) {
                r = context.getResources();
            }
            displayMetrics = r.getDisplayMetrics();

            mPaint.set(mTextView.getPaint());
            mPaint.setTextSize(size);

            if ((mMaxLines == 1 && mPaint.measureText(text) > targetWidth)
                    || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) {
                size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision,
                        displayMetrics);
            }

            if (size < mMinTextSize) {
                size = mMinTextSize;
            }

            mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
        }
    }
1312669
function hiraganaToKatakana(str) {
  if (!hasKana(str)) {
    return str;
  }
  return str.split('').map(charCodeToKatakana).join('');
}
158457
def normalize_text(self, value):
        
        if self.ignore_ws:
            value = self.normalize_whitespace(value)
        if self.ignore_case:
            value = self.normalize_case(value)
        if self.unicode_normal:
            value = self.normalize_unf(value)
        return value
640630
def alphabet2kana(text):
    
    text = text.replace('kya', 'きゃ').replace('kyu', 'きゅ').replace('kyo', 'きょ')
    text = text.replace('gya', 'ぎゃ').replace('gyu', 'ぎゅ').replace('gyo', 'ぎょ')
    text = text.replace('sha', 'しゃ').replace('shu', 'しゅ').replace('sho', 'しょ')
    text = text.replace('zya', 'じゃ').replace('zyu', 'じゅ').replace('zyo', 'じょ')
    text = text.replace('zyi', 'じぃ').replace('zye', 'じぇ')
    text = text.replace('ja', 'じゃ').replace('ju', 'じゅ').replace('jo', 'じょ')
    text = text.replace('jya', 'じゃ').replace('jyu', 'じゅ').replace('jyo', 'じょ')
    text = text.replace('cha', 'ちゃ').replace('chu', 'ちゅ').replace('cho', 'ちょ')
    text = text.replace('tya', 'ちゃ').replace('tyu', 'ちゅ').replace('tyo', 'ちょ')
    text = text.replace('nya', 'にゃ').replace('nyu', 'にゅ').replace('nyo', 'にょ')
    text = text.replace('hya', 'ひゃ').replace('hyu', 'ひゅ').replace('hyo', 'ひょ')
    text = text.replace('mya', 'みゃ').replace('myu', 'みゅ').replace('myo', 'みょ')
    text = text.replace('rya', 'りゃ').replace('ryu', 'りゅ').replace('ryo', 'りょ')
    text = text.replace('bya', 'びゃ').replace('byu', 'びゅ').replace('byo', 'びょ')
    text = text.replace('pya', 'ぴゃ').replace('pyu', 'ぴゅ').replace('pyo', 'ぴょ')
    text = text.replace('oh', 'おお')
    text = text.replace('ga', 'が').replace('gi', 'ぎ').replace('gu', 'ぐ')
    text = text.replace('ge', 'げ').replace('go', 'ご').replace('za', 'ざ')
    text = text.replace('ji', 'じ').replace('zu', 'ず').replace('ze', 'ぜ')
    text = text.replace('zo', 'ぞ').replace('da', 'だ').replace('ji', 'ぢ').replace('di', 'ぢ')
    text = text.replace('va', 'ゔぁ').replace('vi', 'ゔぃ').replace('vu', 'ゔ')
    text = text.replace('ve', 'ゔぇ').replace('vo', 'ゔぉ').replace('vya', 'ゔゃ')
    text = text.replace('vyi', 'ゔぃ').replace('vyu', 'ゔゅ').replace('vye', 'ゔぇ')
    text = text.replace('vyo', 'ゔょ')
    text = text.replace('zu', 'づ').replace('de', 'で').replace('do', 'ど')
    text = text.replace('ba', 'ば').replace('bi', 'び').replace('bu', 'ぶ')
    text = text.replace('be', 'べ').replace('bo', 'ぼ').replace('pa', 'ぱ')
    text = text.replace('pi', 'ぴ').replace('pu', 'ぷ').replace('pe', 'ぺ')
    text = text.replace('po', 'ぽ').replace('dha', 'でゃ').replace('dhi', 'でぃ')
    text = text.replace('dhu', 'でゅ').replace('dhe', 'でぇ').replace('dho', 'でょ')
    text = text.replace('ka', 'か').replace('ki', 'き').replace('ku', 'く')
    text = text.replace('ke', 'け').replace('ko', 'こ').replace('sa', 'さ')
    text = text.replace('shi', 'し').replace('su', 'す').replace('se', 'せ')
    text = text.replace('so', 'そ').replace('ta', 'た').replace('chi', 'ち')
    text = text.replace('tsu', 'つ').replace('te', 'て').replace('to', 'と')
    text = text.replace('na', 'な').replace('ni', 'に').replace('nu', 'ぬ')
    text = text.replace('ne', 'ね').replace('no', 'の').replace('ha', 'は')
    text = text.replace('hi', 'ひ').replace('fu', 'ふ').replace('he', 'へ')
    text = text.replace('ho', 'ほ').replace('ma', 'ま').replace('mi', 'み')
    text = text.replace('mu', 'む').replace('me', 'め').replace('mo', 'も')
    text = text.replace('ra', 'ら').replace('ri', 'り').replace('ru', 'る')
    text = text.replace('re', 'れ').replace('ro', 'ろ')
    text = text.replace('ya', 'や').replace('yu', 'ゆ').replace('yo', 'よ')
    text = text.replace('wa', 'わ').replace('wi', 'ゐ').replace('we', 'ゑ')
    text = text.replace('wo', 'を')
    text = text.replace('nn', 'ん').replace('tu', 'つ').replace('hu', 'ふ')
    text = text.replace('fa', 'ふぁ').replace('fi', 'ふぃ').replace('fe', 'ふぇ')
    text = text.replace('fo', 'ふぉ').replace('-', 'ー')
    text = _convert(text, HEP2KANA)
    ret = []
    for (i, char) in enumerate(text):
        if char in consonants:
            char = 'っ'
        ret.append(char)
    return ''.join(ret)
977878
def _normalize_dakuten(self, chars):
        '''
        
        '''
        prev = None
        prev_n = None

        # Set all repeater characters to 0 initially,
        # then go through the list and remove them all.
        for n in range(len(chars)):
            char = chars[n]

            if char in dkt:
                chars[n] = 0
                if prev in dkt_cvs:
                    chars[prev_n] = dkt_lt[prev]

            if char in hdkt:
                chars[n] = 0
                if prev in hdkt_cvs:
                    chars[prev_n] = hdkt_lt[prev]

            prev = char
            prev_n = n

        # Remove all 0 values. There should not be any other than the ones we
        # just added. (This could use (0).__ne__, but that's Python 3 only.)
        return list(filter(lambda x: x is not 0, chars))
943733
function reporter(context) {
    let { Syntax, RuleError, report, fixer, getSource } = context;
    return {
        [Syntax.Str](node) {
            if (!isUserWrittenNode(node, context)) {
                return;
            }
            const text = getSource(node);
            // 全角同士の間は半角スペースを入れない
            const matchReg = rx`${japaneseRegExp}( )${japaneseRegExp}`;
            const katakakana = /[ァ-ヶ]( )[ァ-ヶ]/;
            matchAll(text, matchReg).forEach(match => {
                const { input, captureGroups } = match;
                // ただしカタカナ複合語の場合を除きます。
                if (katakakana.test(input)) {
                    return;
                }
                captureGroups.forEach(captureGroup => {
                    const index = captureGroup.index;
                    report(
                        node,
                        new RuleError("原則として、全角文字どうしの間にスペースを入れません。", {
                            index: index,
                            fix: fixer.replaceTextRange([index, index + 1], "")
                        })
                    );
                });
            });
        }
    };
}
975427
def _get_ckw_span(fulltext, spans):
    """"""
    _MAXIMUM_SEPARATOR_LENGTH = max(
        [len(_separator)
         for _separator in
         current_app.config["CLASSIFIER_VALID_SEPARATORS"]]
    )
    if spans[0] < spans[1]:
        words = (spans[0], spans[1])
        dist = spans[1][0] - spans[0][1]
    else:
        words = (spans[1], spans[0])
        dist = spans[0][0] - spans[1][1]

    if dist == 0:
        # Two keywords are adjacent. We have a match.
        return (min(words[0] + words[1]),
                max(words[0] + words[1]))  # FIXME: huh, this is a bug?! a sum?
    elif dist <= _MAXIMUM_SEPARATOR_LENGTH:
        separator = fulltext[words[0][1]:words[1][0] + 1]
        # Check the separator.
        if separator.strip() in current_app.config[
                "CLASSIFIER_VALID_SEPARATORS"]:
            return (min(words[0] + words[1]), max(words[0] + words[1]))

    # There is no inclusion.
    return None
407283
def word_wrap(self, text, width=1023):
        
        substrings = []

        string = text
        while len(string) > width:
            index = width - 1
            while not string[index].isspace():
                index = index - 1

            line = string[0:index]
            substrings.append(line)

            string = string[index + 1:]

        substrings.append(string)

        return substrings
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:]
623488
def _unicode(ctx, text):
    
    text = conversions.to_string(text, ctx)
    if len(text) == 0:
        raise ValueError("Text can't be empty")
    return ord(text[0])
1115168
def full_line_width(self):
        
        bar_str_len = sum([
            self._indent,
            ((len(self.title) + 1) if self._title_pos in ["left", "right"]
             else 0),  # Title if present
            len(self.start_char),
            self.max_width,  # Progress bar
            len(self.end_char),
            1,  # Space between end_char and amount_complete_str
            len(str(self.max_value)) * 2 + 1  # 100/100
        ])
        return bar_str_len
1198343
def normalize_cjk_fullwidth_ascii(seq: str) -> str:
    

    def convert(char: str) -> str:
        code_point = ord(char)
        if not 0xFF01 <= code_point <= 0xFF5E:
            return char
        return chr(code_point - 0xFEE0)

    return ''.join(map(convert, seq))
742398
function _wrapText(ctx, params) {
	var allText = String(params.text),
		// Maximum line width (optional)
		maxWidth = params.maxWidth,
		// Lines created by manual line breaks (\n)
		manualLines = allText.split('\n'),
		// All lines created manually and by wrapping
		allLines = [],
		// Other variables
		lines, line, l,
		text, words, w;

	// Loop through manually-broken lines
	for (l = 0; l < manualLines.length; l += 1) {

		text = manualLines[l];
		// Split line into list of words
		words = text.split(' ');
		lines = [];
		line = '';

		// If text is short enough initially
		// Or, if the text consists of only one word
		if (words.length === 1 || ctx.measureText(text).width < maxWidth) {

			// No need to wrap text
			lines = [text];

		} else {

			// Wrap lines
			for (w = 0; w < words.length; w += 1) {

				// Once line gets too wide, push word to next line
				if (ctx.measureText(line + words[w]).width > maxWidth) {
					// This check prevents empty lines from being created
					if (line !== '') {
						lines.push(line);
					}
					// Start new line and repeat process
					line = '';
				}
				// Add words to line until the line is too wide
				line += words[w];
				// Do not add a space after the last word
				if (w !== (words.length - 1)) {
					line += ' ';
				}
			}
			// The last word should always be pushed
			lines.push(line);

		}
		// Remove extra space at the end of each line
		allLines = allLines.concat(
			lines
			.join('\n')
			.replace(/((\n))|($)/gi, '$2')
			.split('\n')
		);

	}

	return allLines;
}