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

/* returns 1 if string of length n is long enough to be decoded */
int
utf8ยทfullrune(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;
}