Skip to content

Commit b73e48c

Browse files
committed
CA1852 and CA1311
1 parent 5d98bd8 commit b73e48c

15 files changed

Lines changed: 20 additions & 19 deletions

File tree

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ dotnet_diagnostic.CA1838.severity = suggestion # CA1838: Avoid 'StringBuilder'
8080
dotnet_diagnostic.CA1845.severity = none # CA1845: Use span-based 'string.Concat'
8181
dotnet_diagnostic.CA1846.severity = none # CA1846: Prefer 'AsSpan' over 'Substring'
8282
dotnet_diagnostic.CA1847.severity = none # CA1847: Use char literal for a single character lookup
83+
dotnet_diagnostic.CA1852.severity = suggestion # CA1852: Seal internal types
8384
dotnet_diagnostic.CA2101.severity = suggestion # CA2101: Specify marshaling for P/Invoke string arguments
8485
dotnet_diagnostic.CA2201.severity = none # CA2201: Do not raise reserved exception types
8586
dotnet_diagnostic.CA2208.severity = suggestion # CA2208: Instantiate argument exceptions correctly

Src/IronPython.Modules/_datetime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ private int CompareTo(object other) {
14721472
string ltzname = tzname() as string;
14731473
if (ltzname != null) {
14741474
// TODO: calling __repr__?
1475-
sb.AppendFormat(", tzinfo={0}", ltzname.ToLower());
1475+
sb.AppendFormat(", tzinfo={0}", ltzname.ToLowerInvariant());
14761476
}
14771477

14781478
sb.AppendFormat(")");

Src/IronPython.Modules/_socket.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ public static object getnameinfo(CodeContext/*!*/ context, [NotNone] PythonTuple
12321232
+ "Raises socket.error if no protocol number can be found."
12331233
)]
12341234
public static object getprotobyname(CodeContext/*!*/ context, [NotNone] string protocolName) {
1235-
switch (protocolName.ToLower()) {
1235+
switch (protocolName.ToLowerInvariant()) {
12361236
case "ah": return IPPROTO_AH;
12371237
case "esp": return IPPROTO_ESP;
12381238
case "dstopts": return IPPROTO_DSTOPTS;
@@ -1266,7 +1266,7 @@ public static int getservbyname(CodeContext/*!*/ context, [NotNone] string servi
12661266
[Documentation("")]
12671267
public static int getservbyname(CodeContext/*!*/ context, [NotNone] string serviceName, [NotNone] string protocolName) {
12681268
if (protocolName != null) {
1269-
protocolName = protocolName.ToLower();
1269+
protocolName = protocolName.ToLowerInvariant();
12701270
if (protocolName != "udp" && protocolName != "tcp")
12711271
throw PythonExceptions.CreateThrowable(error, "service/proto not found");
12721272
}
@@ -1277,7 +1277,7 @@ public static int getservbyname(CodeContext/*!*/ context, [NotNone] string servi
12771277
} catch { }
12781278

12791279

1280-
switch (serviceName.ToLower()) {
1280+
switch (serviceName.ToLowerInvariant()) {
12811281
case "echo": return 7;
12821282
case "daytime": return 13;
12831283
case "ftp-data": return 20;
@@ -1327,7 +1327,7 @@ public static string getservbyport(CodeContext/*!*/ context, int port, [NotNone]
13271327
throw PythonOps.OverflowError("getservbyport: port must be 0-65535.");
13281328

13291329
if (protocolName != null) {
1330-
protocolName = protocolName.ToLower();
1330+
protocolName = protocolName.ToLowerInvariant();
13311331
if (protocolName != "udp" && protocolName != "tcp")
13321332
throw PythonExceptions.CreateThrowable(error, "port/proto not found");
13331333
}

Src/IronPython.SQLite/c#sqlite/build_c.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ static char sqlite3AffinityType( string zIn )
12021202
{
12031203
//u32 h = 0;
12041204
//char aff = SQLITE_AFF_NUMERIC;
1205-
zIn = zIn.ToLower();
1205+
zIn = zIn.ToLowerInvariant();
12061206
if ( zIn.Contains( "char" ) || zIn.Contains( "clob" ) || zIn.Contains( "text" ) )
12071207
return SQLITE_AFF_TEXT;
12081208
if ( zIn.Contains( "blob" ) )

Src/IronPython.SQLite/c#sqlite/date_c.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static int parseModifier( sqlite3_context pCtx, string zMod, DateTime p )
682682
int rc = 1;
683683
int n;
684684
double r = 0;
685-
StringBuilder z = new StringBuilder( zMod.ToLower() );
685+
StringBuilder z = new StringBuilder( zMod.ToLowerInvariant() );
686686
zdtBuf.Length = 0;
687687
//z = zdtBuf;
688688
//for(n=0; n<ArraySize(zdtBuf)-1 && zMod[n]; n++){

Src/IronPython.SQLite/c#sqlite/func_c.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ sqlite3_value[] argv
470470
//{
471471
//(char)sqlite3Toupper( z1[i] );
472472
//}
473-
sqlite3_result_text( context, z2.Length == 0 ? "" : z2.Substring( 0, n ).ToUpper(), -1, null ); //sqlite3_free );
473+
sqlite3_result_text( context, z2.Length == 0 ? "" : z2.Substring( 0, n ).ToUpperInvariant(), -1, null ); //sqlite3_free );
474474
// }
475475
}
476476
}
@@ -499,7 +499,7 @@ sqlite3_value[] argv
499499
// {
500500
// z1[i] = (char)sqlite3Tolower( z1[i] );
501501
// }
502-
sqlite3_result_text( context, z2.Length == 0 ? "" : z2.Substring( 0, n ).ToLower(), -1, null );//sqlite3_free );
502+
sqlite3_result_text( context, z2.Length == 0 ? "" : z2.Substring( 0, n ).ToLowerInvariant(), -1, null );//sqlite3_free );
503503
//}
504504
}
505505
}

Src/IronPython.SQLite/c#sqlite/vdbemem_c.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static int sqlite3VdbeMemStringify( Mem pMem, int enc )
305305
else if ( Double.IsPositiveInfinity( pMem.r ) )
306306
pMem.z = "+Inf";
307307
else if ( pMem.r.ToString( CultureInfo.InvariantCulture ).Contains( "." ) )
308-
pMem.z = pMem.r.ToString( CultureInfo.InvariantCulture ).ToLower();//sqlite3_snprintf(nByte, pMem.z, "%!.15g", pMem->r);
308+
pMem.z = pMem.r.ToString( CultureInfo.InvariantCulture ).ToLowerInvariant();//sqlite3_snprintf(nByte, pMem.z, "%!.15g", pMem->r);
309309
else
310310
pMem.z = pMem.r.ToString( CultureInfo.InvariantCulture) + ".0";
311311
}
@@ -1604,4 +1604,4 @@ static int sqlite3ValueBytes( sqlite3_value pVal, int enc )
16041604
return 0;
16051605
}
16061606
}
1607-
}
1607+
}

Src/IronPython/Runtime/LiteralParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ private static Exception ExnMalformed() {
987987

988988
public static Complex ParseComplex(string s) {
989989
// remove no-meaning spaces and convert to lowercase
990-
string text = s.Trim().ToLower();
990+
string text = s.Trim().ToLowerInvariant();
991991

992992
// remove 1 layer of parens
993993
if (text.StartsWith("(", StringComparison.Ordinal) && text.EndsWith(")", StringComparison.Ordinal)) {

Src/IronPython/Runtime/Operations/FloatOps.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public static object fromhex(CodeContext/*!*/ context, PythonType/*!*/ cls, stri
315315
}
316316

317317
private static double? TryParseSpecialFloat(string self) {
318-
switch (self.ToLower()) {
318+
switch (self.ToLowerInvariant()) {
319319
case "inf":
320320
case "+inf":
321321
case "infinity":

0 commit comments

Comments
 (0)