1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-10-05 13:00:00 +00:00

porting sscrisk/CEL

This commit is contained in:
bolero-MURAKAMI 2012-04-01 22:15:09 +09:00
commit db20f64991
181 changed files with 2531 additions and 607 deletions

31
sprout/cstring/memchr.hpp Normal file
View file

@ -0,0 +1,31 @@
#ifndef SPROUT_CSTRING_MEMCHR_HPP
#define SPROUT_CSTRING_MEMCHR_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR void const* memchr_impl(unsigned char const* s, char c, std::size_t n) {
return !n ? 0
: *s == c ? s
: sprout::detail::memchr_impl(s + 1, c, n - 1)
;
}
} // namespace detail
// 7.21.5.1 memchr ŠÖ<C5A0>
inline SPROUT_CONSTEXPR void const* memchr(void const* s, int c, size_t n) {
return sprout::detail::memchr_impl(static_cast<unsigned char const*>(s), static_cast<unsigned char>(c), n);
}
inline SPROUT_CONSTEXPR void* memchr(void* s, int c, size_t n) {
return const_cast<void*>(
sprout::detail::memchr_impl(static_cast<unsigned char*>(s), static_cast<unsigned char>(c), n)
);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_MEMCHR_HPP

29
sprout/cstring/memcmp.hpp Normal file
View file

@ -0,0 +1,29 @@
#ifndef SPROUT_CSTRING_MEMCMP_HPP
#define SPROUT_CSTRING_MEMCMP_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR int memcmp_impl(unsigned char const* s1, unsigned char const* s2, std::size_t n) {
return !n ? 0
: *s1 == *s2 ? sprout::detail::memcmp_impl(s1 + 1, s2 + 1, n - 1)
: *s1 - *s2
;
}
} // namespace detail
// 7.21.4.1 memcmp ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int memcmp(void const * s1, void const * s2, std::size_t n) {
return sprout::detail::memcmp_impl(
static_cast<unsigned char const*>(s1),
static_cast<unsigned char const*>(s2),
n
);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_MEMCMP_HPP

23
sprout/cstring/strchr.hpp Normal file
View file

