[ox/std] Add toStdStringView and endsWith functions
This commit is contained in:
		
							
								
								
									
										10
									
								
								deps/ox/src/ox/std/stringview.hpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								deps/ox/src/ox/std/stringview.hpp
									
									
									
									
										vendored
									
									
								
							| @@ -8,6 +8,10 @@ | |||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
|  | #ifdef OX_USE_STDLIB | ||||||
|  | #include <string_view> | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #include "iterator.hpp" | #include "iterator.hpp" | ||||||
| #include "strops.hpp" | #include "strops.hpp" | ||||||
| #include "types.hpp" | #include "types.hpp" | ||||||
| @@ -264,6 +268,12 @@ constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept { | |||||||
| 	return base.len() >= endingLen && ox_strcmp(base.data() + (base.len() - endingLen), ending) == 0; | 	return base.len() >= endingLen && ox_strcmp(base.data() + (base.len() - endingLen), ending) == 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #ifdef OX_USE_STDLIB | ||||||
|  | constexpr auto toStdStringView(CRStringView sv) noexcept { | ||||||
|  | 	return std::string_view(sv.data(), sv.bytes()); | ||||||
|  | } | ||||||
|  | #endif | ||||||
|  |  | ||||||
| static_assert(StringView("Read").bytes() == 4); | static_assert(StringView("Read").bytes() == 4); | ||||||
| static_assert(StringView("Read") == StringView("Read")); | static_assert(StringView("Read") == StringView("Read")); | ||||||
| static_assert(StringView("Read") != StringView("Write")); | static_assert(StringView("Read") != StringView("Write")); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user