예제 #1
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy_substr_u(ss_t **s, const ss_t *src, const size_t char_off,
		      const size_t n)
{
	ASSERT_RETURN_IF(!s, ss_void);
	ASSERT_RETURN_IF(!src || !n, ss_clear(s)); /* BEHAVIOR: empty */
	if (*s == src) { /* aliasing */
		char *ps = get_str(*s);
		size_t actual_unicode_count = 0;
		const size_t ss = sd_get_size(*s);
		const size_t off = sc_unicode_count_to_utf8_size(ps, 0,
					ss, char_off, &actual_unicode_count);
		const size_t n_size = sc_unicode_count_to_utf8_size(ps,
			off, ss, n, &actual_unicode_count);
		ASSERT_RETURN_IF(off >= ss, ss_clear(s)); /* BEHAVIOR: empty */
		const size_t copy_size = S_MIN(ss - off, n_size);
		memmove(ps, ps + off, copy_size);
		set_size(*s, copy_size);
		if (n == actual_unicode_count) {
			set_unicode_size_cached(*s, S_TRUE);
			set_unicode_size(*s, n);
		} else { /* BEHAVIOR: cache lost */
			set_unicode_size_cached(*s, S_FALSE);
		}
	} else {
		if (*s)
			ss_clear(s);
		ss_cat_substr_u(s, src, char_off, n);
	}
	return ss_check(s);
}
예제 #2
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy_cn(ss_t **s, const char *src, const size_t src_size)
{
	ASSERT_RETURN_IF(!s, ss_void);
	ASSERT_RETURN_IF(!src || !src_size, ss_clear(s)); /* BEHAVIOR: empty */
	if (*s)
		ss_clear(s);
	ss_cat_cn(s, src, src_size);
	return ss_check(s);
}
예제 #3
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy(ss_t **s, const ss_t *src)
{
	ASSERT_RETURN_IF(!s, ss_void);
	RETURN_IF(*s == src && ss_check(s), *s); /* aliasing, same string */
	RETURN_IF(!src, ss_clear(s)); /* BEHAVIOR: empty */
	if (*s)
		ss_clear(s);
	return ss_cat(s, src);
}
예제 #4
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy_sub(ss_t **s, const ss_t *src, const sv_t *offs, const size_t nth)
{
	ASSERT_RETURN_IF(!s, ss_void);
	ASSERT_RETURN_IF((!src || !offs), ss_clear(s)); /* BEHAVIOR: empty */
	const size_t elems = sv_size(offs) / 2;
	ASSERT_RETURN_IF(nth >= elems, ss_clear(s)); /* BEHAVIOR: empty */
	const size_t off = (size_t)sv_u_at(offs, nth * 2);
	const size_t size = (size_t)sv_u_at(offs, nth * 2 + 1);
	return ss_cpy_substr(s, src, off, size);
}
예제 #5
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy_printf_va(ss_t **s, const size_t size, const char *fmt, va_list ap)
{
	ASSERT_RETURN_IF(!s, ss_void);
	ASSERT_RETURN_IF((!size || !fmt) && ss_clear(s), *s);
	if (*s) {
		ss_reserve(s, size);
		ss_clear(s);
	}
	return ss_cat_printf_va(s, size, fmt, ap);
}
예제 #6
0
파일: sstring.c 프로젝트: nobody1986/libsrt
static ss_t *aux_resize_u(ss_t **s, const sbool_t cat, ss_t *src,
			  const size_t u_chars, int fill_char)
{
	ASSERT_RETURN_IF(!s, ss_void);
	if (!src)
		src = ss_void;
	const size_t at = (cat && *s) ? sd_get_size(*s) : 0,
		     char_size = sc_wc_to_utf8_size(fill_char),
		     current_u_chars = ss_len_u(src);
	RETURN_IF(u_chars == current_u_chars, ss_check(s)); /* same */
	const sbool_t aliasing = *s == src;
	const size_t srcs = sd_get_size(src);
	if (current_u_chars < u_chars) { /* fill */
		const size_t new_elems = u_chars - current_u_chars,
			     at_inc = srcs + new_elems * char_size;
		SS_OVERFLOW_CHECK(s, at, at_inc);
		const size_t out_size = at + at_inc;
		if (ss_reserve(s, out_size) >= out_size) {
			if (!cat && !aliasing) /* copy */
				ss_clear(s);
			if (!aliasing) {
				memcpy(get_str(*s) + at, get_str_r(src), srcs);
				inc_unicode_size(*s, current_u_chars);
				inc_size(*s, srcs);
			}
			size_t i = 0;
			for (; i < new_elems; i++)
				ss_cat_char(s, fill_char);
		}
	} else { /* cut */
		const char *ps = get_str_r(src);
		size_t actual_unicode_count = 0;
		const size_t head_size = sc_unicode_count_to_utf8_size(
						ps, 0, srcs, u_chars,
						&actual_unicode_count);
		SS_OVERFLOW_CHECK(s, at, head_size);
		const size_t out_size = at + head_size;
		S_ASSERT(u_chars == actual_unicode_count);
		if (!aliasing) { /* copy or cat */
			if (ss_reserve(s, out_size) >= out_size) {
				if (!cat && !aliasing) /* copy */
					ss_clear(s);
				memcpy(get_str(*s) + at, ps, head_size);
				inc_unicode_size(*s, actual_unicode_count);
				inc_size(*s, head_size);
			}
		} else { /* cut */
			set_size(*s, head_size);
			set_unicode_size(*s, actual_unicode_count);
		}
	}
	return *s;
}
예제 #7
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy_printf(ss_t **s, const size_t size, const char *fmt, ...)
{
	ASSERT_RETURN_IF(!s, ss_void);
	ASSERT_RETURN_IF((!size || !fmt) && ss_clear(s), *s);
	if (*s) {
		ss_reserve(s, size);
		ss_clear(s);
	}
	va_list ap;
	va_start(ap, fmt);
	ss_cat_printf_va(s, size, fmt, ap);
	va_end(ap);
	return *s;
}
예제 #8
0
void App::button_chord(int button_nr){
	if(button_nr>=0&&button_nr<=keyshift-1) midi_play_chord(basetone+button_nr+kapodaster,radiobutton1);
	if(button_nr>=keyshift&&button_nr<=11) midi_play_chord(basetone-12+button_nr+kapodaster,radiobutton1);
	ss_clear(ss);
	ss<<"Akord: "<<get_chord(basetone+button_nr+kapodaster,radiobutton1);
	echo(ss.str());
}
예제 #9
0
파일: sstring.c 프로젝트: nobody1986/libsrt
static ss_t *aux_rtrim(ss_t **s, const sbool_t cat, const ss_t *src)
{
	ASSERT_RETURN_IF(!s, ss_void);
	if (!src)
		src = ss_void;
	const size_t ss = sd_get_size(src),
		     at = (cat && *s) ? sd_get_size(*s) : 0;
	if (ss > 0) {
		const sbool_t aliasing = *s == src;
		const char *ps = get_str_r(src);
		size_t i = ss - 1;
		for (; i > 0 && isspace(ps[i]); i--);
		if (isspace(ps[i]))
			i--;
		const size_t nspaces = ss - i - 1,
			     copy_size = ss - nspaces,
			     out_size = at + copy_size,
			     cat_usize = cat ? get_unicode_size(*s) : 0,
			     src_usize = *s ? get_unicode_size(*s) : 0;
		if (ss_reserve(s, out_size) >= out_size) {
			char *pt = get_str(*s);
			if (!aliasing)
				 memcpy(pt + at, ps, copy_size);
			set_size(*s, out_size);
			set_unicode_size(*s, cat_usize + src_usize - nspaces);
		}
	} else {
		if (cat)
			ss_check(s);
		else
			ss_clear(s);
	}
	return *s;
}
예제 #10
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy_wn(ss_t **s, const wchar_t *src, const size_t src_size)
{
	ASSERT_RETURN_IF(!s, ss_void);
	if (*s)
		ss_clear(s);
	return ss_cat_wn(s, src, src_size);
}
예제 #11
0
void ST7540_transmit(uint8_t temp){
    //Set the appropriate flags and transmit
    tx_mode();
    ss_clear();
    spi_transmit(temp);
    ss_set();
    rx_mode();
}
예제 #12
0
void App::volume_add(int add){
	volume+=add;
	if(volume<0) volume=0;
	if(volume>100) volume=100;
	ss_clear(ss);
	ss<<"G³oœnoœæ: "<<volume<<"/100";
	SetWindowText(hctrl[28],ss.str().c_str());
}
예제 #13
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy_char(ss_t **s, const int c)
{
	ASSERT_RETURN_IF(!s, ss_void);
	if (ss_reserve(s, SSU8_MAX_SIZE) >= SSU8_MAX_SIZE) {
		ss_clear(s);
		return ss_cat_char(s, c);
	}
	return *s;
}
예제 #14
0
void App::refresh_buttons12(){
	for(int i=0; i<12; i++){
		ss_clear(ss);
		ss<<get_chord(i,radiobutton1);
		if(kapodaster%12!=0){
			ss<<" ("<<get_chord(i+kapodaster,radiobutton1)<<")";
		}
		SetWindowText(hctrl[4+i],ss.str().c_str());
	}
}
예제 #15
0
파일: sstring.c 프로젝트: nobody1986/libsrt
ss_t *ss_cpy_substr(ss_t **s, const ss_t *src, const size_t off, const size_t n)
{
	ASSERT_RETURN_IF(!s, ss_void);
	ASSERT_RETURN_IF(!src || !n, ss_clear(s)); /* BEHAVIOR: empty */
	if (*s == src) { /* aliasing */
		char *ps = get_str(*s);
		const size_t ss = sd_get_size(*s);
		ASSERT_RETURN_IF(off >= ss, ss_clear(s)); /* BEHAVIOR: empty */
		const size_t copy_size = S_MIN(ss - off, n);
		memmove(ps, ps + off, copy_size);
		set_size(*s, copy_size);
		set_unicode_size_cached(*s, S_FALSE); /* BEHAVIOR: cache lost */
	} else {
		if (*s)
			ss_clear(s);
		ss_cat_substr(s, src, off, n);
	}
	return ss_check(s);
}
예제 #16
0
void ST7540_setup(){
    reg_acc();
    tx_mode();
    
    while ((PIN_SPI  &   (1<<SCK))!=0);
    
    ss_clear();
    //Send configuration bytes to ST7540 control register
    spi_transmit(0x13);
    spi_transmit(0xB2);
    spi_transmit(0x32);
    ss_set();
}
예제 #17
0
void App::capo_add(int add){
	kapodaster+=add;
	ss_clear(ss);
	ss<<"Kapodaster: ";
	if(kapodaster>0) ss<<"+";
	ss<<kapodaster;
	if(kapodaster<0){
		int kapo2 = kapodaster;
		while(kapo2<0) kapo2+=12;
		ss<<" (";
		if(kapo2>0) ss<<"+";
		ss<<kapo2<<")";
	}
	SetWindowText(hctrl[23],ss.str().c_str());
	refresh_buttons12();
}
예제 #18
0
파일: sstring.c 프로젝트: nobody1986/libsrt
static ss_t *aux_ltrim(ss_t **s, const sbool_t cat, const ss_t *src)
{
	ASSERT_RETURN_IF(!s, ss_void);
	if (!src)
		src = ss_void;
	const size_t ss = sd_get_size(src);
	if (ss > 0) {
		const sbool_t aliasing = *s == src;
		const char *ps = get_str_r(src);
		size_t i = 0;
		for (; i < ss && isspace(ps[i]); i++);
		size_t at, cat_usize;
		if (cat) {
			if (*s) {
				at = sd_get_size(*s);
				cat_usize = get_unicode_size(*s);
			} else {
				at = cat_usize = 0;
			}
		} else {
			at = cat_usize = 0;
		}
		const size_t out_size = at + ss - i,
			     src_usize = get_unicode_size(src);
		if (ss_reserve(s, out_size) >= out_size) {
			char *pt = get_str(*s);
			if (!aliasing) /* copy or cat: shift data */
				memcpy(pt + at, ps + i, ss - i);
			else
				if (i > 0) /* copy: shift data */
					memmove(pt, ps + i, ss - i);
			set_size(*s, at + ss - i);
			set_unicode_size(*s, cat_usize + src_usize - i);
		}
	} else {
		if (cat)
			ss_check(s);
		else
			ss_clear(s);
	}
	return *s;
}