Coverage Report

Created: 2026-05-16 08:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/frmts/zarr/vsikerchunk_inline.hpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  GDAL
4
 * Purpose:  Zarr driver
5
 * Author:   Even Rouault <even dot rouault at spatialys.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#ifndef VSIKERCHUNK_INLINE_HPP
14
#define VSIKERCHUNK_INLINE_HPP
15
16
#include <string_view>
17
18
inline bool
19
ZARRIsLikelyStreamableKerchunkJSONRefContent(const std::string_view &str)
20
103
{
21
    // v0
22
103
    for (const char *pszExpectedPrefix : {"{\".zgroup\":{", "{\".zgroup\":\"{",
23
103
                                          "{\".zattrs\":{", "{\".zattrs\":\"{"})
24
412
    {
25
412
        for (char ch : str)
26
11.8k
        {
27
11.8k
            if (!(ch == ' ' || ch == '\n' || ch == '\r'))
28
500
            {
29
500
                if (ch != *pszExpectedPrefix)
30
400
                    break;
31
100
                ++pszExpectedPrefix;
32
100
                if (*pszExpectedPrefix == 0)
33
0
                {
34
0
                    return true;
35
0
                }
36
100
            }
37
11.8k
        }
38
412
    }
39
40
103
    {
41
        // v1
42
103
        const char *pszExpectedPrefix = "{\"version\":1,\"refs\":{";
43
103
        for (char ch : str)
44
2.94k
        {
45
2.94k
            if (!(ch == ' ' || ch == '\n' || ch == '\r'))
46
122
            {
47
122
                if (ch != *pszExpectedPrefix)
48
100
                    break;
49
22
                ++pszExpectedPrefix;
50
22
                if (*pszExpectedPrefix == 0)
51
0
                {
52
0
                    return str.find("\".zgroup\"") != std::string::npos ||
53
0
                           str.find("\".zarray\"") != std::string::npos;
54
0
                }
55
22
            }
56
2.94k
        }
57
103
    }
58
103
    return false;
59
103
}
60
61
#endif