From c020d709b42bdfb230445273a2f6168ebfeda5f4 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 23 Jul 2007 21:57:48 +0000 Subject: [PATCH] * default widestring-ansistring conversion needs to use the same algorithm as the rtl to behave the same on compile time and runtime git-svn-id: trunk@8161 - --- .gitattributes | 1 + compiler/widestr.pas | 5 ++++- tests/webtbs/tw6737.pp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw6737.pp diff --git a/.gitattributes b/.gitattributes index bf21c3b12c..99473dcd6b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8203,6 +8203,7 @@ tests/webtbs/tw6687.pp svneol=native#text/plain tests/webtbs/tw6690.pp svneol=native#text/plain tests/webtbs/tw6700.pp svneol=native#text/plain tests/webtbs/tw6735.pp svneol=native#text/plain +tests/webtbs/tw6737.pp -text tests/webtbs/tw6742.pp svneol=native#text/plain tests/webtbs/tw6767.pp svneol=native#text/plain tests/webtbs/tw6865.pp svneol=native#text/plain diff --git a/compiler/widestr.pas b/compiler/widestr.pas index b336b6c33f..8736f78d59 100644 --- a/compiler/widestr.pas +++ b/compiler/widestr.pas @@ -225,6 +225,9 @@ unit widestr; dest : pchar; i : longint; begin + { This routine must work the same as the + the routine in the RTL to have the same compile time (for constant strings) + and runtime conversion (for variables) } source:=tcompilerwidecharptr(r^.data); dest:=p; for i:=1 to r^.len do @@ -232,7 +235,7 @@ unit widestr; if word(source^)<128 then dest^:=char(word(source^)) else - dest^:=' '; + dest^:='?'; inc(dest); inc(source); end; diff --git a/tests/webtbs/tw6737.pp b/tests/webtbs/tw6737.pp new file mode 100644 index 0000000000..597dc8c933 --- /dev/null +++ b/tests/webtbs/tw6737.pp @@ -0,0 +1,31 @@ +{$mode objfpc} +{$H+} + +uses sysutils; + +Function AnsiEndsStr(const ASubText, AText: string): Boolean; +begin + Writeln('ZZ',ASubText,'XX ',AText,'YY'); + Result := AnsiCompareStr(Copy(AText,length(AText)-length(ASubText)+1,length(ASubText)),ASubText)=0; +end; + +VAR + s: WideString; + t: WideString; + err : boolean; +BEGIN + s := 'This is a test.'#961#967; + t := 'test.'#961#967; + IF AnsiEndsStr(t, s) THEN + WriteLn('OK.') + ELSE + err:=true; + IF AnsiEndsStr('test.'#961#967, s) THEN + WriteLn('OK.') + ELSE + err:=true; + if err then + WriteLn('Not OK.'); + if err then + halt(1); +END.