@ -0,0 +1,23 @@
#ifndef SPROUT_CSTRING_STRCHR_HPP
#define SPROUT_CSTRING_STRCHR_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.5.2 strchr ŠÖ<C5A0>
inline SPROUT_CONSTEXPR char const* strchr(char const* s, int c) {
return *s == static_cast<char>(c) ? s
: !*s ? nullptr
: sprout::strchr(s + 1, c)
;
}
inline SPROUT_CONSTEXPR char* strchr(char* s, int c) {
return const_cast<char*>(sprout::strchr(const_cast<char const*>(s), c));
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRCHR_HPP

20
sprout/cstring/strcmp.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef SPROUT_CSTRING_STRCMP_HPP
#define SPROUT_CSTRING_STRCMP_HPP
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.2 strcmp ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int strcmp(char const* s1, char const* s2) {
return !*s1 && !*s2 ? 0
: !*s1 ? -1
: !*s2 ? 1
: *s1 == *s2 ? sprout::strcmp(s1 + 1, s2 + 1)
: static_cast<unsigned char>(*s1) - static_cast<unsigned char>(*s2)
;
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRCMP_HPP

View file

@ -0,0 +1,16 @@
#ifndef SPROUT_CSTRING_STRCOLL_HPP
#define SPROUT_CSTRING_STRCOLL_HPP
#include <sprout/config.hpp>
#include <sprout/cstring/strcmp.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.3 strcoll ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int strcoll(char const* s1, char const* s2) {
return sprout::strcmp(s1, s2);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRCOLL_HPP

View file

@ -0,0 +1,25 @@
#ifndef SPROUT_CSTRING_STRCSPN_HPP
#define SPROUT_CSTRING_STRCSPN_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstring/strchr.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t strcspn_impl(char const* s1, char const* s2, std::size_t n) {
return !*s1 || sprout::strchr(s2, *s1) ? n
: sprout::detail::strcspn_impl(s1 + 1, s2, n + 1)
;
}
} // amespace detail
// 7.21.5.3 strcspn ŠÖ<C5A0>
inline SPROUT_CONSTEXPR std::size_t strcspn(char const* s1, char const* s2) {
return sprout::detail::strcspn_impl(s1, s2, 0);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRCSPN_HPP

24
sprout/cstring/strlen.hpp Normal file
View file

@ -0,0 +1,24 @@
#ifndef SPROUT_CSTRING_STRLEN_HPP
#define SPROUT_CSTRING_STRLEN_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t strlen_impl(char const* s, std::size_t n) {
return !*s ? n :
sprout::detail::strlen_impl(s + 1, n + 1)
;
}
} // namespace detail
// 7.21.6.3 strlen ŠÖ<C5A0>
inline SPROUT_CONSTEXPR std::size_t strlen(char const* s) {
return sprout::detail::strlen_impl(s, 0);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRLEN_HPP

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_CSTRING_STRNCMP_HPP
#define SPROUT_CSTRING_STRNCMP_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.4.4 strncmp ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int strncmp(char const* s1, char const* s2, std::size_t n) {
return !n || (!*s1 && !*s2) ? 0
: !*s1 ? -1
: !*s2 ? 1
: *s1 == *s2 ? sprout::strncmp(s1 + 1, s2 + 1, n - 1)
: static_cast<unsigned char>(*s1) - static_cast<unsigned char>(*s2)
;
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRNCMP_HPP

View file

@ -0,0 +1,24 @@
#ifndef SPROUT_CSTRING_STRPBRK_HPP
#define SPROUT_CSTRING_STRPBRK_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstring/strchr.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.5.4 strpbrk ŠÖ<C5A0>
inline SPROUT_CONSTEXPR char const* strpbrk(char const* s1, char const* s2) {
return !*s1 ? nullptr
: sprout::strchr(s2, *s1) ? s1
: sprout::strpbrk(s1 + 1, s2)
;
}
inline SPROUT_CONSTEXPR char* strpbrk(char* s1, char const* s2) {
return const_cast<char*>(sprout::strpbrk(const_cast<char const*>(s1), s2));
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRPBRK_HPP

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_CSTRING_STRRCHR_HPP
#define SPROUT_CSTRING_STRRCHR_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.5.5 strrchr ŠÖ<C5A0>
inline SPROUT_CONSTEXPR char const* strrchr(char const* s, int c) {
return *s == static_cast<char>(c) && (!*s || !sprout::strrchr(s + 1, c))? s
: !*s ? nullptr
: sprout::strrchr(s + 1, c)
;
}
inline SPROUT_CONSTEXPR char* strrchr(char* s, int c) {
return const_cast<char*>(sprout::strrchr(const_cast<char const*>(s), c));
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRRCHR_HPP

25
sprout/cstring/strspn.hpp Normal file
View file

@ -0,0 +1,25 @@
#ifndef SPROUT_CSTRING_STRSPN_HPP
#define SPROUT_CSTRING_XXX_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstring/strchr.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR std::size_t strspn_impl(char const* s1, char const* s2, std::size_t n) {
return !*s1 || !sprout::strchr(s2, *s1) ? n
: sprout::detail::strspn_impl(s1 + 1, s2, n + 1)
;
}
} // namespace detail
// 7.21.5.6 strspn ŠÖ<C5A0>
inline SPROUT_CONSTEXPR std::size_t strspn(char const* s1, char const* s2) {
return sprout::detail::strspn_impl(s1, s2, 0);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_XXX_HPP

23
sprout/cstring/strstr.hpp Normal file
View file

@ -0,0 +1,23 @@
#ifndef SPROUT_CSTRING_STRSTR_HPP
#define SPROUT_CSTRING_STRSTR_HPP
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 7.21.5.7 strstr ŠÖ<C5A0>
inline SPROUT_CONSTEXPR char const* strstr(char const* s1, char const* s2) {
return !*s2 ? s1
: !*s1 ? nullptr
: *s1 == *s2 && sprout::strstr(s1 + 1, s2 + 1) ? s1
: sprout::strstr(s1 + 1, s2)
;
}
inline SPROUT_CONSTEXPR char* strstr(char* s1, char const* s2) {
return const_cast<char*>(sprout::strstr(const_cast<char const*>(s1), s2));
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_STRSTR_HPP