Coverage Report

Created: 2026-05-21 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/include/tsutil/StringCompare.h
Line
Count
Source
1
/** @file
2
3
  Helper for std::string_view comparison
4
5
  @section license License
6
7
  Licensed to the Apache Software Foundation (ASF) under one
8
  or more contributor license agreements.  See the NOTICE file
9
  distributed with this work for additional information
10
  regarding copyright ownership.  The ASF licenses this file
11
  to you under the Apache License, Version 2.0 (the
12
  "License"); you may not use this file except in compliance
13
  with the License.  You may obtain a copy of the License at
14
15
      http://www.apache.org/licenses/LICENSE-2.0
16
17
  Unless required by applicable law or agreed to in writing, software
18
  distributed under the License is distributed on an "AS IS" BASIS,
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
  See the License for the specific language governing permissions and
21
  limitations under the License.
22
 */
23
24
#pragma once
25
26
#include <strings.h>
27
#include <string_view>
28
29
namespace ts
30
{
31
/**
32
  Returns true iff @a lhs and @a rhs compare equal, ignoring case.
33
34
  Prefer this over libswoc's @c strcasecmp(std::string_view, std::string_view) when you only need
35
  an equality check: this short-circuits on length mismatch, whereas the libswoc version must keep
36
  comparing bytes to produce a correct ordering result even when the lengths differ.
37
38
  For case-sensitive comparison, use @c std::string_view::operator==.
39
 */
40
inline bool
41
iequals(std::string_view lhs, std::string_view rhs) noexcept
42
0
{
43
0
  if (lhs.size() != rhs.size()) {
44
0
    return false;
45
0
  }
46
47
0
  return ::strncasecmp(lhs.data(), rhs.data(), lhs.size()) == 0;
48
0
}
49
} // namespace ts