1919using System . Collections . Generic ;
2020using System . Diagnostics ;
2121using System . IO ;
22+ using System . Linq ;
2223using System . Threading ;
2324using System . Threading . Tasks ;
2425using FirebirdSql . Data . Common ;
@@ -1246,7 +1247,7 @@ protected void WriteRawParameter(IXdrWriter xdr, DbField field)
12461247 else
12471248 {
12481249 var svalue = field . DbValue . GetString ( ) ;
1249- if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 && svalue . RuneCount ( ) > field . CharCount )
1250+ if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 && svalue . EnumerateRunesEx ( ) . Count ( ) > field . CharCount )
12501251 {
12511252 throw IscException . ForErrorCodes ( new [ ] { IscCodes . isc_arith_except , IscCodes . isc_string_truncation } ) ;
12521253 }
@@ -1271,7 +1272,7 @@ protected void WriteRawParameter(IXdrWriter xdr, DbField field)
12711272 else
12721273 {
12731274 var svalue = field . DbValue . GetString ( ) ;
1274- if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 && svalue . RuneCount ( ) > field . CharCount )
1275+ if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 && svalue . EnumerateRunesEx ( ) . Count ( ) > field . CharCount )
12751276 {
12761277 throw IscException . ForErrorCodes ( new [ ] { IscCodes . isc_arith_except , IscCodes . isc_string_truncation } ) ;
12771278 }
@@ -1394,7 +1395,7 @@ protected async ValueTask WriteRawParameterAsync(IXdrWriter xdr, DbField field,
13941395 else
13951396 {
13961397 var svalue = await field . DbValue . GetStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
1397- if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 && svalue . RuneCount ( ) > field . CharCount )
1398+ if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 && svalue . EnumerateRunesEx ( ) . Count ( ) > field . CharCount )
13981399 {
13991400 throw IscException . ForErrorCodes ( new [ ] { IscCodes . isc_arith_except , IscCodes . isc_string_truncation } ) ;
14001401 }
@@ -1419,7 +1420,7 @@ protected async ValueTask WriteRawParameterAsync(IXdrWriter xdr, DbField field,
14191420 else
14201421 {
14211422 var svalue = await field . DbValue . GetStringAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
1422- if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 && svalue . RuneCount ( ) > field . CharCount )
1423+ if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 && svalue . EnumerateRunesEx ( ) . Count ( ) > field . CharCount )
14231424 {
14241425 throw IscException . ForErrorCodes ( new [ ] { IscCodes . isc_arith_except , IscCodes . isc_string_truncation } ) ;
14251426 }
@@ -1532,10 +1533,11 @@ protected object ReadRawValue(IXdrReader xdr, DbField field)
15321533 else
15331534 {
15341535 var s = xdr . ReadString ( innerCharset , field . Length ) ;
1536+ var runes = s . EnumerateRunesEx ( ) . ToList ( ) ;
15351537 if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 &&
1536- s . RuneCount ( ) > field . CharCount )
1538+ runes . Count > field . CharCount )
15371539 {
1538- return s . Substring ( 0 , field . CharCount ) ;
1540+ return new string ( [ .. runes . Take ( field . CharCount ) . SelectMany ( x => x ) ] ) ;
15391541 }
15401542 else
15411543 {
@@ -1629,10 +1631,11 @@ protected async ValueTask<object> ReadRawValueAsync(IXdrReader xdr, DbField fiel
16291631 else
16301632 {
16311633 var s = await xdr . ReadStringAsync ( innerCharset , field . Length , cancellationToken ) . ConfigureAwait ( false ) ;
1634+ var runes = s . EnumerateRunesEx ( ) . ToList ( ) ;
16321635 if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 &&
1633- s . RuneCount ( ) > field . CharCount )
1636+ runes . Count > field . CharCount )
16341637 {
1635- return s . Substring ( 0 , field . CharCount ) ;
1638+ return new string ( [ .. runes . Take ( field . CharCount ) . SelectMany ( x => x ) ] ) ;
16361639 }
16371640 else
16381641 {
0 commit comments