From 9df61636ae0910edc211ced00073e8162f7fd75b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 28 Nov 2012 13:55:05 +0000 Subject: [PATCH] 2012-11-28 14:53 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/xhb/xhb.hbx * contrib/xhb/xhbcomp.prg + added OCCURS() from xhb which appears there in CT lib, but it's not a CT function. Reworked to meet Harbour standards and to avoid compiler warning. --- harbour/ChangeLog.txt | 7 +++++++ harbour/contrib/xhb/xhb.hbx | 1 + harbour/contrib/xhb/xhbcomp.prg | 27 ++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/harbour/ChangeLog.txt b/harbour/ChangeLog.txt index f41ee70301..a08fd63d0f 100644 --- a/harbour/ChangeLog.txt +++ b/harbour/ChangeLog.txt @@ -10,6 +10,13 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2012-11-28 14:53 UTC+0100 Viktor Szakats (harbour syenar.net) + * contrib/xhb/xhb.hbx + * contrib/xhb/xhbcomp.prg + + added OCCURS() from xhb which appears there in CT lib, + but it's not a CT function. Reworked to meet Harbour standards + and to avoid compiler warning. + 2012-11-28 13:19 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/src/vm/classes.c ! fixed passing be reference pseudo object variables which diff --git a/harbour/contrib/xhb/xhb.hbx b/harbour/contrib/xhb/xhb.hbx index 36048fa4e0..41e34844c1 100644 --- a/harbour/contrib/xhb/xhb.hbx +++ b/harbour/contrib/xhb/xhb.hbx @@ -330,6 +330,7 @@ DYNAMIC NumOrX DYNAMIC NumRolX DYNAMIC NumToHex DYNAMIC NumXorX +DYNAMIC Occurs DYNAMIC Ole2txtError DYNAMIC OleError DYNAMIC os_IsWin2000 diff --git a/harbour/contrib/xhb/xhbcomp.prg b/harbour/contrib/xhb/xhbcomp.prg index 3e2d3bd629..f35c7a893c 100644 --- a/harbour/contrib/xhb/xhbcomp.prg +++ b/harbour/contrib/xhb/xhbcomp.prg @@ -6,7 +6,8 @@ * Harbour Project source code: * xhb compatibility functions * - * Copyright 2007 Viktor Szakats (harbour syenar.net) + * Copyright 2007-2012 Viktor Szakats (harbour syenar.net) + * Copyright 2004 Eduardo Fernandes (original of OCCURS()) * www - http://harbour-project.org * * This program is free software; you can redistribute it and/or modify @@ -147,3 +148,27 @@ CREATE CLASS Block FUNCTION _Block OPERATOR "==" FUNCTION xhb_EEqual() ENDCLASS + +/* Return the number of times s1 occurs in s2 */ +FUNCTION Occurs( s1, s2 ) + + LOCAL nCount := 0 + LOCAL nPos + + IF HB_ISSTRING( s1 ) .AND. ; + HB_ISSTRING( s2 ) .AND. ; + Len( s1 ) != 0 .AND. ; + Len( s2 ) != 0 + + DO WHILE .T. + nPos := At( s1, s2 ) + IF nPos > 0 + nCount++ + s2 := SubStr( s2, nPos + 1 ) + ELSE + EXIT + ENDIF + ENDDO + ENDIF + + RETURN nCount