Skip to content

Commit 181b0cb

Browse files
Add a _span string literal operator for creating constexpr CharSpans (#30042)
* Add a _span string literal operator to create constexpr CharSpans * Adopt _span for literals * Tweaks from review
1 parent 506a489 commit 181b0cb

File tree

11 files changed

+117
-50
lines changed

11 files changed

+117
-50
lines changed

src/app/clusters/door-lock-server/door-lock-server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ EmberAfStatus DoorLockServer::createUser(chip::EndpointId endpointId, chip::Fabr
18271827
return static_cast<EmberAfStatus>(DlStatus::kOccupied);
18281828
}
18291829

1830-
const auto & newUserName = !userName.IsNull() ? userName.Value() : chip::CharSpan::fromCharString("");
1830+
const auto & newUserName = !userName.IsNull() ? userName.Value() : ""_span;
18311831
auto newUserUniqueId = userUniqueId.IsNull() ? 0xFFFFFFFF : userUniqueId.Value();
18321832
auto newUserStatus = userStatus.IsNull() ? UserStatusEnum::kOccupiedEnabled : userStatus.Value();
18331833
auto newUserType = userType.IsNull() ? UserTypeEnum::kUnrestrictedUser : userType.Value();

src/controller/CHIPDeviceController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,7 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
25432543
else
25442544
{
25452545
// Default to "XX", for lack of anything better.
2546-
countryCode = CharSpan::fromCharString("XX");
2546+
countryCode = "XX"_span;
25472547
}
25482548

25492549
GeneralCommissioning::Commands::SetRegulatoryConfig::Type request;

src/credentials/tests/TestFabricTable.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -2261,32 +2261,32 @@ void TestFabricLabelChange(nlTestSuite * inSuite, void * inContext)
22612261
// Second scope: set FabricLabel to "acme fabric", make sure it cannot be reverted
22622262
{
22632263
// Fabric label starts unset from prior scope
2264-
CharSpan fabricLabel = CharSpan::fromCharString("placeholder");
2264+
CharSpan fabricLabel = "placeholder"_span;
22652265

22662266
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.GetFabricLabel(1, fabricLabel));
22672267
NL_TEST_ASSERT(inSuite, fabricLabel.size() == 0);
22682268

22692269
// Set a valid name
2270-
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.SetFabricLabel(1, CharSpan::fromCharString("acme fabric")));
2270+
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.SetFabricLabel(1, "acme fabric"_span));
22712271
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.GetFabricLabel(1, fabricLabel));
2272-
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal(CharSpan::fromCharString("acme fabric")) == true);
2272+
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal("acme fabric"_span) == true);
22732273

22742274
// Revert pending fabric data. Should not revert name since nothing pending.
22752275
fabricTable.RevertPendingFabricData();
22762276

2277-
fabricLabel = CharSpan::fromCharString("placeholder");
2277+
fabricLabel = "placeholder"_span;
22782278
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.GetFabricLabel(1, fabricLabel));
2279-
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal(CharSpan::fromCharString("acme fabric")) == true);
2279+
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal("acme fabric"_span) == true);
22802280

22812281
// Verify we fail to set too large a label (> kFabricLabelMaxLengthInBytes)
2282-
CharSpan fabricLabelTooBig = CharSpan::fromCharString("012345678901234567890123456789123456");
2282+
CharSpan fabricLabelTooBig = "012345678901234567890123456789123456"_span;
22832283
NL_TEST_ASSERT(inSuite, fabricLabelTooBig.size() > chip::kFabricLabelMaxLengthInBytes);
22842284

22852285
NL_TEST_ASSERT(inSuite, fabricTable.SetFabricLabel(1, fabricLabelTooBig) == CHIP_ERROR_INVALID_ARGUMENT);
22862286

2287-
fabricLabel = CharSpan::fromCharString("placeholder");
2287+
fabricLabel = "placeholder"_span;
22882288
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.GetFabricLabel(1, fabricLabel));
2289-
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal(CharSpan::fromCharString("acme fabric")) == true);
2289+
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal("acme fabric"_span) == true);
22902290
}
22912291

