MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / string_find_partial_stop

Function string_find_partial_stop

smallthinker/common/common.cpp:451–465  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

449 return str.size() >= suffix.size() && str.compare(str.size()-suffix.size(), suffix.size(), suffix) == 0;
450}
451size_t string_find_partial_stop(const std::string_view & str, const std::string_view & stop) {
452 if (!str.empty() && !stop.empty()) {
453 const char text_last_char = str.back();
454 for (int64_t char_index = stop.size() - 1; char_index >= 0; char_index--) {
455 if (stop[char_index] == text_last_char) {
456 const auto current_partial = stop.substr(0, char_index + 1);
457 if (string_ends_with(str, current_partial)) {
458 return str.size() - char_index - 1;
459 }
460 }
461 }
462 }
463
464 return std::string::npos;
465}
466
467std::string regex_escape(const std::string & s) {
468 static const std::regex special_chars("[.^$|()*+?\\[\\]{}\\\\]");

Callers 2

find_stopping_stringsMethod · 0.85
try_find_literalMethod · 0.85

Calls 4

substrMethod · 0.80
string_ends_withFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected