1 // Copyright (c) 2018 Dr. Colin Hirsch and Daniel Frey 2 // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ 3 4 #ifndef TAO_PEGTL_CONTRIB_ICU_INTERNAL_HPP 5 #define TAO_PEGTL_CONTRIB_ICU_INTERNAL_HPP 6 7 #include <unicode/uchar.h> 8 9 #include "../../config.hpp" 10 11 #include "../../analysis/generic.hpp" 12 #include "../../internal/skip_control.hpp" 13 14 namespace tao 15 { 16 namespace TAO_PEGTL_NAMESPACE 17 { 18 namespace internal 19 { 20 namespace icu 21 { 22 template< typename Peek, UProperty P, bool V = true > 23 struct binary_property 24 { 25 using analyze_t = analysis::generic< analysis::rule_type::ANY >; 26 27 template< typename Input > matchtao::TAO_PEGTL_NAMESPACE::internal::icu::binary_property28 static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) ) 29 { 30 if( const auto r = Peek::peek( in ) ) { 31 if( u_hasBinaryProperty( r.data, P ) == V ) { 32 in.bump( r.size ); 33 return true; 34 } 35 } 36 return false; 37 } 38 }; 39 40 template< typename Peek, UProperty P, int V > 41 struct property_value 42 { 43 using analyze_t = analysis::generic< analysis::rule_type::ANY >; 44 45 template< typename Input > matchtao::TAO_PEGTL_NAMESPACE::internal::icu::property_value46 static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) ) 47 { 48 if( const auto r = Peek::peek( in ) ) { 49 if( u_getIntPropertyValue( r.data, P ) == V ) { 50 in.bump( r.size ); 51 return true; 52 } 53 } 54 return false; 55 } 56 }; 57 58 } // namespace icu 59 60 template< typename Peek, UProperty P, bool V > 61 struct skip_control< icu::binary_property< Peek, P, V > > : std::true_type 62 { 63 }; 64 65 template< typename Peek, UProperty P, int V > 66 struct skip_control< icu::property_value< Peek, P, V > > : std::true_type 67 { 68 }; 69 70 } // namespace internal 71 72 } // namespace TAO_PEGTL_NAMESPACE 73 74 } // namespace tao 75 76 #endif 77