22922292
// Third scope: set fabric label after an update, it sticks, but then goes back after revert
@@ -2320,23 +2320,23 @@ void TestFabricLabelChange(nlTestSuite * inSuite, void * inContext)
23202320
NL_TEST_ASSERT(inSuite, fabricInfo->GetVendorId() == kVendorId);
23212321

23222322
CharSpan fabricLabel = fabricInfo->GetFabricLabel();
2323-
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal(CharSpan::fromCharString("acme fabric")) == true);
2323+
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal("acme fabric"_span) == true);
23242324
}
23252325

23262326
// Update fabric label
2327-
CharSpan fabricLabel = CharSpan::fromCharString("placeholder");
2328-
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.SetFabricLabel(1, CharSpan::fromCharString("roboto fabric")));
2327+
CharSpan fabricLabel = "placeholder"_span;
2328+
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.SetFabricLabel(1, "roboto fabric"_span));
23292329

2330-
fabricLabel = CharSpan::fromCharString("placeholder");
2330+
fabricLabel = "placeholder"_span;
23312331
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.GetFabricLabel(1, fabricLabel));
2332-
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal(CharSpan::fromCharString("roboto fabric")) == true);
2332+
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal("roboto fabric"_span) == true);
23332333

23342334
// Revert pending fabric data. Should revert name to "acme fabric"
23352335
fabricTable.RevertPendingFabricData();
23362336

2337-
fabricLabel = CharSpan::fromCharString("placeholder");
2337+
fabricLabel = "placeholder"_span;
23382338
NL_TEST_ASSERT_SUCCESS(inSuite, fabricTable.GetFabricLabel(1, fabricLabel));
2339-
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal(CharSpan::fromCharString("acme fabric")) == true);
2339+
NL_TEST_ASSERT(inSuite, fabricLabel.data_equal("acme fabric"_span) == true);
23402340
}
23412341
}
23422342

src/crypto/tests/CHIPCryptoPALTest.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -2414,13 +2414,10 @@ static void TestSubject_x509Extraction(nlTestSuite * inSuite, void * inContext)
24142414
NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == subjectDN_Node02_02.AddAttribute_MatterFabricId(0xFAB000000000001D));
24152415
NL_TEST_ASSERT(inSuite,
24162416
CHIP_NO_ERROR ==
2417-
subjectDN_Node02_02.AddAttribute_CommonName(
2418-
chip::CharSpan::fromCharString("TEST CERT COMMON NAME Attr for Node02_02"), false));
2417+
subjectDN_Node02_02.AddAttribute_CommonName("TEST CERT COMMON NAME Attr for Node02_02"_span, false));
24192418
ChipDN subjectDN_Node02_04;
24202419
NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == subjectDN_Node02_04.AddAttribute_MatterCASEAuthTag(0xABCE1002));
2421-
NL_TEST_ASSERT(inSuite,
2422-
CHIP_NO_ERROR ==
2423-
subjectDN_Node02_04.AddAttribute_CommonName(chip::CharSpan::fromCharString("TestCert02_04"), false));
2420+
NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == subjectDN_Node02_04.AddAttribute_CommonName("TestCert02_04"_span, false));
24242421
NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == subjectDN_Node02_04.AddAttribute_MatterFabricId(0xFAB000000000001D));
24252422
NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == subjectDN_Node02_04.AddAttribute_MatterCASEAuthTag(0xABCD0003));
24262423
NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == subjectDN_Node02_04.AddAttribute_MatterNodeId(0xDEDEDEDE00020004));

src/lib/core/Unchecked.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* 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, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* @file
20+
* This file defines the chip::Optional class to handle values which may
21+
* or may not be present.
22+
*
23+
*/
24+
#pragma once
25+
26+
namespace chip {
27+
28+
/// Unchecked is a disambiguation tag that can be used to provide and select a variant of a
29+
/// constructor or other method that omits the runtime checks performed by the default variant.
30+
struct UncheckedType
31+
{
32+
explicit UncheckedType() = default;
33+
};
34+
inline constexpr UncheckedType Unchecked{};
35+
36+
} // namespace chip

