Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/Regular Expressions    [ Add a report in this area ]  
Report #:  104561   Status: Closed
InitialCaps() in System.RegularExpressionsCore does not work
Project:  Delphi Build #:  16.0.4429.46931
Version:    16.4 Submitted By:   Jan Goyvaerts
Report Type:  Basic functionality failure Date Reported:  4/1/2012 11:09:40 PM
Severity:    Commonly encountered problem Last Updated: 4/23/2013 8:14:22 AM
Platform:    All platforms Internal Tracking #:   26974
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE4
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
The InitialCaps function in the implementation section of the System.RegularExpressionsCore unit is supposed to capitalize the first letter of each word in S, but it only capitalizes the first character in S.

To fix this, this line:

Result[1] := UpperCase(S[1], loUserLocale)[1];

must be changed into:

Result[I] := UpperCase(Result[I], loUserLocale)[1];
Steps to Reproduce:
By USc:
- dcc QC104561.dpr
- execute QC104561

expected: output is PASS
actual: output is
FAIL #4
  Expected:        "Hello World"
  Actual:          "Hello world"
  Different chars: "      !    "
FAIL

program QC104561;

{$APPTYPE CONSOLE}

uses
  System.RegularExpressions;

var
  Counter: Integer = 0;

procedure EvalStrings(const Actual, AExpected: string; ATest: Integer);
var
  I, M: Integer;
  S: string;
begin
  if Actual = AExpected then
    Inc(Counter)
  else
  begin
    WriteLn('FAIL #', ATest);
    WriteLn('  Expected:        "', AExpected, '"');
    WriteLn('  Actual:          "', Actual, '"');
    M := Length(Actual);
    if Length(AExpected) < M then
      M := Length(AExpected);
    S := StringOfChar(' ', M);
    for I := 1 to M do
      if Actual[I] <> AExpected[I] then
        S[I] := '!';
    WriteLn('  Different chars: "', S, '"');
  end;
end;

begin
  EvalStrings(TRegEx.Replace('HeLlO WoRlD', '.+', '\u0'), 'HELLO WORLD', 1);
  EvalStrings(TRegEx.Replace('HeLlO WoRlD', '.+', '\l0'), 'hello world', 2);
  EvalStrings(TRegEx.Replace('HeLlO WoRlD', '.+', '\f0'), 'Hello world', 3);
  EvalStrings(TRegEx.Replace('HeLlO WoRlD', '.+', '\i0'), 'Hello World', 4);
  if Counter = 4 then
    WriteLn('PASS')
  else
    WriteLn('FAIL');
end.




Original steps:
This code:

  WriteLn(TRegEx.Replace('HeLlO WoRlD', '.+', '\u0'));
  WriteLn(TRegEx.Replace('HeLlO WoRlD', '.+', '\l0'));
  WriteLn(TRegEx.Replace('HeLlO WoRlD', '.+', '\f0'));
  WriteLn(TRegEx.Replace('HeLlO WoRlD', '.+', '\i0'));

is supposed to print:

HELLO WORLD
hello world
Hello world
Hello World

but it actually prints:

HELLO WORLD
hello world
Hello world
Hello world

The 3rd and 4th lines are the same, but they should be different.
Workarounds
None
Attachment
None
Comments

Tomohiro Takahashi at 4/3/2012 7:19:37 PM -
This report was opened with valid Internal Tracking Number.
Thanks.

Server Response from: ETNACODE01