return _mStr[i];
}
+ bool startsWith(const bt2c::CStringView prefix) const noexcept
+ {
+ BT_ASSERT_DBG(_mStr);
+ BT_ASSERT_DBG(prefix);
+ return std::strncmp(_mStr, prefix, prefix.len()) == 0;
+ }
+
private:
const char *_mStr = nullptr;
};
testNe(foo1, bt2c::CStringView {bar});
}
+void testStartsWith()
+{
+ ok(bt2c::CStringView {"Moutarde choux"}.startsWith("Moutarde"),
+ "\"Moutarde Choux\" starts with \"Moutarde\"");
+ ok(!bt2c::CStringView {"Moutarde choux"}.startsWith("Choux"),
+ "\"Moutarde Choux\" does not start with \"Choux\"");
+ ok(bt2c::CStringView {"Moutarde choux"}.startsWith(""), "\"Moutarde Choux\" starts with \"\"");
+ ok(bt2c::CStringView {"Moutarde choux"}.startsWith("Moutarde choux"),
+ "\"Moutarde Choux\" starts with \"Moutarde choux\"");
+ ok(!bt2c::CStringView {"Moutarde"}.startsWith("Moutarde choux"),
+ "\"Moutarde\" does not start with \"Moutarde choux\"");
+ ok(bt2c::CStringView {""}.startsWith(""), "\"\" starts with \"\"");
+}
+
} /* namespace */
int main()
{
- plan_tests(10);
+ plan_tests(16);
testEquality();
+ testStartsWith();
return exit_status();
}