src/lib/core/tests/TestOTAImageHeader.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ void TestHappyPath(nlTestSuite * inSuite, void * inContext)
8383
NL_TEST_ASSERT(inSuite, header.mVendorId == 0xDEAD);
8484
NL_TEST_ASSERT(inSuite, header.mProductId == 0xBEEF);
8585
NL_TEST_ASSERT(inSuite, header.mSoftwareVersion == 0xFFFFFFFF);
86-
NL_TEST_ASSERT(inSuite, header.mSoftwareVersionString.data_equal(CharSpan::fromCharString("1.0")));
86+
NL_TEST_ASSERT(inSuite, header.mSoftwareVersionString.data_equal("1.0"_span));
8787
NL_TEST_ASSERT(inSuite, header.mPayloadSize == strlen("test payload"));
8888
NL_TEST_ASSERT(inSuite, header.mMinApplicableVersion.HasValue());
8989
NL_TEST_ASSERT(inSuite, header.mMinApplicableVersion.Value() == 1);
9090
NL_TEST_ASSERT(inSuite, header.mMaxApplicableVersion.HasValue());
9191
NL_TEST_ASSERT(inSuite, header.mMaxApplicableVersion.Value() == 2);
92-
NL_TEST_ASSERT(inSuite, header.mReleaseNotesURL.data_equal(CharSpan::fromCharString("https://rn")));
92+
NL_TEST_ASSERT(inSuite, header.mReleaseNotesURL.data_equal("https://rn"_span));
9393
NL_TEST_ASSERT(inSuite, header.mImageDigestType == OTAImageDigestType::kSha256);
9494
NL_TEST_ASSERT(inSuite, header.mImageDigest.size() == 256 / 8);
9595
}
@@ -169,13 +169,13 @@ void TestSmallBlocks(nlTestSuite * inSuite, void * inContext)
169169
NL_TEST_ASSERT(inSuite, header.mVendorId == 0xDEAD);
170170
NL_TEST_ASSERT(inSuite, header.mProductId == 0xBEEF);
171171
NL_TEST_ASSERT(inSuite, header.mSoftwareVersion == 0xFFFFFFFF);
172-
NL_TEST_ASSERT(inSuite, header.mSoftwareVersionString.data_equal(CharSpan::fromCharString("1.0")));
172+
NL_TEST_ASSERT(inSuite, header.mSoftwareVersionString.data_equal("1.0"_span));
173173
NL_TEST_ASSERT(inSuite, header.mPayloadSize == strlen("test payload"));
174174
NL_TEST_ASSERT(inSuite, header.mMinApplicableVersion.HasValue());
175175
NL_TEST_ASSERT(inSuite, header.mMinApplicableVersion.Value() == 1);
176176
NL_TEST_ASSERT(inSuite, header.mMaxApplicableVersion.HasValue());
177177
NL_TEST_ASSERT(inSuite, header.mMaxApplicableVersion.Value() == 2);
178-
NL_TEST_ASSERT(inSuite, header.mReleaseNotesURL.data_equal(CharSpan::fromCharString("https://rn")));
178+
NL_TEST_ASSERT(inSuite, header.mReleaseNotesURL.data_equal("https://rn"_span));
179179
NL_TEST_ASSERT(inSuite, header.mImageDigestType == OTAImageDigestType::kSha256);
180180
NL_TEST_ASSERT(inSuite, header.mImageDigest.size() == 256 / 8);
181181
}

src/lib/support/Span.h

+27-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
#pragma once
1919

2020
#include <array>
21+
#include <cstddef>
2122
#include <cstdint>
2223
#include <cstdlib>
23-
#include <string.h>
24+
#include <cstring>
2425
#include <type_traits>
2526

27+
#include <lib/core/Unchecked.h>
2628
#include <lib/support/CodeUtils.h>
2729

2830
namespace chip {
@@ -149,7 +151,10 @@ class Span
149151
return Span(reinterpret_cast<T *>(&bytes[1]), length);
150152
}
151153

