コード例 #1
0
ファイル: command.c プロジェクト: hughbarney/femto
void right()
{
	int n = utf8_size(*ptr(curbp,curbp->b_point));

	while ((curbp->b_point < pos(curbp, curbp->b_ebuf)) && n-- > 0)
		++curbp->b_point;
}
コード例 #2
0
ファイル: utf8.hpp プロジェクト: hitochan777/cicada
  inline
  int utf8_code(Buf buf)
  {
    typedef unsigned int code_type;
    
    switch (utf8_size(*buf)) {
    case 1: return *buf;
    case 2: return ((code_type(*buf & 0x1F) << 6)
		    | (code_type(*(buf + 1) & 0x3F)));
    case 3: return ((code_type(*buf & 0x0F) << 12)
		    | (code_type(*(buf + 1) & 0x3F) <<  6)
		    | (code_type(*(buf + 2) & 0x3F)));
    case 4: return ((code_type(*buf & 0x07) << 18)
		    | (code_type(*(buf + 1) & 0x3F) << 12)
		    | (code_type(*(buf + 2) & 0x3F) << 6)
		    | (code_type(*(buf + 3) & 0x3F)));
    case 5: return ((code_type(*buf & 0x03) << 24)
		    | (code_type(*(buf + 1) & 0x3F) << 18)
		    | (code_type(*(buf + 2) & 0x3F) << 12)
		    | (code_type(*(buf + 3) & 0x3F) << 6)
		    | (code_type(*(buf + 4) & 0x3F)));
    case 6: return ((code_type(*buf & 0x01) << 30)
		    | (code_type(*(buf + 1) & 0x3F) << 24)
		    | (code_type(*(buf + 2) & 0x3F) << 18)
		    | (code_type(*(buf + 3) & 0x3F) << 12)
		    | (code_type(*(buf + 4) & 0x3F) << 6)
		    | (code_type(*(buf + 5) & 0x3F)));
    default:
      throw std::runtime_error("invlaid utf-8");
    }
  }
コード例 #3
0
ファイル: utf8_strlen.c プロジェクト: SirCmpwn/aerc
size_t utf8_strlen(const char *str) {
	size_t len = 0;
	while (*str) {
		++len;
		str += utf8_size(str);
	}
	return len;
}
コード例 #4
0
ファイル: command.c プロジェクト: hughbarney/femto
int prev_utf8_char_size()
{
	int n;
	for (n=2;n<5;n++)
		if (-1 < curbp->b_point - n && (utf8_size(*(ptr(curbp, curbp->b_point - n))) == n))
			return n;
	return 1;
}
コード例 #5
0
/*
    Get the memory position of a codepoint according
    to its position in the utf-8 string
*/
size_t UTF8string::utf8_bpos_at_( const size_t cpos ) const noexcept
{
    size_t bpos = 0;
    const size_t U8SIZE = utf8_size();

    for ( size_t i = 0; bpos < U8SIZE && i < cpos; i++ )
    {
        bpos += utf8_codepoint_len_( bpos );
    }
    return bpos;
}
コード例 #6
0
ファイル: luatoken.c プロジェクト: live-clones/luatex
int tokenlist_from_lua(lua_State * L)
{
    const char *s;
    int tok, t;
    size_t i, j;
    halfword p, q, r;
    r = get_avail();
    token_info(r) = 0;
    token_link(r) = null;
    p = r;
    t = lua_type(L, -1);
    if (t == LUA_TTABLE) {
        j = lua_rawlen(L, -1);
        if (j > 0) {
            for (i = 1; i <= j; i++) {
                lua_rawgeti(L, -1, (int) i);
                tok = token_from_lua(L);
                if (tok >= 0) {
                    store_new_token(tok);
                }
                lua_pop(L, 1);
            };
        }
        return r;
    } else if (t == LUA_TSTRING) {
        s = lua_tolstring(L, -1, &j);
        for (i = 0; i < j; i++) {
            if (s[i] == 32) {
                tok = token_val(10, s[i]);
            } else {
                int j1 = (int) str2uni((const unsigned char *) (s + i));
                i = i + (size_t) (utf8_size(j1) - 1);
                tok = token_val(12, j1);
            }
            store_new_token(tok);
        }
        return r;
    } else {
        free_avail(r);
        return null;
    }
}
コード例 #7
0
ファイル: command.c プロジェクト: hughbarney/femto
		the_char[n] = '\0'; /* null terminate, the backspaced char(s) */
		curbp->b_point = pos(curbp, curbp->b_egap);
		//debug("point after bs = %ld\n", curbp->b_point);
		add_undo(curbp, UNDO_T_BACKSPACE, curbp->b_point, the_char, NULL);
	}

	curbp->b_point = pos(curbp, curbp->b_egap);
}

void delete()
{
	char_t the_char[7]; /* the deleted char, allow 6 unsigned chars plus a null */
	int n;

	curbp->b_point = movegap(curbp, curbp->b_point);
	n = utf8_size(*(ptr(curbp, curbp->b_point)));

	if (curbp->b_egap < curbp->b_ebuf) {
		/* record the deleted chars in the undo structure */
		memcpy(the_char, curbp->b_egap, n);
		the_char[n] = '\0'; /* null terminate, the deleted char(s) */
		//debug("deleted = '%s'\n", the_char);
		curbp->b_egap += n;
		curbp->b_point = pos(curbp, curbp->b_egap);
		add_mode(curbp, B_MODIFIED);
		add_undo(curbp, UNDO_T_DELETE, curbp->b_point, the_char, NULL);
	}
}

void i_gotoline()
{
コード例 #8
0
ファイル: utf8.hpp プロジェクト: GavinHwa/oh
 inline size_t utf8_size(const std::basic_string<Element, Traits, Allocator> & data)
 {
     HPROSE_STATIC_ASSERT((sizeof(Element) == 2) || (sizeof(Element) == 4), "Require Unicode String");
     return utf8_size(data.begin(), data.end(), UTFType<sizeof(Element)>());
 }