33 template <
typename T, T t,
unsigned int N>
37 static constexpr T value = (
extend<T,t,N-1U>::value << 8U ) | t ;
40 template <
typename T, T t>
43 static constexpr T value = t ;
49 inline constexpr bool operator()( T t )
const noexcept {
return ( t &
extend<T,0x80,
sizeof(T)>::value ) != 0 ; }
54 bool is8bit_imp_int(
const unsigned char * p , std::size_t n )
58 for( std::size_t i = 0U ; i < n ; i++ , j +=
sizeof(T) )
61 std::memcpy( &t , &p[j] ,
sizeof(T) ) ;
68 inline bool is8bit_imp_uchar(
const unsigned char * p0 , std::size_t n )
70 const unsigned char * end = p0 + n ;
71 return std::find_if( p0 , end , [](
char c){
return (c & 0x80U)!=0U ;} ) != end ;
74 inline bool is8bit_slow(
const unsigned char * p0 , std::size_t n )
76 return is8bit_imp_uchar( p0 , n ) ;
79 inline bool is8bit_faster(
const unsigned char * p0 , std::size_t n )
81 using byte_t =
unsigned char ;
82 using int_t =
unsigned long ;
83 const void * vp1 = G::align<int_t>( p0 , n ) ;
86 return is8bit_slow( p0 , n ) ;
91 const byte_t * p1 =
static_cast<const byte_t*
>(vp1) ;
92 const std::size_t n0 = std::distance( p0 , p1 ) ;
93 const std::size_t n1 = G::align_mask<int_t>( n - n0 ) ;
94 const std::size_t ni1 = G::align_shift<int_t>( n - n0 ) ;
95 const std::size_t n2 = n - n0 - n1 ;
96 const byte_t * p2 = p0 + n0 + n1 ;
98 is8bit_imp_uchar(p0,n0) ||
99 is8bit_imp_int<int_t>(p1,ni1) ||
100 is8bit_imp_uchar(p2,n2) ;
108 inline bool eightbit(
const unsigned char * p , std::size_t n )
110 namespace imp = EightBitImp ;
111 return imp::is8bit_faster( p , n ) ;
117 inline bool eightbit(
const char * p , std::size_t n )
119 namespace imp = EightBitImp ;
120 return imp::is8bit_faster(
reinterpret_cast<const unsigned char *
>(p) , n ) ;
126 inline bool eightbit(
const unsigned char * p , std::size_t n ,
int )
128 namespace imp = EightBitImp ;
129 return imp::is8bit_slow( p , n ) ;
135 inline bool eightbit(
const char * p , std::size_t n ,
int )
137 namespace imp = EightBitImp ;
138 return imp::is8bit_slow(
reinterpret_cast<const unsigned char *
>(p) , n ) ;
bool eightbit(const unsigned char *p, std::size_t n)
Returns true if the given data buffer contains a byte greater than 127.
Evaluates a type 'T' bitmask comprising N copies of byte 't'.
Functor returning true if 't' AND-ed with an extend mask based on 0x80 is non-zero.