diff --git a/TiaCodegen-ts/package-lock.json b/TiaCodegen-ts/package-lock.json index 8703977..be4de9c 100644 --- a/TiaCodegen-ts/package-lock.json +++ b/TiaCodegen-ts/package-lock.json @@ -1,12 +1,12 @@ { "name": "@node-projects/tia-codegen-ts", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@node-projects/tia-codegen-ts", - "version": "2.0.1", + "version": "2.0.2", "devDependencies": { "@types/jest": "^29.5.12", "@types/node": "^20.12.7", diff --git a/TiaCodegen-ts/package.json b/TiaCodegen-ts/package.json index b53e105..b8e6352 100644 --- a/TiaCodegen-ts/package.json +++ b/TiaCodegen-ts/package.json @@ -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", diff --git a/TiaCodegen-ts/src/Extensions/NaturalComparer.ts b/TiaCodegen-ts/src/Extensions/NaturalComparer.ts index cf49d0a..b8b51bc 100644 --- a/TiaCodegen-ts/src/Extensions/NaturalComparer.ts +++ b/TiaCodegen-ts/src/Extensions/NaturalComparer.ts @@ -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++; @@ -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; + } } diff --git a/TiaCodegen-ts/tests/NaturalComparer.test.ts b/TiaCodegen-ts/tests/NaturalComparer.test.ts index 63dd2b8..7ad12e1 100644 --- a/TiaCodegen-ts/tests/NaturalComparer.test.ts +++ b/TiaCodegen-ts/tests/NaturalComparer.test.ts @@ -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); + }); });