-
Notifications
You must be signed in to change notification settings - Fork 26
Support Rows before/after, accordion, groups, grids in recursive layouts #1411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
99 changes: 99 additions & 0 deletions
99
src/Altinn.App.Core/Helpers/NaturalStringComparerPolyfill.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #if !NET10_0_OR_GREATER | ||
| using System.Globalization; | ||
|
|
||
| namespace Altinn.App.Core.Helpers; | ||
|
|
||
| /// <summary> | ||
| /// Provides a custom string comparer that performs natural sorting, comparing numeric substrings as numbers rather than strings. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This comparer is used to ensure that strings containing numeric values are ordered logically (e.g., "item2" < "item10"). | ||
| /// </remarks> | ||
| /// <example> | ||
| /// This class is marked as obsolete and is planned for removal when upgrading to .NET 10, as it will include built-in support for natural string comparison. | ||
| /// </example> | ||
| // [Obsolete("This utility can be removed in .NET 10")] | ||
| internal sealed class NaturalStringComparerPolyfill : IComparer<string> | ||
| { | ||
| private static readonly CompareInfo _compareInfo = CultureInfo.InvariantCulture.CompareInfo; | ||
|
|
||
| internal static readonly NaturalStringComparerPolyfill Instance = new(); | ||
|
|
||
| /// <inheritdoc /> | ||
| public int Compare(string? x, string? y) | ||
| { | ||
| if (ReferenceEquals(x, y)) | ||
| return 0; | ||
| if (x is null) | ||
| return -1; | ||
| if (y is null) | ||
| return 1; | ||
|
|
||
| int i = 0, | ||
| j = 0; | ||
| while (i < x.Length && j < y.Length) | ||
| { | ||
| char cx = x[i]; | ||
| char cy = y[j]; | ||
|
|
||
| bool dx = IsAsciiDigit(cx); | ||
| bool dy = IsAsciiDigit(cy); | ||
|
|
||
| if (dx && dy) | ||
| { | ||
| // Read full digit runs | ||
| int sx = i; | ||
| while (i < x.Length && IsAsciiDigit(x[i])) | ||
| i++; | ||
| int sy = j; | ||
| while (j < y.Length && IsAsciiDigit(y[j])) | ||
| j++; | ||
|
|
||
| // Skip leading zeros | ||
| int zx = sx; | ||
| while (zx < i && x[zx] == '0') | ||
| zx++; | ||
| int zy = sy; | ||
| while (zy < j && y[zy] == '0') | ||
| zy++; | ||
|
|
||
| int lenX = i - zx; | ||
| int lenY = j - zy; | ||
|
|
||
| // Compare by numeric length (ignoring leading zeros) | ||
| if (lenX != lenY) | ||
| return lenX.CompareTo(lenY); | ||
|
|
||
| // Same length: compare digit-by-digit | ||
| for (int k = 0; k < lenX; k++) | ||
| { | ||
| int cmp = x[zx + k].CompareTo(y[zy + k]); | ||
| if (cmp != 0) | ||
| return cmp; | ||
| } | ||
|
|
||
| // Perfect numeric tie: shorter with more leading zeros comes first | ||
| int leadingZerosCmp = (i - sx).CompareTo(j - sy); | ||
| if (leadingZerosCmp != 0) | ||
| return leadingZerosCmp; | ||
|
|
||
| // Otherwise continue | ||
| } | ||
|
|
||
| else | ||
| { | ||
| // ordnal for non digit chars | ||
| int cmp = _compareInfo.Compare(x, i, 1, y, j, 1, CompareOptions.Ordinal); | ||
| if (cmp != 0) | ||
| return cmp; | ||
| i++; | ||
| j++; | ||
| } | ||
| } | ||
|
|
||
| // Shorter string first if all equal so far | ||
| return (x.Length - i).CompareTo(y.Length - j); | ||
| } | ||
|
|
||
| private static bool IsAsciiDigit(char c) => c >= '0' && c <= '9'; | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.