Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ dotnet_diagnostic.CA2208.severity = suggestion # CA2208: Instantiate argument e
dotnet_diagnostic.CA2211.severity = none # CA2211: Non-constant fields should not be visible
dotnet_diagnostic.CA2219.severity = suggestion # CA2219: Do not raise exceptions in finally clauses
dotnet_diagnostic.CA2229.severity = suggestion # CA2229: Implement serialization constructors
dotnet_diagnostic.CA2249.severity = suggestion # CA2249: Consider using 'string.Contains' instead of 'string.IndexOf'
dotnet_diagnostic.CA2263.severity = none # CA2263: Prefer generic overload when type is known
dotnet_diagnostic.CA3075.severity = suggestion # CA3075: Insecure DTD processing in XML
dotnet_diagnostic.CA5350.severity = suggestion # CA5350: Do Not Use Weak Cryptographic Algorithms
Expand Down
3 changes: 2 additions & 1 deletion src/core/IronPython.Modules/IronPython.Modules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
T:System.Diagnostics.CodeAnalysis.NotNullAttribute;
T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute;
T:System.Runtime.Versioning.SupportedOSPlatformAttribute;
M:System.String.Contains(System.Char);
M:System.String.EndsWith(System.Char);
</MeziantouPolyfill_IncludedPolyfills>
</PropertyGroup>
Expand Down Expand Up @@ -43,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Polyfill" Version="1.0.120">
<PackageReference Include="Meziantou.Polyfill" Version="1.0.127">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython.Modules/_csv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ private void JoinAppend(string field, bool quoted) {
}

