Alien-libpanda

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
           - 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

745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
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

807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
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

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
    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

1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
        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.297 second using v1.01-cache-2.11-cpan-26ccb49234f )