mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix recursion depth: cstring algorithm
This commit is contained in:
parent
f26032dce8
commit
b51b14efa9
25 changed files with 792 additions and 142 deletions
|
@ -3,21 +3,22 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cstring/strchr.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcschr
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log N)
|
||||
//
|
||||
inline SPROUT_CONSTEXPR wchar_t const*
|
||||
wcschr(wchar_t const* s, int c) {
|
||||
return *s == static_cast<wchar_t>(c) ? s
|
||||
: !*s ? nullptr
|
||||
: sprout::wcschr(s + 1, c)
|
||||
;
|
||||
wcschr(wchar_t const* s, wchar_t c) {
|
||||
return sprout::strchr(s, c);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR wchar_t*
|
||||
wcschr(wchar_t* s, int c) {
|
||||
return const_cast<wchar_t*>(sprout::wcschr(const_cast<wchar_t const*>(s), c));
|
||||
wcschr(wchar_t* s, wchar_t c) {
|
||||
return sprout::strchr(s, c);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -2,21 +2,18 @@
|
|||
#define SPROUT_CWCHAR_WCSCMP_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cstring/strcmp.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcscmp
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
inline SPROUT_CONSTEXPR int
|
||||
wcscmp(wchar_t const* s1, wchar_t const* s2) {
|
||||
return !*s1 && !*s2 ? 0
|
||||
: !*s1 ? -1
|
||||
: !*s2 ? 1
|
||||
: *s1 == *s2 ? sprout::wcscmp(s1 + 1, s2 + 1)
|
||||
: *s1 - *s2
|
||||
;
|
||||
return sprout::strcmp(s1, s2);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -2,17 +2,18 @@
|
|||
#define SPROUT_CWCHAR_WCSCOLL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cwchar/wcscmp.hpp>
|
||||
#include <sprout/cstring/strcoll.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcscoll
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
inline SPROUT_CONSTEXPR int
|
||||
wcscoll(wchar_t const* s1, wchar_t const* s2) {
|
||||
return sprout::wcscmp(s1, s2);
|
||||
return sprout::strcoll(s1, s2);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,17 +3,18 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cwchar/wcschr.hpp>
|
||||
#include <sprout/cstring/strcspn.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// wcscspn
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcscspn(wchar_t const* s1, wchar_t const* s2) {
|
||||
return !*s1 || sprout::wcschr(s2, *s1) ? 0
|
||||
: 1 + sprout::wcscspn(s1 + 1, s2)
|
||||
;
|
||||
return sprout::strcspn(s1, s2);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,27 +3,22 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/ptr_index_iterator.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/algorithm/find.hpp>
|
||||
#include <sprout/cstring/strlen.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// wcslen
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log N)
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcslen(wchar_t const* s) {
|
||||
return !*s ? 0
|
||||
: 1 + sprout::wcslen(s + 1)
|
||||
;
|
||||
return sprout::strlen(s);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcslen(wchar_t const* s, std::size_t n) {
|
||||
return sprout::distance(
|
||||
sprout::as_iterator(s),
|
||||
sprout::find(sprout::as_iterator(s), sprout::as_iterator(s, n), L'\0')
|
||||
);
|
||||
return sprout::strlen(s, n);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,19 +3,18 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/ptr_index_iterator.hpp>
|
||||
#include <sprout/algorithm/tristate_lexicographical_compare.hpp>
|
||||
#include <sprout/cstring/strncmp.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// wcsncmp
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
inline SPROUT_CONSTEXPR int
|
||||
wcsncmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(s1), sprout::as_iterator(s1, n), L'\0',
|
||||
sprout::as_iterator(s2), sprout::as_iterator(s2, n), L'\0'
|
||||
);
|
||||
return sprout::strncmp(s1, s2, n);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,25 +3,22 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cwchar/wcschr.hpp>
|
||||
#include <sprout/cstring/strpbrk.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcspbrk
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
inline SPROUT_CONSTEXPR wchar_t const*
|
||||
wcspbrk(wchar_t const* s1, wchar_t const* s2) {
|
||||
return !*s1 ? nullptr
|
||||
: sprout::wcschr(s2, *s1) ? s1
|
||||
: sprout::wcspbrk(s1 + 1, s2)
|
||||
;
|
||||
return sprout::strpbrk(s1, s2);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR wchar_t*
|
||||
wcspbrk(wchar_t* s1, wchar_t const* s2) {
|
||||
return const_cast<wchar_t*>(sprout::wcspbrk(const_cast<wchar_t const*>(s1), s2));
|
||||
return sprout::strpbrk(s1, s2);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,24 +3,22 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cstring/strrchr.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcsrchr
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log N)
|
||||
//
|
||||
inline SPROUT_CONSTEXPR wchar_t const*
|
||||
wcsrchr(wchar_t const* s, int c) {
|
||||
return *s == static_cast<wchar_t>(c) && (!*s || !sprout::wcsrchr(s + 1, c))? s
|
||||
: !*s ? nullptr
|
||||
: sprout::wcsrchr(s + 1, c)
|
||||
;
|
||||
wcsrchr(wchar_t const* s, wchar_t c) {
|
||||
return sprout::strrchr(s, c);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR wchar_t*
|
||||
wcsrchr(wchar_t* s, int c) {
|
||||
return const_cast<wchar_t*>(sprout::wcsrchr(const_cast<wchar_t const*>(s), c));
|
||||
wcsrchr(wchar_t* s, wchar_t c) {
|
||||
return sprout::strrchr(s, c);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,17 +3,18 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cwchar/wcschr.hpp>
|
||||
#include <sprout/cstring/strspn.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// wcsspn
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcsspn(wchar_t const* s1, wchar_t const* s2) {
|
||||
return !*s1 || !sprout::wcschr(s2, *s1) ? 0
|
||||
: 1 + sprout::wcsspn(s1 + 1, s2)
|
||||
;
|
||||
return sprout::strspn(s1, s2);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -2,22 +2,22 @@
|
|||
#define SPROUT_CWCHAR_WCSSTR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cstring/strstr.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcsstr
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
inline SPROUT_CONSTEXPR wchar_t const*
|
||||
wcsstr(wchar_t const* s1, wchar_t const* s2) {
|
||||
return !*s2 ? s1
|
||||
: !*s1 ? nullptr
|
||||
: *s1 == *s2 && sprout::wcsstr(s1 + 1, s2 + 1) ? s1
|
||||
: sprout::wcsstr(s1 + 1, s2)
|
||||
;
|
||||
return sprout::strstr(s1, s2);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR wchar_t*
|
||||
wcsstr(wchar_t* s1, wchar_t const* s2) {
|
||||
return const_cast<wchar_t*>(sprout::wcsstr(const_cast<wchar_t const*>(s1), s2));
|
||||
return sprout::strstr(s1, s2);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue