aboutsummaryrefslogtreecommitdiffstats
path: root/src/zsplit.c
blob: 40b3e540de40251af9c4ebb4ea0e1cea1224e313 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* See LICENSE file for copyright and license details. */
#include "internals"


void
zsplit(z_t high, z_t low, z_t a, size_t delim)
{
	size_t chars;

	if (zzero(a)) {
		SET_SIGNUM(high, 0);
		SET_SIGNUM(low, 0);
		return;
	}

	chars = delim >> LB_BITS_PER_CHAR;

	if (high == a) {
		if (a->used < chars)
			SET_SIGNUM(low, 0);
		else
			ztrunc(low, a, delim);
		zrsh(high, a, delim);
	} else {
		zrsh(high, a, delim);
		if (a->used < chars)
			SET_SIGNUM(low, 0);
		else
			ztrunc(low, a, delim);
	}
}