Example #1
0
/*
 * Skip fields according to specs
 */
static size_t
skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field)
{

	if (fields < 2) {
		if (BWSLEN(s) == 0)
			*empty_field = true;
		return (0);
	} else if (!(sort_opts_vals.tflag)) {
		size_t cpos = 0;
		bool pb = true;

		while (cpos < BWSLEN(s)) {
			bool isblank;

			isblank = iswblank(BWS_GET(s, cpos));

			if (isblank && !pb) {
				--fields;
				if (fields <= 1)
					return (cpos);
			}
			pb = isblank;
			++cpos;
		}
		if (fields > 1)
			*empty_field = true;
		return (cpos);
	} else {
		size_t cpos = 0;

		while (cpos < BWSLEN(s)) {
			if (BWS_GET(s,cpos) == (wchar_t)sort_opts_vals.field_sep) {
				--fields;
				if (fields <= 1)
					return (cpos + 1);
			}
			++cpos;
		}
		if (fields > 1)
			*empty_field = true;
		return (cpos);
	}
}
Example #2
0
static inline int
get_wc_index(struct sort_list_item *sli, size_t level)
{
	const struct bwstring *bws;

	bws = sli->ka.key[0].k;

	if ((BWSLEN(bws) > level))
		return (unsigned char) BWS_GET(bws,level);
	return (-1);
}
Example #3
0
static inline int
get_wc_index(struct sort_list_item *sli, size_t level)
{
	const struct key_value *kv;
	const struct bwstring *bws;

	kv = get_key_from_keys_array(&sli->ka, 0);
	bws = kv->k;

	if ((BWSLEN(bws) > level))
		return (unsigned char) BWS_GET(bws,level);
	return (-1);
}
Example #4
0
/*
 * Skip columns according to specs
 */
static size_t
skip_cols_to_start(const struct bwstring *s, size_t cols, size_t start,
    bool skip_blanks, bool *empty_key)
{
	if (cols < 1)
		return (BWSLEN(s) + 1);

	if (skip_blanks)
		while (start < BWSLEN(s) && iswblank(BWS_GET(s,start)))
			++start;

	while (start < BWSLEN(s) && cols > 1) {
		--cols;
		++start;
	}

	if (start >= BWSLEN(s))
		*empty_key = true;

	return (start);
}
Example #5
0
/*
 * Find end key position
 */
static size_t
find_field_end(const struct bwstring *s, struct key_specs *ks)
{
	size_t f2, next_field_start, pos_end;
	bool empty_field, empty_key;

	pos_end = 0;
	next_field_start = 0;
	empty_field = false;
	empty_key = false;
	f2 = ks->f2;

	if (f2 == 0)
		return (BWSLEN(s) + 1);
	else {
		if (ks->c2 == 0) {
			next_field_start = skip_fields_to_start(s, f2 + 1,
			    &empty_field);
			if ((next_field_start > 0) && sort_opts_vals.tflag &&
			    (sort_opts_vals.field_sep == BWS_GET(s,
			    next_field_start - 1)))
				--next_field_start;
		} else
			next_field_start = skip_fields_to_start(s, f2,
			    &empty_field);
	}

	if (empty_field || (next_field_start >= BWSLEN(s)))
		return (BWSLEN(s) + 1);

	if (ks->c2) {
		pos_end = skip_cols_to_start(s, ks->c2, next_field_start,
		    ks->pos2b, &empty_key);
		if (pos_end < BWSLEN(s))
			++pos_end;
	} else
		pos_end = next_field_start;

	return (pos_end);
}