19
19
using System . Collections . Generic ;
20
20
using System . Diagnostics ;
21
21
using System . IO ;
22
+ using System . Linq ;
22
23
using System . Threading ;
23
24
using System . Threading . Tasks ;
24
25
using FirebirdSql . Data . Common ;
@@ -1246,7 +1247,7 @@ protected void WriteRawParameter(IXdrWriter xdr, DbField field)
1246
1247
else
1247
1248
{
1248
1249
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 )
1250
1251
{
1251
1252
throw IscException . ForErrorCodes ( new [ ] { IscCodes . isc_arith_except , IscCodes . isc_string_truncation } ) ;
1252
1253
}
@@ -1271,7 +1272,7 @@ protected void WriteRawParameter(IXdrWriter xdr, DbField field)
1271
1272
else
1272
1273
{
1273
1274
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 )
1275
1276
{
1276
1277
throw IscException . ForErrorCodes ( new [ ] { IscCodes . isc_arith_except , IscCodes . isc_string_truncation } ) ;
1277
1278
}
@@ -1394,7 +1395,7 @@ protected async ValueTask WriteRawParameterAsync(IXdrWriter xdr, DbField field,
1394
1395
else
1395
1396
{
1396
1397
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 )
1398
1399
{
1399
1400
throw IscException . ForErrorCodes ( new [ ] { IscCodes . isc_arith_except , IscCodes . isc_string_truncation } ) ;
1400
1401
}
@@ -1419,7 +1420,7 @@ protected async ValueTask WriteRawParameterAsync(IXdrWriter xdr, DbField field,
1419
1420
else
1420
1421
{
1421
1422
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 )
1423
1424
{
1424
1425
throw IscException . ForErrorCodes ( new [ ] { IscCodes . isc_arith_except , IscCodes . isc_string_truncation } ) ;
1425
1426
}
@@ -1532,10 +1533,11 @@ protected object ReadRawValue(IXdrReader xdr, DbField field)
1532
1533
else
1533
1534
{
1534
1535
var s = xdr . ReadString ( innerCharset , field . Length ) ;
1536
+ var runes = s . EnumerateRunesEx ( ) . ToList ( ) ;
1535
1537
if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 &&
1536
- s . RuneCount ( ) > field . CharCount )
1538
+ runes . Count > field . CharCount )
1537
1539
{
1538
- return s . Substring ( 0 , field . CharCount ) ;
1540
+ return new string ( [ .. runes . Take ( field . CharCount ) . SelectMany ( x => x ) ] ) ;
1539
1541
}
1540
1542
else
1541
1543
{
@@ -1629,10 +1631,11 @@ protected async ValueTask<object> ReadRawValueAsync(IXdrReader xdr, DbField fiel
1629
1631
else
1630
1632
{
1631
1633
var s = await xdr . ReadStringAsync ( innerCharset , field . Length , cancellationToken ) . ConfigureAwait ( false ) ;
1634
+ var runes = s . EnumerateRunesEx ( ) . ToList ( ) ;
1632
1635
if ( ( field . Length % field . Charset . BytesPerCharacter ) == 0 &&
1633
- s . RuneCount ( ) > field . CharCount )
1636
+ runes . Count > field . CharCount )
1634
1637
{
1635
- return s . Substring ( 0 , field . CharCount ) ;
1638
+ return new string ( [ .. runes . Take ( field . CharCount ) . SelectMany ( x => x ) ] ) ;
1636
1639
}
1637
1640
else
1638
1641
{
0 commit comments