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
4 changes: 2 additions & 2 deletions TiaCodegen-ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion TiaCodegen-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-projects/tia-codegen-ts",
"version": "2.0.1",
"version": "2.0.2",
"description": "TypeScript port of TiaCodeGen C# library",
"type": "module",
"main": "dist/index.js",
Expand Down
10 changes: 8 additions & 2 deletions TiaCodegen-ts/src/Extensions/NaturalComparer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class NaturalComparer {
if (vx !== vy) return vx < vy ? -1 : 1;
} else {
// Ordinal comparison like char.ToUpperInvariant(cx).CompareTo(...) in the C# version
const ux = cx.toUpperCase();
const uy = cy.toUpperCase();
const ux = this.toUpperChar(cx);
const uy = this.toUpperChar(cy);
if (ux !== uy) return ux < uy ? -1 : 1;
i++;
j++;
Expand All @@ -35,4 +35,10 @@ export class NaturalComparer {
private isDigit(c: string): boolean {
return c >= '0' && c <= '9';
}

// char.ToUpperInvariant keeps characters without a single-char upper case (e.g. 'ß' -> 'SS' in JS)
private toUpperChar(c: string): string {
const upper = c.toUpperCase();
return upper.length === 1 ? upper : c;
}
}
6 changes: 6 additions & 0 deletions TiaCodegen-ts/tests/NaturalComparer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ describe('NaturalComparer', () => {
expect(comparer.compare('a2', 'a10')).toBeLessThan(0);
expect(comparer.compare('a', 'A')).toBe(0);
});

test('keeps characters without a single-char upper case like C# ToUpperInvariant', () => {
const comparer = new NaturalComparer();
expect(comparer.compare('xßy', 'xzy')).toBeGreaterThan(0);
expect(comparer.compare('xßy', 'xÜy')).toBeGreaterThan(0);
});
});
Loading