Skip to content

Commit 50bf20b

Browse files
committed
feat(util): add string.remove_prefix.
1 parent 90a7ddc commit 50bf20b

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Diff for: src/rockchip/RKCfg.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ RKCfgFile::fromParameter(const std::string& path, AutoScanArgument auto_scan_arg
6464
// "mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),...,0x00400000@0x00E3a000(userdata),-@0x0123a000(userdisk:grow)"
6565
std::string mtdparts;
6666
while (std::getline(file, mtdparts)) {
67-
if (mtdparts.starts_with("mtdparts=")) break;
67+
if (mtdparts.starts_with("CMDLINE: "))
68+
if (mtdparts.starts_with("mtdparts=")) break;
6869
}
6970
spdlog::debug("mtdparts: {}", mtdparts);
7071
if (mtdparts.empty()) {

Diff for: src/util/String.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ std::optional<uint32_t> to_uint32(const std::string& str) {
3333
return value;
3434
}
3535

36+
void remove_prefix(std::string& str, const std::string& prefix) {
37+
if (str.size() >= prefix.size() && str.compare(0, prefix.size(), prefix) == 0) {
38+
str.erase(0, prefix.size());
39+
}
40+
}
41+
3642
void remove_suffix(std::string& str, const std::string& suffix) {
3743
if (str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0) {
3844
str.erase(str.size() - suffix.size());

Diff for: src/util/String.h

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ bool to_char16(const std::string& str, char16_t* des, size_t len);
1212
// TODO: Replace with: std::expected
1313
std::optional<uint32_t> to_uint32(const std::string& str);
1414

15+
void remove_prefix(std::string& str, const std::string& prefix);
16+
1517
void remove_suffix(std::string& str, const std::string& suffix);
1618

1719

0 commit comments

Comments
 (0)