Fix IDE0057 (use range operator)
authorStephen Toub <stoub@microsoft.com>
Fri, 16 Aug 2019 20:23:17 +0000 (16:23 -0400)
committerStephen Toub <stoub@microsoft.com>
Sat, 17 Aug 2019 11:31:50 +0000 (07:31 -0400)
Commit migrated from https://github.com/dotnet/coreclr/commit/1a3b806e8cb5f641633de4591ce3130a1949fd44

src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormatInfoScanner.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs
src/libraries/System.Private.CoreLib/src/System/IO/Path.cs
src/libraries/System.Private.CoreLib/src/System/Text/EncodingTable.cs

index a695c76..af82dd2 100644 (file)
@@ -2077,7 +2077,7 @@ namespace System
                     // We set prefixLookup to true if name ends with a "*".
                     // We will also set listType to All so that all members are included in
                     // the candidates which are later filtered by FilterApplyPrefixLookup.
-                    name = name.Substring(0, name.Length - 1);
+                    name = name[0..^1];
                     prefixLookup = true;
                     listType = MemberListType.All;
                 }
index c464575..dff9c96 100644 (file)
@@ -292,7 +292,7 @@ namespace System.Diagnostics.Tracing
             {
                 eventName = this.eventName;
                 if (eventName.EndsWith("Start"))
-                    eventName = eventName.Substring(0, eventName.Length - 5);
+                    eventName = eventName[0..^5];
                 eventName += "Stop";
             }
             this.startStopOptions.Opcode = EventOpcode.Stop;
index d671ffa..625fbc8 100644 (file)
@@ -239,7 +239,7 @@ namespace System.Globalization
                         if (str[str.Length - 1] == '.')
                         {
                             // Old version ignore the trailing dot in the date words. Support this as well.
-                            string strWithoutDot = str.Substring(0, str.Length - 1);
+                            string strWithoutDot = str[0..^1];
                             if (!m_dateWords.Contains(strWithoutDot))
                             {
                                 m_dateWords.Add(strWithoutDot);
index 0e6a7cf..59a0286 100644 (file)
@@ -110,7 +110,7 @@ namespace System.Globalization
             }
             else
             {
-                return String.Substring(start, Indexes[lengthInTextElements + startingTextElement] - start);
+                return String[start..Indexes[lengthInTextElements + startingTextElement]];
             }
         }
 
index 1e52021..3df140e 100644 (file)
@@ -919,7 +919,7 @@ namespace System.IO
         /// </summary>
         public static string TrimEndingDirectorySeparator(string path) =>
             EndsInDirectorySeparator(path) && !PathInternal.IsRoot(path.AsSpan()) ?
-                path.Substring(0, path.Length - 1) :
+                path[0..^1] :
                 path;
 
         /// <summary>
index 3927ce6..ae5eb17 100644 (file)
@@ -112,7 +112,7 @@ namespace System.Text
             {
                 arrayEncodingInfo[i] = new EncodingInfo(
                     s_mappedCodePages[i],
-                    s_webNames.Substring(s_webNameIndices[i], s_webNameIndices[i + 1] - s_webNameIndices[i]),
+                    s_webNames[s_webNameIndices[i]..s_webNameIndices[i + 1]],
                     GetDisplayName(s_mappedCodePages[i], i)
                     );
             }
@@ -172,7 +172,7 @@ namespace System.Text
         private static CodePageDataItem InternalGetCodePageDataItem(int codePage, int index)
         {
             int uiFamilyCodePage = s_uiFamilyCodePages[index];
-            string webName = s_webNames.Substring(s_webNameIndices[index], s_webNameIndices[index + 1] - s_webNameIndices[index]);
+            string webName = s_webNames[s_webNameIndices[index]..s_webNameIndices[index + 1]];
             // All supported code pages have identical header names, and body names.
             string headerName = webName;
             string bodyName = webName;
@@ -186,7 +186,7 @@ namespace System.Text
         {
             string? displayName = SR.GetResourceString("Globalization_cp_" + codePage.ToString());
             if (string.IsNullOrEmpty(displayName))
-                displayName = s_englishNames.Substring(s_englishNameIndices[englishNameIndex], s_englishNameIndices[englishNameIndex + 1] - s_englishNameIndices[englishNameIndex]);
+                displayName = s_englishNames[s_englishNameIndices[englishNameIndex]..s_englishNameIndices[englishNameIndex + 1]];
 
             return displayName;
         }