foreach (char c in need_escape) {
if (field.IndexOf(c) >= 0) {
if (field.Contains(c)) {
if (string.IsNullOrEmpty(_dialect.escapechar))
throw MakeError("need to escape, but no escapechar set");
field = field.Replace(c.ToString(), _dialect.escapechar + c);
Expand Down
4 changes: 2 additions & 2 deletions src/core/IronPython.Modules/_ctypes/SimpleType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SimpleType(CodeContext/*!*/ context, string name, PythonTuple bases, Pyth
if (!TryGetBoundCustomMember(context, "_type_", out object val) ||
(sVal = StringOps.AsString(val)) == null ||
sVal.Length != 1 ||
allowedTypes.IndexOf(sVal[0]) == -1) {
!allowedTypes.Contains(sVal[0])) {
throw PythonOps.AttributeError("AttributeError: class must define a '_type_' attribute which must be a single character string containing one of '{0}'.", allowedTypes);
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public SimpleType(CodeContext/*!*/ context, string name, PythonTuple bases, Pyth
throw new NotImplementedException("simple type " + sVal);
}

if (!name.EndsWith("_be", StringComparison.Ordinal) && !name.EndsWith("_le", StringComparison.Ordinal) && swappedTypes.IndexOf(_charType) != -1) {
if (!name.EndsWith("_be", StringComparison.Ordinal) && !name.EndsWith("_le", StringComparison.Ordinal) && swappedTypes.Contains(_charType)) {
CreateSwappedType(context, name, bases, dict);
}
_format = (BitConverter.IsLittleEndian ? '<' : '>') + _charType.ToString();
Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython.Modules/_ctypes/_ctypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static void FreeLibrary(IntPtr handle) {
}

private static object LoadDLL(string? library, int mode) {
if (library is not null && library.IndexOf((char)0) != -1) throw PythonOps.ValueError("embedded null byte");
if (library is not null && library.Contains((char)0)) throw PythonOps.ValueError("embedded null byte");
IntPtr res = NativeFunctions.LoadDLL(library, mode);
if (res == IntPtr.Zero) {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython.Modules/array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) {
if (_typeCode == 'u') {
char quote = '\'';
string s = new string(((ArrayData<char>)_data).Data, 0, _data.Count);
if (s.IndexOf('\'') != -1 && s.IndexOf('\"') == -1) {
if (s.Contains('\'') && !s.Contains('\"')) {
quote = '\"';
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython.Modules/grp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static struct_group getgrgid(CodeContext context, object gid) {
}

public static struct_group getgrnam(string name) {
if (name is not null && name.IndexOf((char)0) != -1) throw PythonOps.ValueError("embedded null byte");
if (name is not null && name.Contains((char)0)) throw PythonOps.ValueError("embedded null byte");
var grp = _getgrnam(name);
if (grp == IntPtr.Zero) {
throw PythonOps.KeyError($"getgrnam()): name not found: {name}");
Expand Down
4 changes: 2 additions & 2 deletions src/core/IronPython.Modules/nt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ private static string ArgumentsToString(CodeContext/*!*/ context, object? args,
if (space) {
sb.Append(' ');
}
if (strarg.IndexOf(' ') != -1) {
if (strarg.Contains(' ')) {
sb.Append('"');
// double quote any existing quotes
sb.Append(strarg.Replace("\"", "\"\""));
Expand Down Expand Up @@ -2398,7 +2398,7 @@ private static void CheckOptionalArgsCount(int numRegParms, int numOptPosParms,
}

private static void VerifyPath(string path, string functionName, string argName) {
if (path.IndexOf((char)0) != -1) throw PythonOps.ValueError($"{functionName}: embedded null character in {argName}");
if (path.Contains((char)0)) throw PythonOps.ValueError($"{functionName}: embedded null character in {argName}");
}

[SupportedOSPlatform("windows")]
Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython.Modules/winsound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static void PlaySound(CodeContext/*!*/ context, string? sound, int flags)
if (((flags & SND_ASYNC) == SND_ASYNC) && ((flags & SND_MEMORY) == SND_MEMORY)) throw PythonOps.RuntimeError("Cannot play asynchronously from memory");
if ((flags & SND_MEMORY) == SND_MEMORY) throw PythonOps.TypeError($"a bytes-like object is required, not '{PythonOps.GetPythonTypeName(sound)}'");

if (sound.IndexOf((char)0) != -1) throw PythonOps.ValueError("embedded null character");
if (sound.Contains((char)0)) throw PythonOps.ValueError("embedded null character");

if (!PlaySound(sound, IntPtr.Zero, flags)) {
throw PythonOps.RuntimeError("Failed to play sound");
Expand Down
6 changes: 3 additions & 3 deletions src/core/IronPython/IronPython.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute;
T:System.Runtime.Versioning.SupportedOSPlatformAttribute;
T:System.Runtime.Versioning.UnsupportedOSPlatformAttribute;
M:System.String.StartsWith(System.Char);
M:System.String.EndsWith(System.Char);
M:System.String.Contains(System.Char);
M:System.String.EndsWith(System.Char);
M:System.String.StartsWith(System.Char);
</MeziantouPolyfill_IncludedPolyfills>
</PropertyGroup>

Expand Down Expand Up @@ -65,7 +65,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Polyfill" Version="1.0.120">
<PackageReference Include="Meziantou.Polyfill" Version="1.0.127">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython/Modules/Builtin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static object compile(CodeContext/*!*/ context, [NotNone] string source,
string sfilename = PythonOps.FsPathDecoded(context, filename);
var sourceCodeKind = ValidateCompileMode(mode);

if (source.IndexOf('\0') != -1) {
if (source.Contains('\0')) {
throw PythonOps.TypeError("compile() expected string without null bytes");
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython/Runtime/ClrModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ object. Namespaces or types in the assembly can be accessed directly from
if (file.Length == 0) throw new ValueErrorException("assembly name must not be empty string");
ContractUtils.RequiresNotNull(context, nameof(context));

if (file.IndexOf(Path.DirectorySeparatorChar) != -1) {
if (file.Contains(Path.DirectorySeparatorChar)) {
throw new ValueErrorException("filenames must not contain full paths, first add the path to sys.path");
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/IronPython/Runtime/FormattingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public static NumberFormatInfo InvariantUnderscoreNumberInfo {
// that isn't. After all, it would be pretty weird to produce:
// 000,xxx,xxx,xxx. So, produce 0,000,xxx,xxx,xxx instead.
// (Just like CPython)
if (separator.IndexOf(res[beginningOfMaximumWidth]) != -1) {
if (separator.Contains(res[beginningOfMaximumWidth])) {
for (int i = beginningOfMaximumWidth - 1; i >= 0; i--) {
if (separator.IndexOf(res[i]) == -1) {
if (!separator.Contains(res[i])) {
res.Remove(0, i);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython/Runtime/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private static object ImportModuleFrom(CodeContext/*!*/ context, object from, Ar
public static object ImportModule(CodeContext/*!*/ context, object globals, string/*!*/ modName, bool bottom, int level) {
if (level < 0) throw PythonOps.ValueError("level must be >= 0");

if (modName.IndexOf(Path.DirectorySeparatorChar) != -1) {
if (modName.Contains(Path.DirectorySeparatorChar)) {
throw PythonOps.ImportError("Import by filename is not supported.");
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython/Runtime/LiteralParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ public static Complex ParseComplex(string s) {

text = text.Trim();

if (string.IsNullOrEmpty(text) || text.IndexOf(' ') != -1) {
if (string.IsNullOrEmpty(text) || text.Contains(' ')) {
throw ExnMalformed();
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython/Runtime/MemoryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public MemoryView cast([NotNone] string format, [NotNone, AllowNull]object shape
}

private static bool IsSupportedTypecode(char code) {
return ValidCodes.IndexOf(code) >= 0;
return ValidCodes.Contains(code);
}

private static void UnpackBytes(char typecode, object o, Span<byte> dest) {
Expand Down
3 changes: 1 addition & 2 deletions src/core/IronPython/Runtime/NewStringFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ private string ReplaceText(string format) {
/// spec to compute those values.
/// </summary>
private string/*!*/ ReplaceComputedFormats(string/*!*/ formatSpec) {
int computeStart = formatSpec.IndexOf('{');
if (computeStart != -1) {
if (formatSpec.Contains('{')) {
_depth++;
formatSpec = ReplaceText(formatSpec);
_depth--;
Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython/Runtime/Operations/FloatOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ internal static string Repr(CodeContext/*!*/ context, double self, bool trailing

// if it's not round trippable though use .NET's round-trip format
res = self.ToString("R", CultureInfo.InvariantCulture);
if (trailingZeroAfterWholeFloat && res.IndexOf('.') == -1) {
if (trailingZeroAfterWholeFloat && !res.Contains('.')) {
res += ".0";
}
return res;
Expand Down
4 changes: 2 additions & 2 deletions src/core/IronPython/Runtime/Operations/PythonOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ internal static void RegisterEncodingError(CodeContext/*!*/ context, string name
}

internal static PythonTuple LookupEncoding(CodeContext/*!*/ context, string encoding) {
if (encoding.IndexOf('\0') != -1) {
if (encoding.Contains('\0')) {
throw PythonOps.TypeError("lookup string cannot contain null character");
}
//compute encoding.ToLower().Replace(' ', '-') but ToLower only on ASCII letters
Expand Down Expand Up @@ -2109,7 +2109,7 @@ public static object ImportTop(CodeContext/*!*/ context, string fullName, int le
public static object ImportBottom(CodeContext/*!*/ context, string fullName, int level) {
object module = Importer.ImportLightThrow(context, fullName, null, level);

if (!LightExceptions.IsLightException(module) && fullName.IndexOf('.') >= 0) {
if (!LightExceptions.IsLightException(module) && fullName.Contains('.')) {
// Extract bottom from the imported module chain
string[] parts = fullName.Split('.');

Expand Down
4 changes: 2 additions & 2 deletions src/core/IronPython/Runtime/Operations/StringOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static bool __contains__([NotNone] string s, string? item) {
}

public static bool __contains__([NotNone] string s, char item) {
return s.IndexOf(item) != -1;
return s.Contains(item);
}

public static string __format__(CodeContext/*!*/ context, [NotNone] string self, [NotNone] string formatSpec) {
Expand Down Expand Up @@ -1520,7 +1520,7 @@ public static string __str__([NotNone] ExtensibleString self) {
internal static string Quote(string s) {
StringBuilder b = new StringBuilder(s.Length + 5);
char quote = '\'';
if (s.IndexOf('\'') != -1 && s.IndexOf('\"') == -1) {
if (s.Contains('\'') && !s.Contains('\"')) {
quote = '\"';
}
b.Append(quote);
Expand Down
2 changes: 1 addition & 1 deletion src/core/IronPython/Runtime/TypecodeOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static bool TryDecomposeTypecode(string format, out char byteorder, out c
code = format[1];
}
// TODO: add validation of combinations
return ValidByteorder.IndexOf(byteorder) >= 0 && ValidCodes.IndexOf(code) >= 0;
return ValidByteorder.Contains(byteorder) && ValidCodes.Contains(code);
}

public static void DecomposeTypecode(string format, out char byteorder, out char code) {
Expand Down
Loading