View Issue Details

IDProjectCategoryView StatusLast Update
0032404FPCPackagespublic2018-07-30 23:26
ReporterCudaText manAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version3.0.2Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0032404: RegExpr: need WideUpperCase/WideLowerCase
DescriptionIn Unicode define mode, need WideUpperCase instead of AnsiUpperCase


class function TRegExpr.InvertCaseFunction (const Ch : REChar) : REChar;
 begin
  {$IFDEF UniCode}
  if Ch >= 0000128
   then Result := Ch
  else
  {$ENDIF}
   begin
    Result := {$IFDEF FPC}AnsiUpperCase (Ch) [1]{$ELSE} {$IFDEF SYN_WIN32}REChar (CharUpper (PChar (Ch))){$ELSE}REChar (toupper (integer (Ch))){$ENDIF} {$ENDIF};
    if Result = Ch
     then Result := {$IFDEF FPC}AnsiLowerCase (Ch) [1]{$ELSE} {$IFDEF SYN_WIN32}REChar (CharLower (PChar (Ch))){$ELSE}REChar(tolower (integer (Ch))){$ENDIF} {$ENDIF};
   end;
 end; { of function TRegExpr.InvertCaseFunction



also, make this code more readable.
TagsNo tags attached.
Fixed in Revision39534
FPCOldBugId
FPCTarget
Attached Files

Activities

CudaText man

2017-09-11 23:04

reporter   ~0102788

If using WideUpperCase, fix also condition "code >= 128".

Michael Van Canneyt

2017-09-12 10:00

administrator   ~0102793

Can you please provide a test program that demonstrates the issue ?

CudaText man

2017-09-12 11:54

reporter   ~0102798

Doc about regex change case
http://wiki.freepascal.org/CudaText#Change_case_on_replaces

- in Lazarus, open new tab
- enter text
pro про

- test that "про" dont change case:
- call Replace dialog
- enter from ".+", to "\U$0"
- case changed only for EN word, not RU word

Michael Van Canneyt

2017-09-12 11:56

administrator   ~0102799

I actually need a compileable demo program that demonstrates the bug, so I can enter it in the testsuite

CudaText man

2017-09-12 12:08

reporter  

tst-regex-upcase.zip (2,137 bytes)

CudaText man

2017-09-12 12:09

reporter   ~0102800

Lazarus demo. attach.
it shows non Unicode replace: up-case + low-case. RU text not changed.

Michael Van Canneyt

2017-09-12 12:15

administrator   ~0102801

Thank you.

Reworked to:
home:~/Documents/tst-regex-upcase> cat testre.pp
program testure;

{$mode objfpc}
{$H+}
{$CODEPAGE UTF8}

uses
  Classes, SysUtils, regexpr;

var
  r: TRegExpr;
  s, s2: string;
begin
  r:= TRegExpr.create;
  r.Expression:= '.+';
  s:= 'pro про';
  s2:= r.Replace(s, '\U$0', true);
  Writeln(Format('Upcase of "%s" -> "%s"', [s, s2]));

  s:= 'PRO ПРО';
  s2:= r.Replace(s, '\L$0', true);
  Writeln(Format('Lowcase of "%s" -> "%s"', [s, s2]));
end.
home:~/Documents/tst-regex-upcase> fpc testre.pp
home:~/Documents/tst-regex-upcase> ./testre
Upcase of "pro про" -> "PRO про"
Lowcase of "PRO ПРО" -> "pro ПРО"

CudaText man

2017-09-12 13:50

reporter   ~0102803

fix it in TRegExpr.Substitute

    if p0 < p1 then begin
      while p0 < p1 do begin
        case Mode of
          smodeOneLower, smodeAllLower:
            begin
              Ch := p0^;
              Ch := WideLowerCase(Ch)[1];
              ResultPtr^ := Ch;
              if Mode = smodeOneLower then
                Mode := smodeNormal;
            end;
          smodeOneUpper, smodeAllUpper:
            begin
              Ch := p0^;
              Ch := WideUpperCase(Ch)[1];
              ResultPtr^ := Ch;
              if Mode = smodeOneUpper then
                Mode := smodeNormal;
            end;

but only if Unicode define on.

rd0x

2018-01-26 20:43

reporter   ~0106055

Another solution/workaround seems to be here: (use UpCase for condition code)
https://forum.lazarus.freepascal.org/index.php/topic,39578.msg272230.html#msg272230

Thaddy de Koning

2018-01-26 22:03

reporter   ~0106057

Or Uppercase, which has unicodestring overloads

Michael Van Canneyt

2018-07-30 23:26

administrator   ~0109773

Fixed, when compiled with uregexp, output of program is now:

Upcase of "pro про" -> "PRO ПРО"
Lowcase of "PRO ПРО" -> "pro про"

Issue History

Date Modified Username Field Change
2017-09-11 23:02 CudaText man New Issue
2017-09-11 23:04 CudaText man Note Added: 0102788
2017-09-12 10:00 Michael Van Canneyt Note Added: 0102793
2017-09-12 10:00 Michael Van Canneyt Assigned To => Michael Van Canneyt
2017-09-12 10:00 Michael Van Canneyt Status new => feedback
2017-09-12 11:54 CudaText man Note Added: 0102798
2017-09-12 11:54 CudaText man Status feedback => assigned
2017-09-12 11:56 Michael Van Canneyt Note Added: 0102799
2017-09-12 11:57 Michael Van Canneyt Status assigned => feedback
2017-09-12 12:08 CudaText man File Added: tst-regex-upcase.zip
2017-09-12 12:09 CudaText man Note Added: 0102800
2017-09-12 12:09 CudaText man Status feedback => assigned
2017-09-12 12:15 Michael Van Canneyt Note Added: 0102801
2017-09-12 13:50 CudaText man Note Added: 0102803
2018-01-26 20:43 rd0x Note Added: 0106055
2018-01-26 22:03 Thaddy de Koning Note Added: 0106057
2018-07-30 23:26 Michael Van Canneyt Fixed in Revision => 39534
2018-07-30 23:26 Michael Van Canneyt Note Added: 0109773
2018-07-30 23:26 Michael Van Canneyt Status assigned => resolved
2018-07-30 23:26 Michael Van Canneyt Fixed in Version => 3.1.1
2018-07-30 23:26 Michael Van Canneyt Resolution open => fixed
2018-07-30 23:26 Michael Van Canneyt Target Version => 3.2.0