View Issue Details

IDProjectCategoryView StatusLast Update
0035098FPCPackagespublic2019-02-16 17:50
ReporterBart BroersmaAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86_64OSLinux MintOS Version18.0
Product Version3.3.1Product Buildr41332 
Target Version3.2.0Fixed in Version3.3.1 
Summary0035098: Request: add aCount parameter to StrUtils.StringReplace
DescriptionAs a follow-up to 0023987: could the StringReplace versions of StrUtils also be overloaded with versions that have the aCount parameter?
(Since 0023987 is resolved and I cannot reopen it, I opend a new issue.)
TagsNo tags attached.
Fixed in Revision41343
FPCOldBugId
FPCTarget
Attached Files

Activities

Michael Van Canneyt

2019-02-16 15:52

administrator   ~0114184

Added here as well, please test and close if OK.

Bart Broersma

2019-02-16 16:48

reporter   ~0114186

The UnicodeString and WideString variants do not to seem to be overloaded?

Also I'm a little bit confused now since when I use either UnicodeString or WideString (for all parameters and returnvalues) the compiler warns about implicit conversions from Unicode/Wide->Ansi for all parameters and Ansi->Unicode/Wide for the result?
It does this for both the SysUtils.StringReplace() and StrUtils.StringReplace().

According to 0028396 we do have a UnicodeString and WideString implementation of SysUtils.StringReplace?



{$mode objfpc}
{$h+}
uses
  sysutils, strutils;
const
  OldP = 'abc';
  NewP = 'xyz';
  Orig = 'abc def abc ABC def def';
var
  S: String;
  Count: Integer;
  W, OldPW, NewPW, OrigW: WideString;
  U, OldPU, NewPU, OrigU: UnicodeString;
begin
  OldPW := WideString(OldP);
  NewPW := WideString(NewP);
  OrigW := WideString(Orig);
  OldPU := UnicodeString(OldP);
  NewPU := UnicodeString(NewP);
  OrigU := UnicodeString(Orig);

  S := SysUtils.StringReplace(Orig, OldP, NewP, [rfReplaceAll,rfIgnoreCase], Count);
  W := SysUtils.StringReplace(OrigW, OldPW, NewPW, [rfReplaceAll,rfIgnoreCase], Count);
  U := SysUtils.StringReplace(OrigU, OldPU, NewPU, [rfReplaceAll,rfIgnoreCase], Count);

  S := StrUtils.StringReplace(Orig, OldP, NewP, [rfReplaceAll,rfIgnoreCase], Count);
  W := StrUtils.StringReplace(OrigW, OldPW, NewPW, [rfReplaceAll,rfIgnoreCase], Count);
  U := StrUtils.StringReplace(OrigU, OldPU, NewPU, [rfReplaceAll,rfIgnoreCase], Count);
end.


C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas
Free Pascal Compiler version 3.3.1 [2019/02/16] for i386
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
test.pas(23,50) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString"
test.pas(23,43) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString"
test.pas(23,36) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString"
test.pas(23,8) Warning: Implicit string type conversion from "AnsiString" to "WideString"
test.pas(24,50) Warning: Implicit string type conversion with potential data loss from "UnicodeString" to "AnsiString"
test.pas(24,43) Warning: Implicit string type conversion with potential data loss from "UnicodeString" to "AnsiString"
test.pas(24,36) Warning: Implicit string type conversion with potential data loss from "UnicodeString" to "AnsiString"
test.pas(24,8) Warning: Implicit string type conversion from "AnsiString" to "UnicodeString"
test.pas(27,50) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString"
test.pas(27,43) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString"
test.pas(27,36) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString"
test.pas(27,8) Warning: Implicit string type conversion from "AnsiString" to "WideString"
test.pas(28,50) Warning: Implicit string type conversion with potential data loss from "UnicodeString" to "AnsiString"
test.pas(28,43) Warning: Implicit string type conversion with potential data loss from "UnicodeString" to "AnsiString"
test.pas(28,36) Warning: Implicit string type conversion with potential data loss from "UnicodeString" to "AnsiString"
test.pas(28,8) Warning: Implicit string type conversion from "AnsiString" to "UnicodeString"

Michael Van Canneyt

2019-02-16 16:55

administrator   ~0114187

The unicode/widestring variants are untested even for the case without count.
The whole strutils is not tested or meant to work with unicode.

So, no unicode. I will solve this by making a unicode version of strutils.

As for sysutils there is UnicodeStringReplace and WideStringReplace. They have the count parameter too.

Bart Broersma

2019-02-16 17:50

reporter   ~0114192

OK, thanks.

Issue History

Date Modified Username Field Change
2019-02-16 10:35 Bart Broersma New Issue
2019-02-16 10:44 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-02-16 10:44 Michael Van Canneyt Status new => assigned
2019-02-16 15:52 Michael Van Canneyt Fixed in Revision => 41343
2019-02-16 15:52 Michael Van Canneyt Note Added: 0114184
2019-02-16 15:52 Michael Van Canneyt Status assigned => resolved
2019-02-16 15:52 Michael Van Canneyt Fixed in Version => 3.3.1
2019-02-16 15:52 Michael Van Canneyt Resolution open => fixed
2019-02-16 15:52 Michael Van Canneyt Target Version => 3.2.0
2019-02-16 16:48 Bart Broersma Note Added: 0114186
2019-02-16 16:48 Bart Broersma Status resolved => feedback
2019-02-16 16:48 Bart Broersma Resolution fixed => reopened
2019-02-16 16:55 Michael Van Canneyt Note Added: 0114187
2019-02-16 16:55 Michael Van Canneyt Status feedback => resolved
2019-02-16 16:55 Michael Van Canneyt Resolution reopened => fixed
2019-02-16 17:50 Bart Broersma Note Added: 0114192
2019-02-16 17:50 Bart Broersma Status resolved => closed