mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-11-03 09:22:01 +00:00 
			
		
		
		
	llama : better replace_all (#8852)
This commit is contained in:
		@@ -122,17 +122,14 @@ static std::string trim(const std::string & str) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void replace_all(std::string & s, const std::string & search, const std::string & replace) {
 | 
			
		||||
    std::string result;
 | 
			
		||||
    for (size_t pos = 0; ; pos += search.length()) {
 | 
			
		||||
        auto new_pos = s.find(search, pos);
 | 
			
		||||
        if (new_pos == std::string::npos) {
 | 
			
		||||
            result += s.substr(pos, s.size() - pos);
 | 
			
		||||
            break;
 | 
			
		||||
    if (search.empty()) {
 | 
			
		||||
        return; // Avoid infinite loop if 'search' is an empty string
 | 
			
		||||
    }
 | 
			
		||||
        result += s.substr(pos, new_pos - pos) + replace;
 | 
			
		||||
        pos = new_pos;
 | 
			
		||||
    size_t pos = 0;
 | 
			
		||||
    while ((pos = s.find(search, pos)) != std::string::npos) {
 | 
			
		||||
        s.replace(pos, search.length(), replace);
 | 
			
		||||
        pos += replace.length();
 | 
			
		||||
    }
 | 
			
		||||
    s = std::move(result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool is_float_close(float a, float b, float abs_tol) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user