mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix cstring, cwchar
This commit is contained in:
parent
8227569c43
commit
0670013702
17 changed files with 172 additions and 127 deletions
|
@ -6,6 +6,9 @@
|
|||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcscmp
|
||||
//
|
||||
inline SPROUT_CONSTEXPR int
|
||||
wcscmp(wchar_t const* s1, wchar_t const* s2) {
|
||||
return !*s1 && !*s2 ? 0
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
#define SPROUT_CWCHAR_WCSCOLL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cstring/strcmp.hpp>
|
||||
#include <sprout/cwchar/wcscmp.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcscoll
|
||||
//
|
||||
inline SPROUT_CONSTEXPR int
|
||||
wcscoll(wchar_t const* s1, wchar_t const* s2) {
|
||||
return sprout::wcscmp(s1, s2);
|
||||
|
|
|
@ -3,23 +3,17 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cstring/strchr.hpp>
|
||||
#include <sprout/cwchar/wcschr.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
namespace detail {
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcscspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
|
||||
return !*s1 || sprout::wcschr(s2, *s1) ? n
|
||||
: sprout::detail::wcscspn_impl(s1 + 1, s2, n + 1)
|
||||
;
|
||||
}
|
||||
} // amespace detail
|
||||
|
||||
//
|
||||
// wcscspn
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcscspn(wchar_t const* s1, wchar_t const* s2) {
|
||||
return sprout::detail::wcscspn_impl(s1, s2, 0);
|
||||
return !*s1 || sprout::wcschr(s2, *s1) ? 0
|
||||
: 1 + sprout::wcscspn(s1 + 1, s2)
|
||||
;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,14 +3,28 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/ptr_index_iterator.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// wcslen
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcslen(wchar_t const* s) {
|
||||
return !*s ? 0
|
||||
: 1 + sprout::wcslen(s + 1)
|
||||
;
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcslen(wchar_t const* s, std::size_t n) {
|
||||
return NS_SSCRISK_CEL_OR_SPROUT::distance(
|
||||
sprout::as_iterator(s),
|
||||
NS_SSCRISK_CEL_OR_SPROUT::find(sprout::as_iterator(s), sprout::as_iterator(s, n), L'\0')
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CWCHAR_WCSLEN_HPP
|
||||
|
|
|
@ -3,18 +3,21 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/ptr_index_iterator.hpp>
|
||||
#include <sprout/algorithm/tristate_lexicographical_compare.hpp>
|
||||
#include <sprout/cwchar/wcslen.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcsncmp
|
||||
//
|
||||
inline SPROUT_CONSTEXPR int
|
||||
wcsncmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
|
||||
return !n || (!*s1 && !*s2) ? 0
|
||||
: !*s1 ? -1
|
||||
: !*s2 ? 1
|
||||
: *s1 == *s2 ? sprout::wcsncmp(s1 + 1, s2 + 1, n - 1)
|
||||
: *s1 - *s2
|
||||
;
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(s1), sprout::as_iterator(s1, sprout::wcslen(s1, n)),
|
||||
sprout::as_iterator(s2), sprout::as_iterator(s2, sprout::wcslen(s2, n))
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,11 +3,14 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cstring/strchr.hpp>
|
||||
#include <sprout/cwchar/wcschr.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcspbrk
|
||||
//
|
||||
inline SPROUT_CONSTEXPR wchar_t const*
|
||||
wcspbrk(wchar_t const* s1, wchar_t const* s2) {
|
||||
return !*s1 ? nullptr
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// wcsrchr
|
||||
//
|
||||
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
|
||||
|
|
|
@ -1,26 +1,20 @@
|
|||
#ifndef SPROUT_CWCHAR_WCSSPN_HPP
|
||||
#define SPROUT_CWCHAR_XXX_HPP
|
||||
#define SPROUT_CWCHAR_WCSSPN_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/cstring/strchr.hpp>
|
||||
#include <sprout/cwchar/wcschr.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
namespace detail {
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcsspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
|
||||
return !*s1 || !sprout::wcschr(s2, *s1) ? n
|
||||
: sprout::detail::wcsspn_impl(s1 + 1, s2, n + 1)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// wcsspn
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
wcsspn(wchar_t const* s1, wchar_t const* s2) {
|
||||
return sprout::detail::wcsspn_impl(s1, s2, 0);
|
||||
return !*s1 || !sprout::wcschr(s2, *s1) ? 0
|
||||
: 1 + sprout::wcsspn(s1 + 1, s2)
|
||||
;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CWCHAR_XXX_HPP
|
||||
#endif // #ifndef SPROUT_CWCHAR_WCSSPN_HPP
|
||||
|
|
|
@ -3,28 +3,52 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/ptr_index_iterator.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
namespace detail {
|
||||
inline SPROUT_CONSTEXPR wchar_t const*
|
||||
wmemchr_impl(wchar_t const* s, wchar_t c, std::size_t n) {
|
||||
return !n ? 0
|
||||
: *s == c ? s
|
||||
: sprout::detail::wmemchr_impl(s + 1, c, n - 1)
|
||||
;
|
||||
wmemchr_impl(wchar_t const* found, wchar_t const* last) {
|
||||
return found == last ? nullptr
|
||||
: found
|
||||
;
|
||||
}
|
||||
inline SPROUT_CONSTEXPR wchar_t*
|
||||
wmemchr_impl(wchar_t* found, wchar_t* last) {
|
||||
return found == last ? nullptr
|
||||
: found
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// wmemchr
|
||||
//
|
||||
inline SPROUT_CONSTEXPR wchar_t const*
|
||||
wmemchr(wchar_t const* s, wchar_t c, size_t n) {
|
||||
return sprout::detail::wmemchr_impl(s, c, n);
|
||||
return sprout::detail::wmemchr_impl(
|
||||
sprout::as_iterator_base(
|
||||
NS_SSCRISK_CEL_OR_SPROUT::find(
|
||||
sprout::as_iterator(s), sprout::as_iterator(s, n),
|
||||
c
|
||||
)
|
||||
),
|
||||
s + n
|
||||
);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR wchar_t*
|
||||
wmemchr(wchar_t* s, wchar_t c, size_t n) {
|
||||
return const_cast<wchar_t*>(sprout::detail::wmemchr_impl(s, c, n));
|
||||
return sprout::detail::wmemchr_impl(
|
||||
sprout::as_iterator_base(
|
||||
NS_SSCRISK_CEL_OR_SPROUT::find(
|
||||
sprout::as_iterator(s), sprout::as_iterator(s, n),
|
||||
c
|
||||
)
|
||||
),
|
||||
s + n
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -3,23 +3,19 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/ptr_index_iterator.hpp>
|
||||
#include <sprout/algorithm/tristate_lexicographical_compare.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
namespace detail {
|
||||
inline SPROUT_CONSTEXPR int
|
||||
wmemcmp_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
|
||||
return !n ? 0
|
||||
: *s1 == *s2 ? sprout::detail::wmemcmp_impl(s1 + 1, s2 + 1, n - 1)
|
||||
: *s1 - *s2
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// wmemcmp
|
||||
//
|
||||
inline SPROUT_CONSTEXPR int
|
||||
wmemcmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
|
||||
return sprout::detail::wmemcmp_impl(s1, s2, n);
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(s1), sprout::as_iterator(s1, n),
|
||||
sprout::as_iterator(s2), sprout::as_iterator(s2, n)
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue