Coverage Report

Created: 2025-09-10 20:18

/root/doris/common/cpp/util.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
// Most code of this file is copied from rocksdb SyncPoint.
19
// https://github.com/facebook/rocksdb
20
21
#include <string>
22
23
namespace doris {
24
25
50
std::string normalize_http_uri(const std::string& uri) {
26
50
    if (uri.empty()) {
27
1
        return uri;
28
1
    }
29
30
    // Find the end of protocol part (http:// or https://)
31
    // Example: in "https://example.com", protocol_end will be 8 (position after "://")
32
49
    size_t protocol_end = uri.find("://");
33
49
    if (protocol_end == std::string::npos) {
34
12
        protocol_end = 0; // No protocol found, start from beginning
35
37
    } else {
36
37
        protocol_end += 3; // Skip past "://"
37
37
    }
38
39
    // Keep protocol part (e.g., "https://")
40
49
    std::string result = uri.substr(0, protocol_end);
41
42
    // Process the rest of URI to remove duplicate slashes
43
    // Example: "//path//to///file" becomes "/path/to/file"
44
2.05k
    for (size_t i = protocol_end; i < uri.length(); i++) {
45
2.01k
        char current = uri[i];
46
47
        // Add current character if it's not a slash, or if it's the first slash in sequence
48
        // This prevents consecutive slashes like "//" or "///" from being added
49
2.01k
        if (current != '/' || result.empty() || result.back() != '/') {
50
1.82k
            result += current;
51
1.82k
        }
52
2.01k
    }
53
49
    return result;
54
50
}
55
} // namespace doris