mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-06 14:31:35 +08:00
Array methods for case conversion
This commit is contained in:
@@ -742,6 +742,38 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the string to upper/lower case in place, assuming that encoding is ASCII.
|
||||||
|
* These methods can only be used with string-like arrays; otherwise compilation will fail.
|
||||||
|
*/
|
||||||
|
void convertToUpperCaseASCII()
|
||||||
|
{
|
||||||
|
StaticAssert<Base::IsStringLike>::check();
|
||||||
|
|
||||||
|
for (SizeType i = 0; i < size(); i++)
|
||||||
|
{
|
||||||
|
const int x = Base::at(i);
|
||||||
|
if ((x <= 'z') && (x >= 'a'))
|
||||||
|
{
|
||||||
|
Base::at(i) = static_cast<ValueType>(x + ('Z' - 'z'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void convertToLowerCaseASCII()
|
||||||
|
{
|
||||||
|
StaticAssert<Base::IsStringLike>::check();
|
||||||
|
|
||||||
|
for (SizeType i = 0; i < size(); i++)
|
||||||
|
{
|
||||||
|
const int x = Base::at(i);
|
||||||
|
if ((x <= 'Z') && (x >= 'A'))
|
||||||
|
{
|
||||||
|
Base::at(i) = static_cast<ValueType>(x - ('Z' - 'z'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills this array as a packed square matrix from a static array.
|
* Fills this array as a packed square matrix from a static array.
|
||||||
* Please refer to the specification to learn more about matrix packing.
|
* Please refer to the specification to learn more about matrix packing.
|
||||||
|
|||||||
@@ -1278,3 +1278,21 @@ TEST(Array, FuzzyComparison)
|
|||||||
uavcan::YamlStreamer<ArrayDynamic64>::stream(std::cout, array_d64, 0);
|
uavcan::YamlStreamer<ArrayDynamic64>::stream(std::cout, array_d64, 0);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Array, CaseConversion)
|
||||||
|
{
|
||||||
|
Array<IntegerSpec<8, SignednessUnsigned, CastModeTruncate>, ArrayModeDynamic, 30> str;
|
||||||
|
|
||||||
|
str.convertToLowerCaseASCII();
|
||||||
|
str.convertToUpperCaseASCII();
|
||||||
|
|
||||||
|
ASSERT_STREQ("", str.c_str());
|
||||||
|
|
||||||
|
str = "Hello World!";
|
||||||
|
|
||||||
|
ASSERT_STREQ("Hello World!", str.c_str());
|
||||||
|
str.convertToLowerCaseASCII();
|
||||||
|
ASSERT_STREQ("hello world!", str.c_str());
|
||||||
|
str.convertToUpperCaseASCII();
|
||||||
|
ASSERT_STREQ("HELLO WORLD!", str.c_str());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user