Coverage Report

Created: 2025-11-15 08:43

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
58
{
21
    // v0
22
58
    for (const char *pszExpectedPrefix : {"{\".zgroup\":{", "{\".zgroup\":\"{",
23
58
                                          "{\".zattrs\":{", "{\".zattrs\":\"{"})
24
232
    {
25
232
        for (char ch : str)
26
5.39k
        {
27
5.39k
            if (!(ch == ' ' || ch == '\n' || ch == '\r'))
28
360
            {
29
360
                if (ch != *pszExpectedPrefix)
30
228
                    break;
31
132
                ++pszExpectedPrefix;
32
132
                if (*pszExpectedPrefix == 0)
33
0
                {
34
0
                    return true;
35
0
                }
36
132
            }
37
5.39k
        }
38
232
    }
39
40
58
    {
41
        // v1
42
58
        const char *pszExpectedPrefix = "{\"version\":1,\"refs\":{";
43
58
        for (char ch : str)
44
1.34k
        {
45
1.34k
            if (!(ch == ' ' || ch == '\n' || ch == '\r'))
46
87
            {
47
87
                if (ch != *pszExpectedPrefix)
48
57
                    break;
49
30
                ++pszExpectedPrefix;
50
30
                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
30
            }
56
1.34k
        }
57
58
    }
58
58
    return false;
59
58
}
60
61
#endif