Coverage Report

Created: 2025-05-12 01:12

/root/doris/be/src/util/string_util.cpp
Line
Count
Source (jump to first uncovered line)
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 "util/string_util.h"
19
20
#include <absl/strings/str_split.h>
21
22
#include "util/hash_util.hpp"
23
24
namespace doris {
25
26
74
size_t hash_of_path(const std::string& identifier, const std::string& path) {
27
74
    size_t hash = std::hash<std::string>()(identifier);
28
74
    std::vector<std::string> path_parts = absl::StrSplit(path, "/", absl::SkipWhitespace());
29
264
    for (auto& part : path_parts) {
30
264
        HashUtil::hash_combine<std::string>(hash, part);
31
264
    }
32
74
    return hash;
33
74
}
34
35
0
Result<int> safe_stoi(const std::string& input, const std::string& name) {
36
0
    try {
37
0
        return std::stoi(input);
38
0
    } catch (const std::invalid_argument& e) {
39
0
        return ResultError(Status::Error<ErrorCode::INVALID_ARGUMENT>(
40
0
                std::string("Invalid format of '{}': '{}', {}"), name, input, e.what()));
41
0
    } catch (const std::out_of_range& e) {
42
0
        return ResultError(Status::Error<ErrorCode::INVALID_ARGUMENT>(
43
0
                std::string("'{}' value out of range: '{}', {}"), name, input, e.what()));
44
0
    }
45
0
}
46
} // namespace doris