* * *

Author Topic: UpCase vs. UpperCase  (Read 350 times)

Pascal

  • Hero Member
  • *****
  • Posts: 541
UpCase vs. UpperCase
« on: December 07, 2017, 07:11:31 am »
Which is best to use?
laz trunk - fpc trunk 32bit - Windows 10 Pro x64

Noodly

  • Jr. Member
  • **
  • Posts: 54
Re: UpCase vs. UpperCase
« Reply #1 on: December 07, 2017, 08:04:32 am »
UpCase is more flexible as it works on chars as well as more string types than UpperCase.

Thaddy

  • Hero Member
  • *****
  • Posts: 4777
Re: UpCase vs. UpperCase
« Reply #2 on: December 07, 2017, 10:09:48 am »
UpCase is more flexible as it works on chars as well as more string types than UpperCase.
Absolutely wrong, Not correct, they are completely equivalent:
   https://www.freepascal.org/docs-html/rtl/sysutils/uppercase.html
The most flexible one has the misleading name AnsiUpperCase which will work with any character set provided a string manager is installed: 
   https://www.freepascal.org/docs-html/rtl/sysutils/ansiuppercase.html

It is rather sad that both of you did not simply RTFM. <grumpy  >:D >:D>
The FPC manuals are excellent. Always read them first.

So: read those two links and you gain some expertise on the subject  ::)

« Last Edit: December 07, 2017, 10:41:53 am by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Noodly

  • Jr. Member
  • **
  • Posts: 54
Re: UpCase vs. UpperCase
« Reply #3 on: December 07, 2017, 11:22:21 am »
Before posting I did RTFM and saw the "completely equivalent statement" in the UpperCase entry. In the context it's badly worded because if it's true then this would compile:

Code: [Select]
program uptest;
uses sysutils;
var
  a,b : char;
begin
  a:='a';
  a:=UpCase(a);
  b:='b';
  b:=UpperCase(b);
end.   

What the FM should say is that "UpperCase has been superseded by (and therefore can be replaced by) the more capable UpCase function and is provided for compatibility only" or words to that effect.

Zath

  • Sr. Member
  • ****
  • Posts: 262
Re: UpCase vs. UpperCase
« Reply #4 on: December 07, 2017, 11:49:28 am »
Is there any reason why new coding to allow for new string formats can't be added to the original command name ?

Thaddy

  • Hero Member
  • *****
  • Posts: 4777
Re: UpCase vs. UpperCase
« Reply #5 on: December 07, 2017, 12:13:17 pm »
Is there any reason why new coding to allow for new string formats can't be added to the original command name ?
Compatibility: the char version from system.pas of UpCase needs to be AnsiChar in the range 1..127. That's a Pascal language issue.

Also not that Uppercase for string in sysutils is deprecated because it is code duplication with upcase for string in system. They are exactly the same.
So if you don't need anything fancy, use upcase from system because you have lighter code as you don't have to include sysutils.
« Last Edit: December 07, 2017, 12:24:04 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Thaddy

  • Hero Member
  • *****
  • Posts: 4777
Re: UpCase vs. UpperCase
« Reply #6 on: December 07, 2017, 12:15:07 pm »
Before posting I did RTFM and saw the "completely equivalent statement" in the UpperCase entry. In the context it's badly worded because if it's true then this would compile:

Code: [Select]
program uptest;
uses sysutils;
var
  a,b : char;
begin
  a:='a';
  a:=UpCase(a);
  b:='b';
  b:=UpperCase(b);
end.   

What the FM should say is that "UpperCase has been superseded by (and therefore can be replaced by) the more capable UpCase function and is provided for compatibility only" or words to that effect.

You are mixing up the old style upcase for char with the new style upcase for string in system. And that one is the same as Uppercase in sysutils. No extra's both ways, same code.
Code: Pascal  [Select]
  1. program untitled;
  2. {$ifdef fpc}{$mode delphi}{$H+}{$I-}{$endif}
  3. uses sysutils;
  4. var
  5.   a,b : string;
  6. begin
  7.   a:='a';
  8.   a:=UpCase(a);
  9.   b:='b';
  10.   b:=UpperCase(b);
  11. end.
   
« Last Edit: December 07, 2017, 12:24:41 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus