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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
namespace propagation
{
// NOTE - code within `detail` namespace implements internal details, and not part
// of the public interface.
namespace detail
{
/**
* Splits a string by separator, up to given buffer count words.
* Returns the amount of words the input was split into.
*/
inline size_t SplitString(nostd::string_view s,
char separator,
nostd::string_view *results,
size_t count)
{
if (count == 0)
{
return count;
}
size_t filled = 0;
size_t token_start = 0;
for (size_t i = 0; i < s.size(); i++)
{
if (s[i] != separator)
{
continue;
}
results[filled++] = s.substr(token_start, i - token_start);
if (filled == count)
{
return count;
}
token_start = i + 1;
}
if (filled < count)
{
results[filled++] = s.substr(token_start);
}
return filled;
}
} // namespace detail
} // namespace propagation
} // namespace trace
OPENTELEMETRY_END_NAMESPACE
|