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
11 changes: 7 additions & 4 deletions src/Java.Interop.Tools.Generator/Utilities/NamingConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ public static AndroidSdkVersion ParseApiLevel (string? value)
if (!value.HasValue ())
return null;

var hyphen = value.IndexOf ('-');
if (hyphen < 0 || (hyphen+1) >= value.Length)
const string ApiFilenamePrefix = "api-";

var hyphen = value.LastIndexOf (ApiFilenamePrefix);
if (hyphen < 0 || checked (hyphen + 1 + ApiFilenamePrefix.Length) >= value.Length)
return null;
hyphen += ApiFilenamePrefix.Length;

int end = hyphen + 1;
int end = hyphen;
if (char.IsAsciiDigit (value [end++])) {
for ( ; end < value.Length; ++end) {
var n = value [end + 1];
Expand All @@ -46,7 +49,7 @@ public static AndroidSdkVersion ParseApiLevel (string? value)
}
}

return value.Substring (hyphen + 1, end - hyphen - 1);
return value.Substring (hyphen, end - hyphen);
}

// The 'merge.SourceFile' attribute may be on the element, or only on its parent. For example,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public void ParseApiLevel ()
Assert.AreEqual (28, v.ApiLevel);
Assert.AreEqual (0, v.MinorRelease);

v = NamingConverter.ParseApiLevel (@"…\Xamarin-Work\…\bin\BuildDebug\api\api-36.1.xml.in");
Assert.AreEqual (36, v.ApiLevel);
Assert.AreEqual (1, v.MinorRelease);

v = NamingConverter.ParseApiLevel (@"..\..\bin\BuildDebug\api\api-36.1.xml.in");
Assert.AreEqual (36, v.ApiLevel);
Assert.AreEqual (1, v.MinorRelease);
Expand Down