Dear All
I continue with my mp3 play list file writer. I have abandoned looking at file properties for the purpose of calculating the total play time of all the files listed in the play list file. That will have to wait for now.
I am at the stage of validating the path/filenames. Through trial and error I have worked out that the play list function will only read in paths and file names whose characters are within limited range of ASCII. Specifically all 1 byte characters between Alt + 32 - Alt + 126, inclusive. There are some characters in that range which cannot be used in path filenames, such as Alt + 42
- , so I did not test those. This is definitive information proved by trial and error and it leaves a lot of characters that cannot be used. Some are already in file names of mp3 files on my mp3 player and they will not play if included in the play list file. That is how I became suspicious of the play list functions limitations. So with the Hercule Poirot in me inspired I set about writing a validation section to my programme.
The following code explains where I have got to so far. All permissible characters are in a string. A 3 byte character is selected to see what happens when it is NOT fund in the string. On click, zero is written to the label caption. As it should be.
procedure TForm1.Button1Click(Sender: TObject);
var
LegalChars : string; letter : Char; posi : LongInt;
begin
LegalChars :='\ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!$%&‘’()+,-.;=@[]^_`{}~';
posi := 99;
posi := pos('►', LegalChars); Label1.Caption := IntToStr(posi); // Output to label caption = 0
end;
end.
The intention is to loop through a path/filename testing to see if each character is in the string of legal chars. When a character is not found the loop will break and the path/filename is written to an error file. That means the specific char, '►', will need to be replaced with a string of a char, which might be 1 or 2 or 3 bytes in size, like this.
procedure TForm1.Button1Click(Sender: TObject);
var
LegalChars, PathFile : string; letter : Char; posi : LongInt;
begin
LegalChars :='\ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!$%&‘’()+,-.;=@[]^_`{}~';
posi := 99;
PathFile :='Agua de ►Pena\ROMARIAS\BAILE DA FESTA.mp3';
posi := UTF8Pos(PathFile[9], LegalChars); Label1.Caption := IntToStr(posi); // Output to label caption = 69?
end;
end.
The 69th char in the string of legal chars is: ‘ (single open speech mark).
I have done much reading.
https://wiki.lazarus.freepascal.org/UTF8_strings_and_characters
https://www.pascal-programming.info/lesson10.php
I think I grasp the concepts that 2 and 3 byte characters need to be saved to a string, but it mucks up pos. I am at the edge of my knowledge and any help appreciated
Thanks