Alien-libpanda
view release on metacpan or search on metacpan
- new overloads for endian conversions
1.0.6 12.01.2018
- class panda::function - compareble version of std::function
- class CallbackDispatcher - implementation of observer pattern
- simple logger tools
1.0.5 08.09.2017
- string::append now can use COW in case of empty string
1.0.4 07.05.2017
- shared_ptr::operator bool is explicit now
1.0.3 16.05.2017
- fix default pos value for find_last_of, find_last_not_of
1.0.2 16.05.2017
- bugfix for stoX group of functions in case of no pos argument
1.0.1 15.05.2017
- do not bootstrap so library (no XS code inside), it will be loaded automatically because of "-l" linker flag
1.0.0 11.05.2017
- C++ code moved from Panda::Lib
src/panda/basic_string.h view on Meta::CPAN
size_type find_first_of (CharT ch, size_type pos = 0) const {
return find(ch, pos);
}
size_type find_first_of (basic_string_view<CharT, Traits> sv, size_type pos = 0) const {
return find_first_of(sv.data(), pos, sv.length());
}
template <class Alloc2>
size_type find_first_not_of (const basic_string<CharT, Traits, Alloc2>& str, size_type pos = 0) const {
return find_first_not_of(str._str, pos, str._length);
}
size_type find_first_not_of (const CharT* s, size_type pos, size_type count) const {
if (count == 0) return pos >= _length ? npos : pos;
const CharT* end = _str + _length;
for (const CharT* ptr = _str + pos; ptr < end; ++ptr) if (!traits_type::find(s, count, *ptr)) return ptr - _str;
return npos;
}
template<class _CharT, typename = typename std::enable_if<std::is_same<_CharT, CharT>::value>::type>
size_type find_first_not_of (const _CharT* const& s, size_type pos = 0) const {
return find_first_not_of(s, pos, traits_type::length(s));
}
template <size_type SIZE>
size_type find_first_not_of (const CharT (&s)[SIZE], size_type pos = 0) const {
return find_first_not_of(s, pos, SIZE-1);
}
size_type find_first_not_of (CharT ch, size_type pos = 0) const {
const CharT* end = _str + _length;
for (const CharT* ptr = _str + pos; ptr < end; ++ptr) if (!traits_type::eq(*ptr, ch)) return ptr - _str;
return npos;
}
size_type find_first_not_of (basic_string_view<CharT, Traits> sv, size_type pos = 0) const {
return find_first_not_of(sv.data(), pos, sv.length());
}
template <class Alloc2>
size_type find_last_of (const basic_string<CharT, Traits, Alloc2>& str, size_type pos = npos) const {
return find_last_of(str._str, pos, str._length);
}
size_type find_last_of (const CharT* s, size_type pos, size_type count) const {
if (count == 0) return npos;
for (const CharT* ptr = _str + (pos >= _length ? (_length - 1) : pos); ptr >= _str; --ptr)
src/panda/basic_string.h view on Meta::CPAN
size_type find_last_of (CharT ch, size_type pos = npos) const {
return rfind(ch, pos);
}
size_type find_last_of (basic_string_view<CharT, Traits> sv, size_type pos = npos) const {
return find_last_of(sv.data(), pos, sv.length());
}
template <class Alloc2>
size_type find_last_not_of (const basic_string<CharT, Traits, Alloc2>& str, size_type pos = npos) const {
return find_last_not_of(str._str, pos, str._length);
}
size_type find_last_not_of (const CharT* s, size_type pos, size_type count) const {
if (count == 0) return pos >= _length ? (_length-1) : pos;
for (const CharT* ptr = _str + (pos >= _length ? (_length - 1) : pos); ptr >= _str; --ptr)
if (!traits_type::find(s, count, *ptr)) return ptr - _str;
return npos;
}
template<class _CharT, typename = typename std::enable_if<std::is_same<_CharT, CharT>::value>::type>
size_type find_last_not_of (const _CharT* const& s, size_type pos = npos) const {
return find_last_not_of(s, pos, traits_type::length(s));
}
template <size_type SIZE>
size_type find_last_not_of (const CharT (&s)[SIZE], size_type pos = npos) const {
return find_last_not_of(s, pos, SIZE-1);
}
size_type find_last_not_of (CharT ch, size_type pos = npos) const {
for (const CharT* ptr = _str + (pos >= _length ? (_length - 1) : pos); ptr >= _str; --ptr)
if (!traits_type::eq(*ptr, ch)) return ptr - _str;
return npos;
}
size_type find_last_not_of (basic_string_view<CharT, Traits> sv, size_type pos = npos) const {
return find_last_not_of(sv.data(), pos, sv.length());
}
basic_string& append (size_type count, CharT ch) {
if (count) {
_reserve_save(_length + count);
traits_type::assign(_str + _length, count, ch);
_length += count;
}
return *this;
}
src/panda/basic_string_view.h view on Meta::CPAN
size_t find_last_of (const _CharT* const& s, size_t pos = 0) const {
return find_last_of(s, pos, traits_type::length(s));
}
template <size_t SIZE>
size_t find_last_of (const CharT (&s)[SIZE], size_t pos = 0) const {
return find_last_of(s, pos, SIZE-1);
}
size_t find_first_not_of (basic_string_view v, size_t pos = 0) const {
return find_first_not_of(v._str, pos, v._length);
}
size_t find_first_not_of (CharT ch, size_t pos = 0) const {
const CharT* end = _str + _length;
for (const CharT* ptr = _str + pos; ptr < end; ++ptr) if (!traits_type::eq(*ptr, ch)) return ptr - _str;
return npos;
}
size_t find_first_not_of (const CharT* s, size_t pos, size_t count) const {
if (count == 0) return pos >= _length ? npos : pos;
const CharT* end = _str + _length;
for (const CharT* ptr = _str + pos; ptr < end; ++ptr) if (!traits_type::find(s, count, *ptr)) return ptr - _str;
return npos;
}
template<class _CharT, typename = typename std::enable_if<std::is_same<_CharT, CharT>::value>::type>
size_t find_first_not_of (const _CharT* const& s, size_t pos = 0) const {
return find_first_not_of(s, pos, traits_type::length(s));
}
template <size_t SIZE>
size_t find_first_not_of (const CharT (&s)[SIZE], size_t pos = 0) const {
return find_first_not_of(s, pos, SIZE-1);
}
size_t find_last_not_of (basic_string_view v, size_t pos = 0) const {
return find_last_not_of(v._str, pos, v._length);
}
size_t find_last_not_of (CharT ch, size_t pos = 0) const {
for (const CharT* ptr = _str + (pos >= _length ? (_length - 1) : pos); ptr >= _str; --ptr)
if (!traits_type::eq(*ptr, ch)) return ptr - _str;
return npos;
}
size_t find_last_not_of (const CharT* s, size_t pos, size_t count) const {
if (count == 0) return pos >= _length ? (_length-1) : pos;
for (const CharT* ptr = _str + (pos >= _length ? (_length - 1) : pos); ptr >= _str; --ptr)
if (!traits_type::find(s, count, *ptr)) return ptr - _str;
return npos;
}
template<class _CharT, typename = typename std::enable_if<std::is_same<_CharT, CharT>::value>::type>
size_t find_last_not_of (const _CharT* const& s, size_t pos = 0) const {
return find_last_not_of(s, pos, traits_type::length(s));
}
template <size_t SIZE>
size_t find_last_not_of (const CharT (&s)[SIZE], size_t pos = 0) const {
return find_last_not_of(s, pos, SIZE-1);
}
private:
static int _compare (const CharT* ptr1, size_t len1, const CharT* ptr2, size_t len2) {
int r = traits_type::compare(ptr1, ptr2, std::min(len1, len2));
if (!r) r = (len1 < len2) ? -1 : (len1 > len2 ? 1 : 0);
return r;
}
t/string_test.h view on Meta::CPAN
REQUIRE(s.find_first_of(FString(cstr("o"))) == 1);
REQUIRE(s.find_first_of(FString(cstr("o")), 2) == 6);
REQUIRE(s.find_first_of(FString(cstr("o")), 14) == npos);
REQUIRE(s.find_first_of(FString(EMPTY), 0) == npos);
REQUIRE(s.find_first_of(FString(EMPTY), 15) == npos);
REQUIRE(s.find_first_of(FString(cstr("pnv"))) == 2);
REQUIRE(s.find_first_of(FString(cstr("pnv")), 3) == 5);
REQUIRE(s.find_first_of(FString(cstr("pnv")), 6) == 7);
REQUIRE(s.find_first_of(FString(cstr("pnv")), 8) == npos);
}
SECTION("find_first_not_of") {
REQUIRE(s.find_first_not_of(FString(cstr("o"))) == 0);
REQUIRE(s.find_first_not_of(FString(cstr("j"))) == 1);
REQUIRE(s.find_first_not_of(FString(cstr("o")), 1) == 2);
REQUIRE(s.find_first_not_of(FString(cstr("d")), 13) == npos);
REQUIRE(s.find_first_not_of(FString(EMPTY), 0) == 0);
REQUIRE(s.find_first_not_of(FString(EMPTY), 15) == npos);
REQUIRE(s.find_first_not_of(FString(cstr("jopa nviy"))) == 11);
REQUIRE(s.find_first_not_of(FString(cstr("og ")), 10) == 13);
REQUIRE(s.find_first_not_of(FString(cstr("ogd ")), 10) == npos);
}
SECTION("find_last_of") {
REQUIRE(s.find_last_of(FString(cstr("o"))) == 12);
REQUIRE(s.find_last_of(FString(cstr("o")), 9999) == 12);
REQUIRE(s.find_last_of(FString(cstr("o")), 10) == 6);
REQUIRE(s.find_last_of(FString(cstr("o")), 1) == 1);
REQUIRE(s.find_last_of(FString(cstr("o")), 0) == npos);
REQUIRE(s.find_last_of(FString(EMPTY), 0) == npos);
REQUIRE(s.find_last_of(FString(EMPTY), 15) == npos);
REQUIRE(s.find_last_of(FString(cstr("pnv"))) == 7);
REQUIRE(s.find_last_of(FString(cstr("pnv")), 6) == 5);
REQUIRE(s.find_last_of(FString(cstr("pnv")), 4) == 2);
REQUIRE(s.find_last_of(FString(cstr("pnv")), 1) == npos);
}
SECTION("find_last_not_of") {
REQUIRE(s.find_last_not_of(FString(cstr("o"))) == 13);
REQUIRE(s.find_last_not_of(FString(cstr("d"))) == 12);
REQUIRE(s.find_last_not_of(FString(cstr("d")), 9999) == 12);
REQUIRE(s.find_last_not_of(FString(cstr("d")), 12) == 12);
REQUIRE(s.find_last_not_of(FString(cstr("o")), 12) == 11);
REQUIRE(s.find_last_not_of(FString(cstr("j")), 0) == npos);
REQUIRE(s.find_last_not_of(FString(EMPTY), 0) == 0);
REQUIRE(s.find_last_not_of(FString(EMPTY), 13) == 13);
REQUIRE(s.find_last_not_of(FString(EMPTY), 14) == 13);
REQUIRE(s.find_last_not_of(FString(EMPTY), 15) == 13);
REQUIRE(s.find_last_not_of(FString(cstr("nviy god"))) == 3);
REQUIRE(s.find_last_not_of(FString(cstr("jpa ")), 4) == 1);
REQUIRE(s.find_last_not_of(FString(cstr("jopa ")), 4) == npos);
}
}
static void test_reserve () {
get_allocs();
SECTION("literal") {
get_allocs();
String s(LITERAL);
SECTION(">len") {
s.reserve(100);
( run in 0.535 second using v1.01-cache-2.11-cpan-cc502c75498 )