Browse Source

* 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 -

peter 18 years ago
parent
commit
c020d709b4
3 changed files with 36 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 4 1
      compiler/widestr.pas
  3. 31 0
      tests/webtbs/tw6737.pp

+ 1 - 0
.gitattributes

@@ -8203,6 +8203,7 @@ tests/webtbs/tw6687.pp svneol=native#text/plain
 tests/webtbs/tw6690.pp svneol=native#text/plain
 tests/webtbs/tw6690.pp svneol=native#text/plain
 tests/webtbs/tw6700.pp svneol=native#text/plain
 tests/webtbs/tw6700.pp svneol=native#text/plain
 tests/webtbs/tw6735.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/tw6742.pp svneol=native#text/plain
 tests/webtbs/tw6767.pp svneol=native#text/plain
 tests/webtbs/tw6767.pp svneol=native#text/plain
 tests/webtbs/tw6865.pp svneol=native#text/plain
 tests/webtbs/tw6865.pp svneol=native#text/plain

+ 4 - 1
compiler/widestr.pas

@@ -225,6 +225,9 @@ unit widestr;
         dest   : pchar;
         dest   : pchar;
         i      : longint;
         i      : longint;
       begin
       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);
         source:=tcompilerwidecharptr(r^.data);
         dest:=p;
         dest:=p;
         for i:=1 to r^.len do
         for i:=1 to r^.len do
@@ -232,7 +235,7 @@ unit widestr;
            if word(source^)<128 then
            if word(source^)<128 then
             dest^:=char(word(source^))
             dest^:=char(word(source^))
            else
            else
-            dest^:=' ';
+            dest^:='?';
            inc(dest);
            inc(dest);
            inc(source);
            inc(source);
          end;
          end;

+ 31 - 0
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.