@@ -61,11 +61,35 @@ protected override string GetValueBitMaskEarlyExit<T>(MethodType methodType, ulo
6161 """ ;
6262 }
6363
64- protected override string GetLengthEarlyExit ( MethodType methodType , uint min , uint max , uint minByte , uint maxByte ) =>
65- $ """
66- if ({ ( min . Equals ( max ) ? $ "key.length() != { map . ToValueLabel ( max ) } " : $ "const size_t len = key.length(); len < { map . ToValueLabel ( min ) } || len > { map . ToValueLabel ( max ) } ") } )
67- { RenderExit ( methodType ) }
68- """ ;
64+ protected override string GetLengthEarlyExit ( MethodType methodType , uint min , uint max , uint minByte , uint maxByte , GeneratorEncoding encoding )
65+ {
66+ uint minLen ;
67+ uint maxLen ;
68+
69+ switch ( encoding )
70+ {
71+ case GeneratorEncoding . ASCII :
72+ case GeneratorEncoding . UTF8 :
73+ minLen = minByte ;
74+ maxLen = maxByte ;
75+ break ;
76+ case GeneratorEncoding . UTF32 :
77+ minLen = minByte / 4 ;
78+ maxLen = maxByte / 4 ;
79+ break ;
80+ case GeneratorEncoding . UTF16 :
81+ minLen = min ;
82+ maxLen = max ;
83+ break ;
84+ default :
85+ throw new InvalidOperationException ( "Unsupported encoding: " + encoding ) ;
86+ }
87+
88+ return $ """
89+ if ({ ( minLen . Equals ( maxLen ) ? $ "key.length() != { map . ToValueLabel ( maxLen ) } " : $ "const size_t len = key.length(); len < { map . ToValueLabel ( minLen ) } || len > { map . ToValueLabel ( maxLen ) } ") } )
90+ { RenderExit ( methodType ) }
91+ """ ;
92+ }
6993
7094 protected override string GetStringBitMaskEarlyExit ( MethodType methodType , ulong mask , int byteCount , bool ignoreCase , GeneratorEncoding encoding )
7195 {
@@ -78,12 +102,12 @@ protected override string GetStringBitMaskEarlyExit(MethodType methodType, ulong
78102 if ( ! ignoreCase )
79103 {
80104 return $ """
81- uint64_t first = 0;
82- std::memcpy(&first, key.data(), { byteCount } );
105+ uint64_t first = 0;
106+ std::memcpy(&first, key.data(), { byteCount } );
83107
84- if ((first & { mask . ToStringInvariant ( ) } ULL) != 0)
85- { RenderExit ( methodType ) }
86- """ ;
108+ if ((first & { mask . ToStringInvariant ( ) } ULL) != 0)
109+ { RenderExit ( methodType ) }
110+ """ ;
87111 }
88112
89113 StringBuilder sb = new StringBuilder ( ) ;
@@ -92,17 +116,17 @@ protected override string GetStringBitMaskEarlyExit(MethodType methodType, ulong
92116 for ( int i = 0 ; i < byteCount ; i ++ )
93117 {
94118 sb . Append ( $ """
95- uint32_t c{ i } = static_cast<uint32_t>(key[{ i } ]);
96- c{ i } = to_lower_ascii(c{ i } );
97- first |= static_cast<uint64_t>(c{ i } ) << { i * 8 } ;
98- """ ) ;
119+ uint32_t c{ i } = static_cast<uint32_t>(key[{ i } ]);
120+ c{ i } = to_lower_ascii(c{ i } );
121+ first |= static_cast<uint64_t>(c{ i } ) << { i * 8 } ;
122+ """ ) ;
99123 }
100124
101125 sb . Append ( $ """
102126
103- if ((first & { mask . ToStringInvariant ( ) } ULL) != 0)
104- { RenderExit ( methodType ) }
105- """ ) ;
127+ if ((first & { mask . ToStringInvariant ( ) } ULL) != 0)
128+ { RenderExit ( methodType ) }
129+ """ ) ;
106130 return sb . ToString ( ) ;
107131 }
108132
@@ -137,4 +161,4 @@ private static string RenderExit(MethodType methodType) => methodType == MethodT
137161 }
138162 """
139163 : "return false;" ;
140- }
164+ }
0 commit comments