152-
// Allow creating CharSpans from a character string.
154+
// Creates a CharSpan from a null-terminated C character string.
155+
//
156+
// Note that for string literals, the user-defined `_span` string
157+
// literal operator should be used instead, e.g. `"Hello"_span`.
153158
template <class U, typename = std::enable_if_t<std::is_same<T, const U>::value && std::is_same<const char, T>::value>>
154159
static Span fromCharString(U * chars)
155160
{
@@ -162,11 +167,31 @@ class Span
162167
template <typename U>
163168
bool operator==(const Span<U> & other) const = delete;
164169

170+
// Creates a Span without checking whether databuf is a null pointer.
171+
//
172+
// Note: The normal (checked) constructor should be used for general use;
173+
// this overload exists for special use cases where databuf is guaranteed
174+
// to be valid (not null) and a constexpr constructor is required.
175+
//
176+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61648 prevents making
177+
// operator""_span a friend (and this constructor private).
178+
179+
constexpr Span(UncheckedType tag, pointer databuf, size_t datalen) : mDataBuf(databuf), mDataLen(datalen) {}
180+
165181
private:
166182
pointer mDataBuf;
167183
size_t mDataLen;
168184
};
169185

186+
inline namespace literals {
187+
188+
inline constexpr Span<const char> operator"" _span(const char * literal, size_t size)
189+
{
190+
return Span<const char>(Unchecked, literal, size);
191+
}
192+
193+
} // namespace literals
194+
170195
namespace detail {
171196

172197
// To make FixedSpan (specifically various FixedByteSpan types) default constructible

src/lib/support/tests/TestJsonToTlv.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void TestConverter(nlTestSuite * inSuite, void * inContext)
141141
jsonString = "{\n"
142142
" \"1:STRING\" : \"hello\"\n"
143143
"}\n";
144-
ConvertJsonToTlvAndValidate(CharSpan::fromCharString("hello"), jsonString);
144+
ConvertJsonToTlvAndValidate("hello"_span, jsonString);
145145

146146
// Validated using https://base64.guru/converter/encode/hex
147147
const uint8_t byteBuf[] = { 0x01, 0x02, 0x03, 0x04, 0xff, 0xfe, 0x99, 0x88, 0xdd, 0xcd };
@@ -161,7 +161,7 @@ void TestConverter(nlTestSuite * inSuite, void * inContext)
161161
structVal.a = 20;
162162
structVal.b = true;
163163
structVal.d = byteBuf;
164-
structVal.e = CharSpan::fromCharString("hello");
164+
structVal.e = "hello"_span;
165165
structVal.g = static_cast<float>(1.0);
166166
structVal.h = static_cast<double>(1.0);
167167

src/lib/support/tests/TestSpan.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ static void TestFromCharString(nlTestSuite * inSuite, void * inContext)
291291
NL_TEST_ASSERT(inSuite, s1.data_equal(CharSpan(str, 3)));
292292
}
293293

294+
static void TestLiteral(nlTestSuite * inSuite, void * inContext)
295+
{
296+
constexpr CharSpan literal = "HI!"_span;
297+
NL_TEST_ASSERT(inSuite, literal.size() == 3);
298+
NL_TEST_ASSERT(inSuite, literal.data_equal(CharSpan::fromCharString("HI!")));
299+
NL_TEST_ASSERT(inSuite, ""_span.size() == 0);
300+
}
301+
294302
static void TestConversionConstructors(nlTestSuite * inSuite, void * inContext)
295303
{
296304
struct Foo
@@ -330,6 +338,7 @@ static const nlTest sTests[] = {
330338
NL_TEST_DEF_FN(TestSubSpan),
331339
NL_TEST_DEF_FN(TestFromZclString),
332340
NL_TEST_DEF_FN(TestFromCharString),
341+
NL_TEST_DEF_FN(TestLiteral),
333342
NL_TEST_DEF_FN(TestConversionConstructors),
334343
NL_TEST_SENTINEL(),
335344
};

src/lib/support/tests/TestStringSplitter.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void TestStrdupSplitter(nlTestSuite * inSuite, void * inContext)
4545
StringSplitter splitter("single", ',');
4646

4747
NL_TEST_ASSERT(inSuite, splitter.Next(out));
48-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("single")));
48+
NL_TEST_ASSERT(inSuite, out.data_equal("single"_span));
4949

5050
// next stays at nullptr also after valid data
5151
NL_TEST_ASSERT(inSuite, !splitter.Next(out));
@@ -59,11 +59,11 @@ void TestStrdupSplitter(nlTestSuite * inSuite, void * inContext)
5959
StringSplitter splitter("one,two,three", ',');
6060

