Skip to content

Commit 157539a

Browse files
committed
Generate Index and Range
1 parent ddafe42 commit 157539a

5 files changed

Lines changed: 50 additions & 32 deletions

File tree

AdvancedSharpAdbClient/AdvancedSharpAdbClient.csproj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,26 @@
148148
<DefineConstants>$(DefineConstants);HAS_RUNTIMEINFORMATION</DefineConstants>
149149
</PropertyGroup>
150150

151+
<PropertyGroup Condition="'$(TargetFramework)' != 'net2.0-client'
152+
and '$(TargetFramework)' != 'net3.0-client'
153+
and '$(TargetFramework)' != 'net3.5-client'
154+
and '$(TargetFramework)' != 'net4.0-client'
155+
and '$(TargetFramework)' != 'net4.5.2'
156+
and '$(TargetFramework)' != 'net4.6.2'
157+
and '$(TargetFramework)' != 'netstandard1.3'
158+
and '$(TargetFramework)' != 'netcore5.0'
159+
and '$(TargetFramework)' != 'uap10.0'">
160+
<DefineConstants>$(DefineConstants);HAS_RANGE</DefineConstants>
161+
<PolySharpIncludeGeneratedTypes>$(PolySharpIncludeGeneratedTypes);System.Range</PolySharpIncludeGeneratedTypes>
162+
</PropertyGroup>
163+
151164
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'
152165
or '$(TargetFramework)' == 'net6.0-windows10.0.17763.0'
153166
or '$(TargetFramework)' == 'net8.0'
154167
or '$(TargetFramework)' == 'net8.0-windows10.0.17763.0'
155168
or '$(TargetFramework)' == 'netcoreapp3.1'
156169
or '$(TargetFramework)' == 'netstandard2.1'">
157-
<DefineConstants>$(DefineConstants);HAS_BUFFERS;HAS_INDEXRANGE</DefineConstants>
170+
<DefineConstants>$(DefineConstants);HAS_BUFFERS</DefineConstants>
158171
<PolySharpIncludeGeneratedTypes>$(PolySharpIncludeGeneratedTypes);System.Runtime.CompilerServices.CollectionBuilderAttribute</PolySharpIncludeGeneratedTypes>
159172
</PropertyGroup>
160173

AdvancedSharpAdbClient/DeviceCommands/LinuxPath.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ public static string Combine(params string[] paths)
5858
{
5959
capacity += paths[i].Length;
6060
}
61-
#if HAS_INDEXRANGE
6261
char ch = paths[i][^1];
63-
#else
64-
char ch = paths[i][paths[i].Length - 1];
65-
#endif
6662
if (ch != DirectorySeparatorChar)
6763
{
6864
capacity++;
@@ -81,16 +77,11 @@ public static string Combine(params string[] paths)
8177
}
8278
else
8379
{
84-
#if HAS_INDEXRANGE
8580
char ch2 = builder[^1];
86-
#else
87-
char ch2 = builder[builder.Length - 1];
88-
#endif
8981
if (ch2 != DirectorySeparatorChar)
9082
{
9183
_ = builder.Append(DirectorySeparatorChar);
9284
}
93-
9485
_ = builder.Append(paths[j]);
9586
}
9687
}
@@ -125,11 +116,16 @@ public static string Combine(params string[] paths)
125116
{
126117
return tpath;
127118
}
128-
#if HAS_INDEXRANGE
129-
tpath = tpath[..(tpath.LastIndexOf(DirectorySeparatorChar) + 1)];
119+
120+
tpath =
121+
#if HAS_BUFFERS
122+
tpath.AsSpan(0, tpath.LastIndexOf(DirectorySeparatorChar) + 1).ToString();
123+
#elif HAS_RANGE
124+
tpath[..(tpath.LastIndexOf(DirectorySeparatorChar) + 1)];
130125
#else
131-
tpath = tpath.Substring(0, tpath.LastIndexOf(DirectorySeparatorChar) + 1);
126+
tpath.Substring(0, tpath.LastIndexOf(DirectorySeparatorChar) + 1);
132127
#endif
128+
133129
return FixupPath(tpath);
134130
}
135131
else if (tpath.Length == 1)

AdvancedSharpAdbClient/DeviceCommands/Models/AndroidProcess.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public AndroidProcess(string line, bool cmdLinePrefix = false)
4343

