aboutsummaryrefslogtreecommitdiff
path: root/sys/libunicode/findlast.c
blob: ab25ab2e7dde14e77a050b69ea93a44faa316317 (plain)
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
32
#include "internal.h"

byte*
utf8·findlast(byte* s, rune c)
{
    long c1;
    rune r;
    byte *l;

    if(c < Tx)
        return strrchr(s, c);

    l = nil;
    for(;;){
        c1 = *(ubyte*)s;
        if(c1 < Tx){
            if(c1 == 0) return l;
            if(c1 == c) l = s;
            s++;
            continue;
        }

        c1 = utf8·decode(s, &r);

        if(r == c)
            l = s;

        s += c1;
    }

    return nil;
}