Coverage Report

Created: 2026-07-27 15:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/itoken_extractor.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "storage/itoken_extractor.h"
19
20
#include <stdint.h>
21
22
#include "util/simd/vstring_function.h"
23
24
namespace doris {
25
26
bool NgramTokenExtractor::next_in_string(const char* data, size_t length, size_t* __restrict pos,
27
                                         size_t* __restrict token_start,
28
1.11M
                                         size_t* __restrict token_length) const {
29
1.11M
    *token_start = *pos;
30
1.11M
    *token_length = 0;
31
1.11M
    size_t code_points = 0;
32
10.1M
    for (; code_points < n && *token_start + *token_length < length; ++code_points) {
33
9.05M
        size_t sz = get_utf8_byte_length(static_cast<uint8_t>(data[*token_start + *token_length]));
34
9.05M
        *token_length += sz;
35
9.05M
    }
36
1.11M
    *pos += get_utf8_byte_length(static_cast<uint8_t>(data[*pos]));
37
1.11M
    return code_points == n;
38
1.11M
}
39
40
bool NgramTokenExtractor::next_in_string_like(const char* data, size_t length, size_t* pos,
41
579
                                              std::string& token) const {
42
579
    token.clear();
43
44
579
    size_t code_points = 0;
45
579
    bool escaped = false;
46
2.43k
    for (size_t i = *pos; i < length;) {
47
2.35k
        if (escaped && (data[i] == '%' || data[i] == '_' || data[i] == '\\')) {
48
10
            token += data[i];
49
10
            ++code_points;
50
10
            escaped = false;
51
10
            ++i;
52
2.34k
        } else if (!escaped && (data[i] == '%' || data[i] == '_')) {
53
            /// This token is too small, go to the next.
54
76
            token.clear();
55
76
            code_points = 0;
56
76
            escaped = false;
57
76
            *pos = ++i;
58
2.26k
        } else if (!escaped && data[i] == '\\') {
59
10
            escaped = true;
60
10
            ++i;
61
2.25k
        } else {
62
2.25k
            const size_t sz = get_utf8_byte_length(static_cast<uint8_t>(data[i]));
63
4.58k
            for (size_t j = 0; j < sz; ++j) {
64
2.33k
                token += data[i + j];
65
2.33k
            }
66
2.25k
            i += sz;
67
2.25k
            ++code_points;
68
2.25k
            escaped = false;
69
2.25k
        }
70
71
2.35k
        if (code_points == n) {
72
498
            *pos += get_utf8_byte_length(static_cast<uint8_t>(data[*pos]));
73
498
            return true;
74
498
        }
75
2.35k
    }
76
77
81
    return false;
78
579
}
79
} // namespace doris