4444
if (cmdLinePrefix)
4545
{
46-
#if HAS_INDEXRANGE
47-
string[] cmdLineParts = line[..processNameStart]
46+
string[] cmdLineParts =
47+
#if HAS_RANGE
48+
line[..processNameStart]
4849
#else
49-
50-
string[] cmdLineParts = line.Substring(0, processNameStart)
50+
line.Substring(0, processNameStart)
5151
#endif
5252
.Split('\0');
5353

@@ -57,11 +57,7 @@ public AndroidProcess(string line, bool cmdLinePrefix = false)
5757
}
5858
else
5959
{
60-
#if HAS_INDEXRANGE
6160
pid = int.Parse(cmdLineParts[^1]);
62-
#else
63-
pid = int.Parse(cmdLineParts[cmdLineParts.Length - 1]);
64-
#endif
6561
ProcessId = pid;
6662

6763
comm = cmdLineParts[0];
@@ -74,21 +70,25 @@ public AndroidProcess(string line, bool cmdLinePrefix = false)
7470

7571
if (!parsedCmdLinePrefix)
7672
{
77-
#if HAS_INDEXRANGE
78-
pid = int.Parse(line[..processNameStart]);
73+
pid =
74+
#if HAS_BUFFERS
75+
int.Parse(line.AsSpan(0, processNameStart));
76+
#elif HAS_RANGE
77+
int.Parse(line[..processNameStart]);
7978
#else
80-
pid = int.Parse(line.Substring(0, processNameStart));
79+
int.Parse(line.Substring(0, processNameStart));
8180
#endif
8281
ProcessId = pid;
8382

8483
comm = line.Substring(processNameStart + 1, processNameEnd - processNameStart - 1);
8584
Name = comm;
8685
}
8786

88-
#if HAS_INDEXRANGE
89-
string[] parts = line[(processNameEnd + 1)..]
87+
string[] parts =
88+
#if HAS_RANGE
89+
line[(processNameEnd + 1)..]
9090
#else
91-
string[] parts = line.Substring(processNameEnd + 1)
91+
line.Substring(processNameEnd + 1)
9292
#endif
9393
.Split(' ', StringSplitOptions.RemoveEmptyEntries);
9494

AdvancedSharpAdbClient/DeviceCommands/Receivers/PackageManagerReceiver.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) The Android Open Source Project, Ryan Conrad, Quamotion, yungd1plomat, wherewhere. All rights reserved.
33
// </copyright>
44

5+
using System;
56
using System.Collections.Generic;
67

78
namespace AdvancedSharpAdbClient.DeviceCommands.Receivers
@@ -36,10 +37,13 @@ protected override void ProcessNewLines(IEnumerable<string> lines)
3637
// package:mwc2015.be
3738

3839
// Remove the "package:" prefix
39-
#if HAS_INDEXRANGE
40-
string package = line[8..];
40+
string package =
41+
#if HAS_BUFFERS
42+
line.AsSpan(8).ToString();
43+
#elif HAS_RANGE
44+
line[8..];
4145
#else
42-
string package = line.Substring(8);
46+
line.Substring(8);
4347
#endif
4448
//// If there's a '=' included, use the last instance,
4549
//// to accommodate for values like
@@ -54,7 +58,10 @@ protected override void ProcessNewLines(IEnumerable<string> lines)
5458
}
5559
else
5660
{
57-
#if HAS_INDEXRANGE
61+
#if HAS_BUFFERS
62+
string path = package.AsSpan(0, separator).ToString();
63+
string name = package.AsSpan(separator + 1).ToString();
64+
#elif HAS_RANGE
5865
string path = package[..separator];
5966
string name = package[(separator + 1)..];
6067
#else

AdvancedSharpAdbClient/DeviceCommands/Receivers/VersionInfoReceiver.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ private void CheckPackagesSection(string line)
8585

8686
return !inPackagesSection ? null
8787
: line != null && line.Trim().StartsWith("versionName=")
88-
#if HAS_INDEXRANGE
88+
#if HAS_BUFFERS
89+
? line.Trim().AsSpan(12).ToString().Trim() : null;
90+
#elif HAS_RANGE
8991
? line.Trim()[12..].Trim() : null;
9092
#else
9193
? line.Trim().Substring(12).Trim() : null;

0 commit comments

Comments
 (0)