aboutsummaryrefslogtreecommitdiff
path: root/src/libutf/canfit.c
blob: 4579ab3457ddcedcb645d8b2f6295bee209a2a53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "internal.h"

/* returns 1 if string of length n is long enough to be decoded */
int
utf8ยทcanfit(byte* s, int n)
{
    int  i;
    rune c;

    if(n <= 0)
        return 0;

    c = *(ubyte*)s;
    if(c < TByte1)
        return 1;

    if(c < TByte3)
        return n >= 2;
    if(c < TByte4)
        return n >= 3;

    return n >= UTFmax;
}