[core] Add StringRef::starts_with - #18142
Conversation
|
@bluetoothbot review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #18142 +/- ##
=======================================
Coverage 87.28% 87.28%
=======================================
Files 64 64
Lines 14697 14697
Branches 2217 2217
=======================================
Hits 12829 12829
Misses 1558 1558
Partials 310 310 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
|
@bluetoothbot review |
|
|
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
@bluetoothbot review |
|
@bluetoothbot review |
029c2e8 to
386cfd0
Compare
PR Review — [core] Add StringRef::starts_withBoth prior suggestions are addressed and the helper is correct — merge-ready, no findings. What's solid:
Prior findings, both now resolved:
Checklist
Automated review by Kōan (Claude) |
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
👋 Hi there! This PR modifies 1 file(s) with codeowners. @esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
There was a problem hiding this comment.
Pull request overview
This PR extends ESPHome’s core StringRef utility with a starts_with() helper (similar to std::string::starts_with) to support prefix-matching on bounded, potentially non-null-terminated buffers—needed for upcoming BLE advertisement name handling that will expose names as StringRef.
Changes:
- Added
StringRef::starts_with()overloads forStringRef,const char*, andstd::string. - Added new GoogleTest coverage for prefix-matching behavior, including non-terminated buffer cases and overload behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
esphome/core/string_ref.h |
Adds starts_with() implementation and overloads on the StringRef view type. |
tests/components/core/test_string_ref.cpp |
Introduces unit tests validating correct prefix matching across edge cases and overloads. |
|
thanks |
What does this implement/fix?
Adds a starts_with helper to StringRef, matching std::string::starts_with; a length check plus memcmp on the view. The next PR in this series stores BLE advertisement names in a fixed buffer exposed as StringRef, and the listeners that prefix match on the name (radon_eye_ble, thermopro_ble) keep working through this helper.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome.io with documentation (if applicable):
Pull request in developers.esphome.io with developer documentation (if applicable):
Test Environment
Example entry for
config.yaml:# Example config.yamlChecklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: