Coverage Report

Created: 2025-10-30 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PROJ/src/wkt_parser.cpp
Line
Count
Source
1
/******************************************************************************
2
 * Project:  PROJ
3
 * Purpose:  WKT parser common routines
4
 * Author:   Even Rouault, <even.rouault at spatialys.com>
5
 *
6
 ******************************************************************************
7
 * Copyright (c) 2018 Even Rouault, <even.rouault at spatialys.com>
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a
10
 * copy of this software and associated documentation files (the "Software"),
11
 * to deal in the Software without restriction, including without limitation
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
 * and/or sell copies of the Software, and to permit persons to whom the
14
 * Software is furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included
17
 * in all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
 * DEALINGS IN THE SOFTWARE.
26
 ****************************************************************************/
27
28
#include "wkt_parser.hpp"
29
30
#include <algorithm>
31
#include <string>
32
33
// ---------------------------------------------------------------------------
34
35
866
void pj_wkt_error(pj_wkt_parse_context *context, const char *msg) {
36
866
    context->errorMsg = "Parsing error : ";
37
866
    context->errorMsg += msg;
38
866
    context->errorMsg += ". Error occurred around:\n";
39
40
866
    std::string ctxtMsg;
41
866
    const int n = static_cast<int>(context->pszLastSuccess - context->pszInput);
42
866
    int start_i = std::max(0, n - 40);
43
38.0k
    for (int i = start_i; i < n + 40 && context->pszInput[i]; i++) {
44
37.1k
        if (context->pszInput[i] == '\r' || context->pszInput[i] == '\n') {
45
202
            if (i > n) {
46
35
                break;
47
167
            } else {
48
167
                ctxtMsg.clear();
49
167
                start_i = i + 1;
50
167
            }
51
36.9k
        } else {
52
36.9k
            ctxtMsg += context->pszInput[i];
53
36.9k
        }
54
37.1k
    }
55
866
    context->errorMsg += ctxtMsg;
56
866
    context->errorMsg += '\n';
57
11.2k
    for (int i = start_i; i < n; i++)
58
10.3k
        context->errorMsg += ' ';
59
866
    context->errorMsg += '^';
60
866
}