@@ -208,20 +208,19 @@ class ps_ptr {
208208 }
209209// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
210210// 📌📌📌 S W A P 📌📌📌
211-
212211 // A.swap(B);
213212 void swap (ps_ptr<T>& other) noexcept {
214213 std::swap (this ->mem , other.mem );
215214 std::swap (this ->allocated_size , other.allocated_size );
216215 }
217216// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
218217// 📌📌📌 S W A P W I T H R A W P O I N T E R 📌📌📌
219- void swap_with_pointer (T*& raw_ptr) noexcept {
220- T* temp = get ();
221- mem.release (); // Gib Besitz auf, ohne zu löschen
222- mem = std::unique_ptr<T, PsramDeleter>(raw_ptr); // Übernehme neuen Zeiger
223- raw_ptr = temp;
224- }
218+ void swap_with_pointer (T*& raw_ptr) noexcept {
219+ T* temp = get ();
220+ mem.release (); // Gib Besitz auf, ohne zu löschen
221+ mem = std::unique_ptr<T, PsramDeleter>(raw_ptr); // Übernehme neuen Zeiger
222+ raw_ptr = temp;
223+ }
225224// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
226225 // 📌📌📌 A P P E N D 📌📌📌
227226
@@ -230,9 +229,9 @@ void swap_with_pointer(T*& raw_ptr) noexcept {
230229 // text1.append(", Welt!");
231230 // printf("%s\n", text1.get()); // → "Hallo, Welt!"
232231
233- template <typename U = T>// Only activate if T = char, similar to strcat
234- typename std::enable_if<std::is_same< U, char >::value, void >::type
235- append (const char * suffix) {
232+ template <typename U = T>
233+ requires std::is_same_v< U, char >
234+ void append (const char * suffix) {
236235 if (!suffix || !*suffix) return ;
237236
238237 std::size_t old_len = mem ? std::strlen (static_cast <char *>(mem.get ())) : 0 ;
@@ -271,16 +270,13 @@ void swap_with_pointer(T*& raw_ptr) noexcept {
271270
272271 // Only for T = Char: Check whether the string begins with the given prefix
273272 template <typename U = T>
274- typename std::enable_if<std::is_same< U, char >::value, bool >::type
275- starts_with (const char * prefix) const {
273+ requires std::is_same_v< U, char >
274+ bool starts_with (const char * prefix) const {
276275 if (!mem || !prefix) return false ;
277276
278277 const char * str = static_cast <const char *>(mem.get ());
279- std::size_t prefix_len = std::strlen (prefix);
280- std::size_t str_len = std::strlen (str);
281- if (prefix_len > str_len) return false ;
282-
283- return std::strncmp (str, prefix, prefix_len) == 0 ;
278+ std::string_view sv (str); // C++17, sicherer als strlen
279+ return sv.starts_with (prefix);
284280 }
285281// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
286282 // 📌📌📌 E N D S _ W I T H 📌📌📌
@@ -295,16 +291,13 @@ void swap_with_pointer(T*& raw_ptr) noexcept {
295291
296292 // Only for T = Char: Check whether the string ends with the given suffix
297293 template <typename U = T>
298- typename std::enable_if<std::is_same< U, char >::value, bool >::type
299- ends_with (const char * suffix ) const {
300- if (!mem || !suffix ) return false ;
294+ requires std::is_same_v< U, char >
295+ bool ends_with (const char * prefix ) const {
296+ if (!mem || !prefix ) return false ;
301297
302298 const char * str = static_cast <const char *>(mem.get ());
303- std::size_t suffix_len = std::strlen (suffix);
304- std::size_t str_len = std::strlen (str);
305- if (suffix_len > str_len) return false ;
306-
307- return std::strncmp (str + str_len - suffix_len, suffix, suffix_len) == 0 ;
299+ std::string_view sv (str); // C++17, sicherer als strlen
300+ return sv.ends_with (prefix);
308301 }
309302// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
310303 // 📌📌📌 S T A R T S _ W I T H _ I C A S E 📌📌📌
@@ -319,8 +312,8 @@ void swap_with_pointer(T*& raw_ptr) noexcept {
319312
320313 // case non-sensitive: starts with Prefix?
321314 template <typename U = T>
322- typename std::enable_if<std::is_same< U, char >::value, bool >::type
323- starts_with_icase (const char * prefix) const {
315+ requires std::is_same_v< U, char >
316+ bool starts_with_icase (const char * prefix) const {
324317 if (!mem || !prefix) return false ;
325318
326319 const char * str = static_cast <const char *>(mem.get ());
@@ -340,29 +333,29 @@ void swap_with_pointer(T*& raw_ptr) noexcept {
340333 // printf("MP3 recognized (case-insensitive)\n");
341334 // }
342335
343- // case non-sensitive: ends with suffix?
344- template <typename U = T>
345- typename std::enable_if<std::is_same< U, char >::value, bool >::type
346- ends_with_icase (const char * suffix) const {
347- if (!mem || !suffix) return false ;
336+ // case non-sensitive: ends with suffix?
337+ template <typename U = T>
338+ requires std::is_same_v< U, char >
339+ bool ends_with_icase (const char * suffix) const {
340+ if (!mem || !suffix) return false ;
348341
349- const char * str = static_cast <const char *>(mem.get ());
350- std::size_t suffix_len = std::strlen (suffix);
351- std::size_t str_len = std::strlen (str);
352- if (suffix_len > str_len) return false ;
342+ const char * str = static_cast <const char *>(mem.get ());
343+ std::size_t suffix_len = std::strlen (suffix);
344+ std::size_t str_len = std::strlen (str);
345+ if (suffix_len > str_len) return false ;
353346
354- return strncasecmp_local (str + str_len - suffix_len, suffix, suffix_len) == 0 ;
355- }
347+ return strncasecmp_local (str + str_len - suffix_len, suffix, suffix_len) == 0 ;
348+ }
356349// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
357350 // 📌📌📌 F O R M A T 📌📌📌
358351
359352 // ps_ptr<char> greeting;
360353 // greeting.format("Value: %d, Text: %s", 42, "Hello"); // sprintf
361354 // printf("%s\n", greeting.get()); // → Wert: 42, Text: Hello
362355
363- template <typename U = T> // Only activate if T = char
364- typename std::enable_if<std::is_same< U, char >::value, void >::type
365- format (const char * fmt, ...) {
356+ template <typename U = T>
357+ requires std::is_same_v< U, char >
358+ void format (const char * fmt, ...) {
366359 if (!fmt) return ;
367360
368361 va_list args;
@@ -399,8 +392,8 @@ ends_with_icase(const char* suffix) const {
399392
400393 // Nur aktivieren, wenn T = char
401394 template <typename U = T>
402- typename std::enable_if<std::is_same< U, char >::value, void >::type
403- appendf (const char * fmt, ...) {
395+ requires std::is_same_v< U, char >
396+ void appendf (const char * fmt, ...) {
404397 if (!fmt) return ;
405398
406399 // Formatstring vorbereiten
@@ -483,8 +476,8 @@ ends_with_icase(const char* suffix) const {
483476
484477 // Specialized version: only for T = char (search for individual characters)
485478 template <typename U = T>
486- typename std::enable_if<std::is_same< U, char >::value, int >::type
487- index_of (char ch, std::size_t start = 0 ) const {
479+ requires std::is_same_v< U, char >
480+ int index_of (char ch, std::size_t start = 0 ) const {
488481 if (!mem) return -1 ;
489482
490483 const char * str = static_cast <const char *>(mem.get ());
@@ -498,8 +491,8 @@ ends_with_icase(const char* suffix) const {
498491 }
499492 // Overload for const char* (substring search)
500493 template <typename U = T>
501- typename std::enable_if<std::is_same< U, char >::value, int >::type
502- index_of (const char * substr, std::size_t start = 0 ) const {
494+ requires std::is_same_v< U, char >
495+ int index_of (const char * substr, std::size_t start = 0 ) const {
503496 if (!mem || !substr || !*substr) return -1 ;
504497
505498 const char * str = static_cast <const char *>(mem.get ());
@@ -524,8 +517,8 @@ ends_with_icase(const char* suffix) const {
524517
525518 // Case-insensitive substring search
526519 template <typename U = T>
527- typename std::enable_if<std::is_same< U, char >::value, int >::type
528- index_of_icase (const char * substr, std::size_t start = 0 ) const {
520+ requires std::is_same_v< U, char >
521+ int index_of_icase (const char * substr, std::size_t start = 0 ) const {
529522 if (!mem || !substr || !*substr) return -1 ;
530523
531524 const char * str = static_cast <const char *>(mem.get ());
@@ -549,8 +542,8 @@ ends_with_icase(const char* suffix) const {
549542 // 📌📌📌 L A S T _ I N D E X _ O F 📌📌📌
550543
551544 template <typename U = T>
552- typename std::enable_if<std::is_same< U, char >::value, int >::type
553- last_index_of (char ch) const {
545+ requires std::is_same_v< U, char >
546+ int last_index_of (char ch) const {
554547 if (!mem) return -1 ;
555548
556549 const char * str = static_cast <const char *>(mem.get ());
@@ -588,8 +581,8 @@ ends_with_icase(const char* suffix) const {
588581 // printf("ID3 found at: %d\n", pos1);
589582
590583 template <typename U = T>
591- typename std::enable_if<std::is_same< U, char >::value, int >::type
592- index_of_substr (const char * needle, std::size_t max_pos = SIZE_MAX) const {
584+ requires std::is_same_v< U, char >
585+ int index_of_substr (const char * needle, std::size_t max_pos = SIZE_MAX) const {
593586 if (!mem || !needle || !*needle) return -1 ;
594587
595588 const char * haystack = static_cast <const char *>(mem.get ());
@@ -614,8 +607,8 @@ ends_with_icase(const char* suffix) const {
614607 // text.strlen(); // --> 5
615608
616609 template <typename U = T>
617- typename std::enable_if<std::is_same< U, char >::value, std:: size_t >::type
618- strlen () const {
610+ requires std::is_same_v< U, char >
611+ size_t strlen () const {
619612 if (!valid ()) return 0 ;
620613 return std::strlen (get ());
621614 }
@@ -758,9 +751,9 @@ ends_with_icase(const char* suffix) const {
758751 // 📌📌📌 S H R I N K _ T O _ F I T 📌📌📌
759752
760753 // Only for Char: Put the buffer on the actual length +1 (for \ 0)
761- template <typename U = T>
762- typename std::enable_if<std::is_same< U, char >::value, void >::type
763- shrink_to_fit () {
754+ template <typename U = T>
755+ requires std::is_same_v< U, char >
756+ void shrink_to_fit () {
764757 if (!mem) return ;
765758 std::size_t len = std::strlen (get ());
766759 if (len == 0 ) return ;
@@ -780,9 +773,9 @@ ends_with_icase(const char* suffix) const {
780773 // ps_ptr<char> addr = "0x1A3B";
781774 // uint64_t val = addr.to_uint64(16);
782775
783- template <typename U = T>
784- typename std::enable_if<std::is_same< U, char >::value, uint64_t >::type
785- to_uint64 (int base = 10 ) const {
776+ template <typename U = T>
777+ requires std::is_same_v< U, char >
778+ uint64_t to_uint64 (int base = 10 ) const {
786779 if (!mem || !get ()) return 0 ;
787780
788781 char * end = nullptr ;
@@ -853,8 +846,8 @@ ends_with_icase(const char* suffix) const {
853846 // text3.trim(); // → "Hello, World!"
854847
855848 template <typename U = T>
856- typename std::enable_if<std::is_same< U, char >::value, void >::type
857- trim () {
849+ requires std::is_same_v< U, char >
850+ void trim () {
858851 if (!mem) return ;
859852
860853 char * str = static_cast <char *>(mem.get ());
@@ -886,7 +879,7 @@ ends_with_icase(const char* suffix) const {
886879// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
887880 // 📌📌📌 S I Z E 📌📌📌
888881
889- std:: size_t size () const { return allocated_size; }
882+ size_t size () const { return allocated_size; }
890883
891884// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
892885 // 📌📌📌 V A L I D 📌📌📌
0 commit comments