File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ implementation
2222type
2323 TWeatherCityList = TDictionary<string, TWeatherCity>;
2424
25+ TUTF8CustomComparer = class (TInterfacedObject, IComparer<string>)
26+ public
27+ function Compare (const Left, Right: string): Integer;
28+ end ;
29+
2530var
2631 WeatherCityList: TWeatherCityList;
2732
@@ -43,7 +48,7 @@ procedure ChallengeWithDictionary;
4348
4449 // create the output list
4550 CityArray := WeatherCityList.Keys.ToArray;
46- TArray.Sort<string>(CityArray, TStringComparer.Ordinal );
51+ TArray.Sort<string>(CityArray, TUTF8CustomComparer.Create );
4752 FirstOutput := True;
4853 Write(' {' );
4954 for var City in CityArray do
@@ -60,4 +65,12 @@ procedure ChallengeWithDictionary;
6065 end ;
6166end ;
6267
68+ { TUTF8CustomComparer }
69+
70+ function TUTF8CustomComparer.Compare (const Left, Right: string): Integer;
71+ begin
72+ // Convert UTF-8 strings to UnicodeString for comparison
73+ Result := CompareStr(UTF8ToWideString(Left), UTF8ToWideString(Right));
74+ end ;
75+
6376end .
You can’t perform that action at this time.
0 commit comments