Browse Source

--- Merging r14785 into '.':
A tests/test/units/strutils
A tests/test/units/strutils/posextest.pp
U tests/Makefile.fpc
C tests/Makefile
--- Merging r14786 into '.':
U rtl/objpas/strutils.pp
--- Merging r14818 into '.':
U rtl/objpas/classes/lists.inc
--- Merging r14819 into '.':
U packages/winunits-base/src/activex.pp
Summary of conflicts:
Text conflicts: 1

# revisions: 14785,14786,14818,14819
------------------------------------------------------------------------
r14785 | marco | 2010-01-23 23:02:44 +0100 (Sat, 23 Jan 2010) | 2 lines
Changed paths:
M /trunk/tests/Makefile
M /trunk/tests/Makefile.fpc
A /trunk/tests/test/units/strutils
A /trunk/tests/test/units/strutils/posextest.pp

* strutils rtl unit dir + test of posex. (related to bug #15357)

------------------------------------------------------------------------
------------------------------------------------------------------------
r14786 | marco | 2010-01-23 23:03:20 +0100 (Sat, 23 Jan 2010) | 2 lines
Changed paths:
M /trunk/rtl/objpas/strutils.pp

* fix for #0 problem in posex + faster (indexbyte) based implementations.

------------------------------------------------------------------------
------------------------------------------------------------------------
r14818 | marco | 2010-01-27 20:49:28 +0100 (Wed, 27 Jan 2010) | 2 lines
Changed paths:
M /trunk/rtl/objpas/classes/lists.inc

* fix for 15597. Added returnvalue to early-out exit().

------------------------------------------------------------------------
------------------------------------------------------------------------
r14819 | marco | 2010-01-27 20:58:58 +0100 (Wed, 27 Jan 2010) | 2 lines
Changed paths:
M /trunk/packages/winunits-base/src/activex.pp

* OLE_COLOR and OLE_HANDLE

------------------------------------------------------------------------

git-svn-id: branches/fixes_2_4@14832 -

marco 15 years ago
parent
commit
8e870b54d0

+ 1 - 0
.gitattributes

@@ -8651,6 +8651,7 @@ tests/test/units/sharemem/test1.pp svneol=native#text/plain
 tests/test/units/softfpu/sfttst.pp svneol=native#text/plain
 tests/test/units/strings/tstrcopy.pp svneol=native#text/plain
 tests/test/units/strings/tstrings1.pp svneol=native#text/plain
+tests/test/units/strutils/posextest.pp svneol=native#text/plain
 tests/test/units/system/interlocked1.pp svneol=native#text/plain
 tests/test/units/system/tabs.pp svneol=native#text/plain
 tests/test/units/system/talign.pp svneol=native#text/plain

+ 8 - 0
packages/winunits-base/src/activex.pp

@@ -57,6 +57,14 @@ type
    BSTR	               = POLESTR;
    TOleDate	       = DATE;
    POleDate	       = ^TOleDate;	
+   OLE_HANDLE	       = UINT;
+   LPOLE_HANDLE        = ^OLE_HANDLE;
+   OLE_COLOR	       = DWORD;
+   LPOLE_COLOR         = ^OLE_COLOR;
+   TOleHandle          = OLE_HANDLE;
+   POleHandle          = LPOLE_HANDLE;
+   TOleColor           = OLE_COLOR;
+   POleColor           = LPOle_Color;
 
 CONST
    GUID_NULL  : TGUID =  '{00000000-0000-0000-0000-000000000000}';

+ 1 - 1
rtl/objpas/classes/lists.inc

@@ -174,7 +174,7 @@ function TFPList.Expand: TFPList;
 var
   IncSize : Longint;
 begin
-  if FCount < FCapacity then exit;
+  if FCount < FCapacity then exit(self);
   IncSize := 4;
   if FCapacity > 3 then IncSize := IncSize + 4;
   if FCapacity > 8 then IncSize := IncSize+8;

+ 40 - 28
rtl/objpas/strutils.pp

@@ -618,45 +618,57 @@ begin
   Result:=SearchBuf(Buf,BufLen,SelStart,SelLength,SearchString,[soDown]);
 end;
 
-
 Function PosEx(const SubStr, S: string; Offset: Cardinal): Integer;
 
-var i : pchar;
+var
+  i,MaxLen, SubLen : SizeInt;
+  SubFirst: Char;
+  pc : pchar;
 begin
-  if (offset<1) or (offset>SizeUInt(length(s))) then exit(0);
-  i:=strpos(@s[offset],@substr[1]);
-  if i=nil then
-    PosEx:=0
-  else
-    PosEx:=succ(i-pchar(pointer(s)));
+  PosEx:=0;
+  SubLen := Length(SubStr);
+  if (SubLen > 0) and (Offset > 0) and (Offset <= Cardinal(Length(S))) then
+   begin
+    MaxLen := Length(S)- SubLen;
+    SubFirst := SubStr[1];
+    i := indexbyte(S[Offset],Length(S) - Offset + 1, Byte(SubFirst));
+    while (i >= 0) and ((i + sizeint(Offset) - 1) <= MaxLen) do
+    begin
+      pc := @S[i+SizeInt(Offset)];
+      //we know now that pc^ = SubFirst, because indexbyte returned a value > -1
+      if (CompareByte(Substr[1],pc^,SubLen) = 0) then
+      begin
+        PosEx := i + SizeInt(Offset);
+        Exit;
+      end;
+      //point Offset to next char in S
+      Offset := sizeuint(i) + Offset + 1;
+      i := indexbyte(S[Offset],Length(S) - Offset + 1, Byte(SubFirst));
+    end;
+  end;
 end;
 
+Function PosEx(c:char; const S: string; Offset: Cardinal): Integer;
+
+var
+  Len : longint;
+  p: SizeInt;
+begin
+  Len := length(S);
+  if (Offset < 1) or (Offset > SizeUInt(Length(S))) then exit(0);
+  Len := length(S);
+  p := indexbyte(S[Offset],Len-offset+1,Byte(c));
+  if (p < 0) then
+    PosEx := 0
+  else
+    PosEx := p + sizeint(Offset);
+end; 
 
 Function PosEx(const SubStr, S: string): Integer;inline; // Offset: Cardinal = 1
 begin
   posex:=posex(substr,s,1);
 end;
 
-
-Function PosEx(c:char; const S: string; Offset: Cardinal): Integer;
-
-var l : longint;
-begin
-  if (offset<1) or (offset>SizeUInt(length(s))) then exit(0);
-  l:=length(s);
-{$ifndef useindexbyte}
-  while (SizeInt(offset)<=l) and (s[offset]<>c) do inc(offset);
-  if SizeInt(offset)>l then
-   posex:=0
-  else
-   posex:=offset;
-{$else}
-  posex:=offset+indexbyte(s[offset],l-offset+1);
-  if posex=(offset-1) then
-    posex:=0;
-{$endif}
-end;
-
 function StringsReplace(const S: string; OldPattern, NewPattern: array of string;  Flags: TReplaceFlags): string;
 
 var pc,pcc,lastpc : pchar;

+ 9 - 2
tests/Makefile

@@ -2,7 +2,7 @@
 # Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/01/25]
 #
 default: allexectests
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx haiku
 LIMIT83fs = go32v2 os2 emx watcom
@@ -607,6 +607,10 @@ ifeq ($(OS_TARGET),symbian)
 SHAREDLIBEXT=.dll
 SHORTSUFFIX=symbian
 endif
+ifeq ($(OS_TARGET),NativeNT)
+SHAREDLIBEXT=.dll
+SHORTSUFFIX=nativent
+endif
 else
 ifeq ($(OS_TARGET),go32v1)
 PPUEXT=.pp1
@@ -1192,6 +1196,9 @@ endif
 ifdef EXEFILES
 override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
 endif
+ifdef CLEAN_PROGRAMS
+override CLEANEXEFILES+=$(addprefix $(TARGETDIRPREFIX),$(addsuffix $(EXEEXT), $(CLEAN_PROGRAMS)))
+endif
 ifdef CLEAN_UNITS
 override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
 endif
@@ -1467,7 +1474,7 @@ endif
 ifndef LOG
 export LOG:=$(TEST_OUTPUTDIR)/log
 endif
-TESTSUBDIRS=cg cg/variants cg/cdecl opt units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem
+TESTSUBDIRS=cg cg/variants cg/cdecl opt units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem units/strutils
 TESTPACKAGESUBDIRS=cg packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib packages/fcl-db packages/fcl-base packages/fcl-xml
 ifdef QUICKTEST
 export QUICKTEST

+ 1 - 1
tests/Makefile.fpc

@@ -128,7 +128,7 @@ endif
 
 
 # Subdirs available in the test subdir
-TESTSUBDIRS=cg cg/variants cg/cdecl opt units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem
+TESTSUBDIRS=cg cg/variants cg/cdecl opt units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem units/strutils
 TESTPACKAGESUBDIRS=cg packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib packages/fcl-db packages/fcl-base packages/fcl-xml
 
 ifdef QUICKTEST

+ 51 - 0
tests/test/units/strutils/posextest.pp

@@ -0,0 +1,51 @@
+{$mode objfpc} {$h+}
+{$hints on}
+{$warnings on}
+
+uses strutils;
+
+var doexit : integer =0;
+
+procedure posTest(const substr,str:ansistring;start:integer;shouldberes:integer;testnr:integer);
+
+var res : integer;
+
+begin
+  res:=posex(substr,str,start);
+  if res<>shouldberes then
+   begin
+     writeln('test ',testnr:5,' resulted in ',res:5,' should be ',shouldberes);
+     doexit:=1;
+   end;
+  if res>0 then
+   begin
+     if copy(str,res,length(substr))<>substr then
+      begin
+        doexit:=1;
+        writeln('test ',testnr,' doesn''t match search phrase');
+      end;
+   end;
+end; 
+
+const 
+  S = 'Start'+#0#1+'BaseLevel'+#0#2+'Sublevel1'+#0#2+'Sublevel2'+#0#1+'LastOne';
+  Sub = 'LastOne';
+
+  s2 = '1234one8901one';
+  s3 = '1234one8901on';
+  s4 = '1234on234on3';
+begin
+  postest(sub,s,1,41,1);
+  postest('One',s,1,45,2);
+  postest('Start',s,1,1,3);
+  postest('one',s2,1,5,4);
+  postest('one',s2,6,12,5);
+  postest('one',s3,6,0,6);
+  postest('one',s3,0,0,7);
+  postest('one',s2,14,0,8);
+  postest('One',s2,1,0,9); // test if compare is case sensitive
+  postest('one',s4,1,0,10); // test if compare is case sensitive
+
+  if doexit>0 then
+    halt(1);
+end.