Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc9a636

Browse files
authored
Merge pull request#220 from alranel/isempty
Add String::isEmpty()
2 parents2c4e96c +73e2d09 commitfc9a636

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎api/String.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class String
8989
// invalid string (i.e., "if (s)" will be true afterwards)
9090
boolreserve(unsignedint size);
9191
inlineunsignedintlength(void)const {return len;}
92+
inlineboolisEmpty(void)const {returnlength() ==0; }
9293

9394
// creates a copy of the assigned value. if the value is null or
9495
// invalid, or if the memory allocation fails, the string will be

‎test/src/String/test_isEmpty.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2023 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include<catch.hpp>
10+
11+
#include<api/String.h>
12+
13+
#include"StringPrinter.h"
14+
15+
/**************************************************************************************
16+
* TEST CODE
17+
**************************************************************************************/
18+
19+
TEST_CASE ("Testing String::isEmpty when string is empty","[String-isEmpty-01]")
20+
{
21+
arduino::String str;
22+
REQUIRE(str.isEmpty());
23+
}
24+
25+
TEST_CASE ("Testing String::isEmpty when string contains characters","[String-isEmpty-02]")
26+
{
27+
arduino::Stringstr("Testing String::isEmpty");
28+
REQUIRE(!str.isEmpty());
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp