@@ -2667,6 +2667,7 @@ namespace etl
2667
2667
// / Returns a pointer to the character after the last copied.
2668
2668
// *********************************************************************
2669
2669
template <typename TIterator1, typename TIterator2>
2670
+ static
2670
2671
typename etl::enable_if<etl::is_pointer<TIterator1>::value && etl::is_pointer<TIterator2>::value, TIterator2>::type
2671
2672
copy_characters (TIterator1 from, size_t n, TIterator2 to)
2672
2673
{
@@ -2680,6 +2681,7 @@ namespace etl
2680
2681
// / Returns an iterator to the character after the last copied.
2681
2682
// *********************************************************************
2682
2683
template <typename TIterator1, typename TIterator2>
2684
+ static
2683
2685
typename etl::enable_if<!etl::is_pointer<TIterator1>::value || !etl::is_pointer<TIterator2>::value, TIterator2>::type
2684
2686
copy_characters (TIterator1 from, size_t n, TIterator2 to)
2685
2687
{
@@ -2694,6 +2696,39 @@ namespace etl
2694
2696
return to;
2695
2697
}
2696
2698
2699
+ // *********************************************************************
2700
+ // / get_string_length, optimised for sizeof(U) == sizeof(char).
2701
+ // *********************************************************************
2702
+ template <typename U>
2703
+ static
2704
+ typename etl::enable_if<sizeof (U) == sizeof (char ), size_t >::type
2705
+ get_string_length (const U* src)
2706
+ {
2707
+ return ::strlen (reinterpret_cast <const char *>(src));
2708
+ }
2709
+
2710
+ // *********************************************************************
2711
+ // / get_string_length, optimised for sizeof(U) == sizeof(wchar_t).
2712
+ // *********************************************************************
2713
+ template <typename U>
2714
+ static
2715
+ typename etl::enable_if<sizeof (U) == sizeof (wchar_t ), size_t >::type
2716
+ get_string_length (const U* src)
2717
+ {
2718
+ return ::wcslen (reinterpret_cast <const wchar_t *>(src));
2719
+ }
2720
+
2721
+ // *********************************************************************
2722
+ // / get_string_length, optimised for anything else.
2723
+ // *********************************************************************
2724
+ template <typename U>
2725
+ static
2726
+ typename etl::enable_if<(sizeof (U) != sizeof (char )) && (sizeof (U) != sizeof (wchar_t )), size_t >::type
2727
+ get_string_length (const U* src)
2728
+ {
2729
+ return etl::strlen (src);
2730
+ }
2731
+
2697
2732
// *********************************************************************
2698
2733
// / Common implementation for 'assign' and 'append' for iterators.
2699
2734
// *********************************************************************
@@ -2733,20 +2768,30 @@ namespace etl
2733
2768
}
2734
2769
2735
2770
// *********************************************************************
2736
- // / Common implementation for 'assign' and 'append' for single pointer.
2771
+ // / Common implementation for 'assign' and 'append' for C string pointer.
2737
2772
// *********************************************************************
2738
- void append_impl (iterator position, const_pointer first , bool truncated, bool secure)
2773
+ void append_impl (iterator position, const_pointer src , bool truncated, bool secure)
2739
2774
{
2775
+ if (src == ETL_NULLPTR)
2776
+ {
2777
+ clear ();
2778
+ return ;
2779
+ }
2780
+
2740
2781
difference_type start = etl::distance (p_buffer, position);
2741
2782
difference_type free_space = etl::distance (position, p_buffer + CAPACITY);
2742
2783
2743
- etl::str_n_copy_result result = etl::str_n_copy (first, size_t (free_space), position);
2784
+ pointer dst = position;
2785
+ size_t length = get_string_length (src);
2786
+ size_t count = (length < size_t (free_space)) ? length : size_t (free_space);
2787
+ etl::mem_copy (src, count, dst);
2744
2788
2745
- current_size = size_t (start) + result.count ;
2789
+ truncated |= (src[count] != 0 );
2790
+ current_size = size_t (start) + count;
2746
2791
p_buffer[current_size] = 0 ;
2747
2792
2748
2793
#if ETL_HAS_STRING_TRUNCATION_CHECKS
2749
- set_truncated (result. truncated || truncated);
2794
+ set_truncated (truncated);
2750
2795
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
2751
2796
ETL_ASSERT (is_truncated == false , ETL_ERROR (string_truncation));
2752
2797
#endif
0 commit comments