6161
NL_TEST_ASSERT(inSuite, splitter.Next(out));
62-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("one")));
62+
NL_TEST_ASSERT(inSuite, out.data_equal("one"_span));
6363
NL_TEST_ASSERT(inSuite, splitter.Next(out));
64-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("two")));
64+
NL_TEST_ASSERT(inSuite, out.data_equal("two"_span));
6565
NL_TEST_ASSERT(inSuite, splitter.Next(out));
66-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("three")));
66+
NL_TEST_ASSERT(inSuite, out.data_equal("three"_span));
6767
NL_TEST_ASSERT(inSuite, !splitter.Next(out));
6868
NL_TEST_ASSERT(inSuite, out.data() == nullptr);
6969
}
@@ -73,15 +73,15 @@ void TestStrdupSplitter(nlTestSuite * inSuite, void * inContext)
7373
StringSplitter splitter("a**bc*d,e*f", '*');
7474

7575
NL_TEST_ASSERT(inSuite, splitter.Next(out));
76-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("a")));
76+
NL_TEST_ASSERT(inSuite, out.data_equal("a"_span));
7777
NL_TEST_ASSERT(inSuite, splitter.Next(out));
78-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
78+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
7979
NL_TEST_ASSERT(inSuite, splitter.Next(out));
80-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("bc")));
80+
NL_TEST_ASSERT(inSuite, out.data_equal("bc"_span));
8181
NL_TEST_ASSERT(inSuite, splitter.Next(out));
82-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("d,e")));
82+
NL_TEST_ASSERT(inSuite, out.data_equal("d,e"_span));
8383
NL_TEST_ASSERT(inSuite, splitter.Next(out));
84-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("f")));
84+
NL_TEST_ASSERT(inSuite, out.data_equal("f"_span));
8585
NL_TEST_ASSERT(inSuite, !splitter.Next(out));
8686
}
8787

@@ -90,37 +90,37 @@ void TestStrdupSplitter(nlTestSuite * inSuite, void * inContext)
9090
StringSplitter splitter(",", ',');
9191
// Note that even though "" is nullptr right away, "," becomes two empty strings
9292
NL_TEST_ASSERT(inSuite, splitter.Next(out));
93-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
93+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
9494
NL_TEST_ASSERT(inSuite, splitter.Next(out));
95-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
95+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
9696
NL_TEST_ASSERT(inSuite, !splitter.Next(out));
9797
}
9898
{
9999
StringSplitter splitter("log,", ',');
100100
NL_TEST_ASSERT(inSuite, splitter.Next(out));
101-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("log")));
101+
NL_TEST_ASSERT(inSuite, out.data_equal("log"_span));
102102
NL_TEST_ASSERT(inSuite, splitter.Next(out));
103-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
103+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
104104
NL_TEST_ASSERT(inSuite, !splitter.Next(out));
105105
}
106106
{
107107
StringSplitter splitter(",log", ',');
108108
NL_TEST_ASSERT(inSuite, splitter.Next(out));
109-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
109+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
110110
NL_TEST_ASSERT(inSuite, splitter.Next(out));
111-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("log")));
111+
NL_TEST_ASSERT(inSuite, out.data_equal("log"_span));
112112
NL_TEST_ASSERT(inSuite, !splitter.Next(out));
113113
}
114114
{
115115
StringSplitter splitter(",,,", ',');
116116
NL_TEST_ASSERT(inSuite, splitter.Next(out));
117-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
117+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
118118
NL_TEST_ASSERT(inSuite, splitter.Next(out));
119-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
119+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
120120
NL_TEST_ASSERT(inSuite, splitter.Next(out));
121-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
121+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
122122
NL_TEST_ASSERT(inSuite, splitter.Next(out));
123-
NL_TEST_ASSERT(inSuite, out.data_equal(CharSpan::fromCharString("")));
123+
NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
124124
NL_TEST_ASSERT(inSuite, !splitter.Next(out));
125125
}
126126
}

src/lib/support/tests/TestTlvToJson.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void TestConverter(nlTestSuite * inSuite, void * inContext)
140140
"}\n";
141141
EncodeAndValidate(static_cast<double>(1.0), jsonString);
142142

143-
CharSpan charSpan = CharSpan::fromCharString("hello");
143+
CharSpan charSpan = "hello"_span;
144144
jsonString = "{\n"
145145
" \"1:STRING\" : \"hello\"\n"
146146
"}\n";

0 commit comments

Comments
 (0)