blob: 5108f186e727875b946d9d682297627791c425de (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <ctype.h>
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace common
{
class StringUtil
{
public:
static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right) noexcept
{
while (left <= right && isspace(str[left]))
{
left++;
}
while (left <= right && isspace(str[right]))
{
right--;
}
return str.substr(left, 1 + right - left);
}
static nostd::string_view Trim(nostd::string_view str) noexcept
{
if (str.empty())
{
return str;
}
return Trim(str, 0, str.size() - 1);
}
};
} // namespace common
OPENTELEMETRY_END_NAMESPACE
|