mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 05:32:44 +00:00 
			
		
		
		
	AK: Add an overload of String::find_byte_offset for StringView
This commit is contained in:
		
							parent
							
								
									38b4e938b7
								
							
						
					
					
						commit
						c35b1371a3
					
				
					 3 changed files with 55 additions and 2 deletions
				
			
		|  | @ -8,6 +8,7 @@ | |||
| #include <AK/Checked.h> | ||||
| #include <AK/FlyString.h> | ||||
| #include <AK/Format.h> | ||||
| #include <AK/MemMem.h> | ||||
| #include <AK/String.h> | ||||
| #include <AK/StringBuilder.h> | ||||
| #include <AK/Utf8View.h> | ||||
|  | @ -328,6 +329,21 @@ Optional<size_t> String::find_byte_offset(u32 code_point, size_t from_byte_offse | |||
|     return {}; | ||||
| } | ||||
| 
 | ||||
| Optional<size_t> String::find_byte_offset(StringView substring, size_t from_byte_offset) const | ||||
| { | ||||
|     auto view = bytes_as_string_view(); | ||||
|     if (from_byte_offset >= view.length()) | ||||
|         return {}; | ||||
| 
 | ||||
|     auto index = memmem_optional( | ||||
|         view.characters_without_null_termination() + from_byte_offset, view.length() - from_byte_offset, | ||||
|         substring.characters_without_null_termination(), substring.length()); | ||||
| 
 | ||||
|     if (index.has_value()) | ||||
|         return *index + from_byte_offset; | ||||
|     return {}; | ||||
| } | ||||
| 
 | ||||
| bool String::operator==(String const& other) const | ||||
| { | ||||
|     if (is_short_string()) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn