[REQ] Error in function Fulltrim?

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

[REQ] Error in function Fulltrim?

Post by fulvio53s03 »

Dear Friends,
some time ago viewtopic.php?t=4139&postdays=0&postord ... m&start=20 I saw that, in my opinion, there was an error in Function FullTrim of StringUtils1 as the function some times truncated the last good letter in a word.
NOw, writing the update of the 35mm.it script I falled in the same error and I constructed a function a little bit different from your 'fulltrim' (see 'here is the difference' in the script).
Here you are an example:

Code: Select all

(***************************************************

Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/

[Infos]
Authors=Fulvio53s03
Title=try Full Trim
Description=
Site=
Language=?
Version=1.0
Requires=3.5
Comments=
License=GPL
GetInfo=0

[Options]

***************************************************)

program TryFullTrim;
uses
  StringUtils1;
var
  TempField, MytrimField, FulltrimField: string;
  ResultPath: string;

function MyTrim(Value: string):string;
var
  ExitLoop: Boolean;
begin
  Result := '';
  ExitLoop := False;
  repeat
    case copy(Value, 1, 1) of
      ' ', #9, #10, #13:    Value := copy(Value, 2, Length(Value)-1);
    else
      ExitLoop := True;
    end;
  until ExitLoop;
  ExitLoop := False;
  repeat
    case copy(Value, Length(Value), 1) of
      ' ', #9, #10, #13:    Value := copy(Value, 1, Length(Value)-1); // here is the difference
    else
      ExitLoop := True;
    end;
  until ExitLoop;
  Result := Value;
end;

begin
 tempfield := #9 + ' ' + #9 + ' ' +#9 + ' ' + 'America' + #9 + ' ' +#9;
 MytrimField := MyTrim(TempField);
 FulltrimField := FullTrim(TempField);

 Showmessage ('***' + MytrimField + '***' + FulltrimField + '***');
end.
Would you try to execute and tell me if my function is always right or if there is a Bug?

Thanks in advance
:wink:
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

Hmm.. this is identical with the FullTrim function from StringUtils1.pas. Maybe you used an older version prior v6 of this file ? Last update of this file was in february (it was updated because of Cp1252ToASCII function, I guess). You can check your file version on constant "StringUtils1_Version = 6;" and you can use this constant in your script to check if user has latest version of StringUtils1 installed, so that you can be sure your script runs correct.

http://update.antp.be/amc/scripts/StringUtils1.pas
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

Thanks Bad4U, You are right (as usual).
I tried to insert the check of Stingutils1 in my script but with bad results. Would you give me an example, Please?

In addition: I saw in new StringUtils1 a function called Cp1252ToASCII and I hoped it could resolve my problems of accented letters (see viewtopic.php?t=4464 but it isn't so.
Would you (or Antp) help me? ... any suggestion? :D

Have a good Sunday You all.
Ciao. :grinking:
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

You can find an example for checking StringUtils1 version and using Cp1252ToASCII function on latest IMDB script:

Code: Select all

function ConvertToASCII(AText: string): string;
begin
  Result := AText;
  if GetOption('ConvertToASCII') = 1 then
  begin
    if StringUtils1_Version > 5 then
      Result := Cp1252ToASCII(AText)
    else
      ShowMessage('The "ConvertToASCII" option requires a newer version of StringUtils1.pas (at least version 6).' + #13#10 + 'Run the "Update Scripts" script to get it.');
  end;
end;
Copy this function to your script and simply use ConvertToASCII(Value) to call it from your code. And/or you can check StringUtils_Version on the beginning of your script if you want make sure it has latest FullTrim version included (there's an example on IMDB script for that, too, simply replace "Checkversion(x,x,x)" with "StringUtils_Version > 5").


About the problem with apostrophes, it should be ok the way you use

Code: Select all

UrlEncode(MovieName)
If it doesn't work for you, try to replace with

Code: Select all

UrlEncode(UTF8Encode(MovieName))
or with

Code: Select all

StringReplace(UrlEncode(UTF8Encode(MovieName)),'''',' ')
Sorry, I do not have time to do some tests at the moment.
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

Allright about check version of StringUtils1 :grinking:
The solutions proposed about accented letters are not OK, unfortunately :cry:
No other Ideas?

Thanks. :shaking:
antp
Site Admin
Posts: 9652
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I get lots of 404 messages with any title that I type, what is that accent problem?
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

@Antp
Thanks.
I think you are getting errors 404 as You are using the old script 35mm.it.
If you try with my new script viewtopic.php?t=4464 you will see that accented vocals are not translated (but in the source of the html page they are non showed)... I tried in a lot of ways to avoid the problem but I don't find solutions... :cry:

Have a good evening.
antp
Site Admin
Posts: 9652
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I thought that I used that update but I have put it in a wrong folder :lol:

The "problem" is that the page is in UTF8, if I understood well you get Luis Buñuel where you want to have Luis Buñuel?
So you have to use UTF8Decode in each SetField which could contain accents.
e.g. : SetField(fieldDirector, UTF8Decode(TempField));
Alternatively (maybe easier, as you have to insert only at one or two point of the script) is to do the UTF8Decode on the whole page before processing it.
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

What can I say? Astonished!

Now it's all Ok (till next doubt :wow:)
Bye.
Post Reply