aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authork-m_schindler <k-m_schindler@b956fd51-792f-4845-bead-9b4dfca2ff2c>2016-01-01 21:14:55 +0000
committerk-m_schindler <k-m_schindler@b956fd51-792f-4845-bead-9b4dfca2ff2c>2016-01-01 21:14:55 +0000
commit6b6c46c490fa3391139fbecc4776514bf040cf6d (patch)
tree08607aad78ef10d22c840b2bac9f7ef52551cb86
parentc179ce1e13ecb0528a3a948b4ff75f6a5c4509d8 (diff)
downloadusdx-6b6c46c490fa3391139fbecc4776514bf040cf6d.tar.gz
usdx-6b6c46c490fa3391139fbecc4776514bf040cf6d.tar.xz
usdx-6b6c46c490fa3391139fbecc4776514bf040cf6d.zip
add GetStringWithNoAccents
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@3156 b956fd51-792f-4845-bead-9b4dfca2ff2c
-rw-r--r--src/base/UCommon.pas62
-rw-r--r--src/base/USong.pas12
-rw-r--r--src/base/USongs.pas5
-rw-r--r--src/screens/UScreenJukebox.pas2
4 files changed, 79 insertions, 2 deletions
diff --git a/src/base/UCommon.pas b/src/base/UCommon.pas
index 18022337..25b30ed1 100644
--- a/src/base/UCommon.pas
+++ b/src/base/UCommon.pas
@@ -62,6 +62,23 @@ const
*}
function SplitString(const Str: string; MaxCount: integer = 0; Separators: TSysCharSet = SepWhitespace): TStringDynArray;
+function StringInArray(const Value: string; Strings: array of string): boolean;
+
+function GetStringWithNoAccents(str: UTF8String): UTF8String;
+
+type
+ TRGB = record
+ R: single;
+ G: single;
+ B: single;
+ end;
+
+ TRGBA = record
+ R, G, B, A: double;
+ end;
+
+function RGBToHex(R, G, B: integer):string;
+function HexToRGB(Hex: string): TRGB;
type
TMessageType = (mtInfo, mtError);
@@ -104,6 +121,16 @@ uses
UMain,
UUnicodeUtils;
+function StringInArray(const Value: string; Strings: array of string): boolean;
+var
+ i: integer;
+begin
+ Result := true;
+ for i := Low(Strings) to High(Strings) do
+ if Strings[i] = Value then exit;
+ Result := false;
+end;
+
function SplitString(const Str: string; MaxCount: integer; Separators: TSysCharSet): TStringDynArray;
{*
@@ -157,6 +184,41 @@ begin
AddSplit(Start, Length(Str)+1);
end;
+const
+ Accents: array [0..37] of UTF8String = ('ç', 'á', 'é', 'í', 'ó', 'ú', 'ý', 'à', 'è', 'ì', 'ò', 'ù', 'ã', 'õ', 'ñ', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'î', 'ô', 'û', '!', '¡', '"', '&', '(', ')', '?', '¿', ',', '.', ':', ';');
+ NoAccents: array [0..37] of UTF8String = ('c', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', 'a', 'o', 'n', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', '', '', '', '', '', '', '', '', '', '', '', '');
+
+function GetStringWithNoAccents(str: UTF8String): UTF8String;
+var
+ i: integer;
+ tmp: string;
+begin
+ tmp := Utf8ToAnsi(str);
+
+ for i := 0 to High(Accents) do
+ begin
+ str := StringReplace(str, Accents[i], NoAccents[i], [rfReplaceAll, rfIgnoreCase]);
+ end;
+
+ Result := str;
+end;
+
+function RGBToHex(R, G, B: integer): string;
+begin
+ Result := IntToHex(R, 2) + IntToHex(G, 2) + IntToHex(B, 2);
+end;
+
+function HexToRGB(Hex: string): TRGB;
+var
+ Col: TRGB;
+begin
+ Col.R := StrToInt('$'+Copy(Hex, 1, 2));
+ Col.G := StrToInt('$'+Copy(Hex, 3, 2));
+ Col.B := StrToInt('$'+Copy(Hex, 5, 2));
+
+ Result := Col;
+end;
+
// data used by the ...Locale() functions
{$IF Defined(Linux) or Defined(FreeBSD)}
diff --git a/src/base/USong.pas b/src/base/USong.pas
index 041f3853..1dda2825 100644
--- a/src/base/USong.pas
+++ b/src/base/USong.pas
@@ -135,6 +135,10 @@ type
Title: UTF8String;
Artist: UTF8String;
+ // use in search
+ TitleNoAccent: UTF8String;
+ ArtistNoAccent: UTF8String;
+
Creator: UTF8String;
CoverTex: TTexture;
@@ -787,12 +791,14 @@ begin
//Title
self.Title := Parser.SongInfo.Header.Title;
+ self.TitleNoAccent := LowerCase(GetStringWithNoAccents(UTF8Decode(Parser.SongInfo.Header.Title)));
//Add Title Flag to Done
Done := Done or 1;
//Artist
self.Artist := Parser.SongInfo.Header.Artist;
+ self.ArtistNoAccent := LowerCase(GetStringWithNoAccents(UTF8Decode(Parser.SongInfo.Header.Artist)));
//Add Artist Flag to Done
Done := Done or 2;
@@ -968,6 +974,8 @@ begin
if (Identifier = 'TITLE') then
begin
DecodeStringUTF8(Value, Title, Encoding);
+ self.TitleNoAccent := LowerCase(GetStringWithNoAccents(UTF8Decode(Title)));
+
//Add Title Flag to Done
Done := Done or 1;
end
@@ -975,6 +983,8 @@ begin
else if (Identifier = 'ARTIST') then
begin
DecodeStringUTF8(Value, Artist, Encoding);
+ self.ArtistNoAccent := LowerCase(GetStringWithNoAccents(UTF8Decode(Artist)));
+
//Add Artist Flag to Done
Done := Done or 2;
end
@@ -1073,7 +1083,7 @@ begin
DecodeStringUTF8(Value, Language, Encoding)
end
- //Language Sorting
+ //Year Sorting
else if (Identifier = 'YEAR') then
begin
TryStrtoInt(Value, self.Year)
diff --git a/src/base/USongs.pas b/src/base/USongs.pas
index 25ad4ae3..554e6a17 100644
--- a/src/base/USongs.pas
+++ b/src/base/USongs.pas
@@ -777,7 +777,10 @@ var
TmpString: UTF8String;
WordArray: array of UTF8String;
begin
- FilterStr := Trim(FilterStr);
+
+ FilterStr := Trim(UTF8Decode(FilterStr));
+ FilterStr := GetStringWithNoAccents(FilterStr);
+
if (FilterStr <> '') then
begin
Result := 0;
diff --git a/src/screens/UScreenJukebox.pas b/src/screens/UScreenJukebox.pas
index ae0eacad..36a65720 100644
--- a/src/screens/UScreenJukebox.pas
+++ b/src/screens/UScreenJukebox.pas
@@ -374,6 +374,8 @@ begin
if (Filter <> '') then
begin
+ Filter := GetStringWithNoAccents(UTF8Decode(UTF8LowerCase(Filter)));
+
SetLength(JukeboxVisibleSongs, 0);
for I := 0 to High(JukeboxSongsList) do
begin