2012-12-05 17:35 UTC+0100 Viktor Szakats (harbour syenar.net)

* contrib/xhb/regexrpl.prg
  * contrib/xhb/xhb.hbx
    ! minor casing fix

  + contrib/xhb/tests/regexrpl.prg
    + added test from xhb (the function doesn't 
      seem to work)

  + tests/regex.prg
  + tests/regextst.prg
    + added regex tests from xhb

  * contrib/hblzf/tests/test.prg
    ! typos

  * package/winuni/RELNOTES.txt
    * minor
This commit is contained in:
Viktor Szakats
2012-12-05 16:38:11 +00:00
parent ae0b06281b
commit 6c447a486a
8 changed files with 277 additions and 14 deletions

View File

@@ -10,6 +10,25 @@
* Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment
*/
2012-12-05 17:35 UTC+0100 Viktor Szakats (harbour syenar.net)
* contrib/xhb/regexrpl.prg
* contrib/xhb/xhb.hbx
! minor casing fix
+ contrib/xhb/tests/regexrpl.prg
+ added test from xhb (the function doesn't
seem to work)
+ tests/regex.prg
+ tests/regextst.prg
+ added regex tests from xhb
* contrib/hblzf/tests/test.prg
! typos
* package/winuni/RELNOTES.txt
* minor
2012-12-04 23:01 UTC+0100 Viktor Szakats (harbour syenar.net)
* src/3rd/pcre/Makefile
* src/3rd/pcre/pcre.dif

View File

@@ -13,14 +13,14 @@ PROCEDURE Main()
LOCAL b64_expected_result := "BFRoaXMgIAIUdGVzdCBvZiBMWkYgZXh0ZW5zaW9u"
LOCAL nLen, nResult := 0
? "LZF Api version is", ;
hb_ntos( hb_lzf_version() ) + "(0x" + hb_NumToHex( hb_lzf_version() ) + ")"
? "LZF API version is", ;
hb_ntos( hb_lzf_version() ) + " (0x" + hb_NumToHex( hb_lzf_version() ) + ")"
? "LibLZF optimized for", iif( hb_lzf_optimized_for_speed(), "speed.", "compression." )
? "--- test 1 ---"
/*
If the output buffer is not large enough or any error occurs
hb_lzf_compress return NIL
hb_lzf_compress() returns NIL
*/
cStr := TEST_STRING
str_compressed := hb_lzf_compress( cStr, 15, @nResult )
@@ -29,7 +29,7 @@ PROCEDURE Main()
? "Lenght of a string is", hb_ntos( Len( cStr ) )
? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
ELSE
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
ENDIF
? "--- test 2 ---"
@@ -41,7 +41,7 @@ PROCEDURE Main()
? "Lenght of a string is", hb_ntos( Len( cStr ) )
? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
ELSE
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
ENDIF
? "--- test 3 ---"
@@ -56,7 +56,7 @@ PROCEDURE Main()
? iif( hb_base64Encode( str_compressed ) == b64_expected_result, "OK!", "not OK!" )
ELSE
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
ENDIF
? "--- test 4 ---"
@@ -72,7 +72,7 @@ PROCEDURE Main()
? iif( hb_base64Encode( str_compressed ) == b64_expected_result, "OK!", "not OK!" )
ELSE
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
ENDIF
? "--- test 5 ---"
@@ -83,7 +83,7 @@ PROCEDURE Main()
? "Lenght of a string is", hb_ntos( Len( cStr ) )
? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
ELSE
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
? "hb_lzf_compress() returns", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
ENDIF
? "--- test 6 ---"
@@ -128,7 +128,7 @@ PROCEDURE Main()
str_decompressed := hb_lzf_decompress( str_compressed, @str_decompressed, @nResult )
IF nResult != HB_LZF_OK
? "hb_lzf_decompress() return", ;
? "hb_lzf_decompress() returns", ;
iif( nResult == HB_LZF_MEM_ERROR, "HB_LZF_MEM_ERROR", hb_ntos( nResult ) )
ELSE
? iif( cStr == str_decompressed, "OK!", "not OK!" )

View File

@@ -53,7 +53,7 @@
#define MATCH_START 2
#define MATCH_END 3
FUNCTION hb_RegexReplace( cRegex, cString, cReplace, lCaseSensitive, lNewLine, nMaxMatches, nGetMatch )
FUNCTION hb_regexReplace( cRegex, cString, cReplace, lCaseSensitive, lNewLine, nMaxMatches, nGetMatch )
LOCAL aMatches, aMatch
LOCAL cReturn

View File

@@ -0,0 +1,75 @@
/*
* $Id$
*/
/*
* xHarbour Project test code:
* hb_regexReplace( cRegex, cString, cReplace, lCaseSensitive, lNewLine, nMaxMatches, nGetMatch ) --> cReturn
*
* Copyright 2006 Francesco Saverio Giudice <info/at/fsgiudice.com>
* www - http://www.xharbour.org
*
*/
#require "xhb"
PROCEDURE Main()
LOCAL cString, cRegex, cReplace
CLS
? "*** xHarbour hb_regexReplace() test ***"
?
?
? "A simple replace, return is a single match, without submatches."
? "Using 1 to retrieve matches"
cString := "aaabbbcccddd111222333aaabbbcccddd111222333"
cRegex := "aaa"
cReplace := "999"
? "String: ", cString
? "Result: ", hb_regexReplace( cRegEx, cString, cReplace,,,, 1 )
?
? "A replace with a capturing match, return is a submatch."
? "Using 2 to retrieve 1st submatches"
cString := "aaabbbcccddd111222333aaabbbcccddd111222333"
cRegex := "(aaa)"
cReplace := "999"
? "String: ", cString
? "Result: ", hb_regexReplace( cRegEx, cString, cReplace,,,, 2 )
?
WAIT
?
? "Replacing a multiline string searching text that is on single line."
cString := "Hi folks! This is a real" + hb_eol() + "multiline text. Try this as a test."
cRegex := "(?im)this (.*) a"
cReplace := "<IT WORKS!>"
? "String: ", cString
? "Result: ", hb_regexReplace( cRegEx, cString, cReplace,,,, 2 )
?
WAIT
?
? "Replacing a multiline string searching text that is splitted on more lines."
cString := "Hi all. <text>This is a" + hb_eol() + ;
"multiline text.</text> Try this as a test" + hb_eol() + ;
"with <text>another line of text</text>."
cRegex := "(?ims)<text>(.*?)</text>"
cReplace := "<IT WORKS!>"
? "String: ", cString
? "Result: ", hb_regexReplace( cRegEx, cString, cReplace,,,, 2 )
?
WAIT
?
? "Replacing a multifield string."
cString := "/C=IT/O=xHarbour/OU=www.xharbour.com/CN=GIUDICE_FRANCESCO_SAVERIO/email=info@fsgiudice.com"
cRegex := "(?:\/(\w+)=)([\w.@]+)"
cReplace := "<IT WORKS!>"
? "String: ", cString
? "Result: ", hb_regexReplace( cRegEx, cString, cReplace,,,, 2 )
?
WAIT
RETURN

View File

@@ -171,7 +171,7 @@ DYNAMIC hb_QSelf
DYNAMIC hb_QWith
DYNAMIC hb_ReadIni
DYNAMIC hb_ReadLine
DYNAMIC hb_RegexReplace
DYNAMIC hb_regexReplace
DYNAMIC hb_ResetWith
DYNAMIC hb_ServiceGenerateFault
DYNAMIC hb_ServiceGenerateFPE

View File

@@ -108,7 +108,7 @@ Changes since previous (2.0.0beta3 20090905) release:
- New Harbour C level UTF-8 and UTF-16 string handling functions.
- Rewritten internal codepage and collation support. Collations
are now ensured to be CA-Cl*pper compatible.
- HB_TRANSLATE() now supports UTF-8.
- hb_Translate() now supports UTF-8.
- OS/2 platform support improvements (watcom, .dll support, GCC OMF support).
- gtxwc fixes.
- General finalization to *nix Harbour dynamic library generation built into
@@ -133,7 +133,7 @@ Changes since previous (2.0.0beta3 20090905) release:
- Build system now uses automatic version detection for MSVC compilers.
- Core trace message functionality improvements (new .prg level
interface, Windows OutputDebugString support)
- New SET( _SET_DBCODEPAGE ).
- New Set( _SET_DBCODEPAGE ).
- RDDADS fixes.
- Removed support for harbour.cfg and Harbour compiler -go output mode.
- New Harbour types (HB_SIZE, HB_BOOL, etc).
@@ -191,7 +191,7 @@ Changes since previous (2.0.0beta1 20090609) release:
- hbxbp and hbqt enhancements
- hbwin refinements and better compatibility
- new uhttpd2 sessioned HTTP server
- C++ build support for all compilers, new HB_WAEVAL() function,
- C++ build support for all compilers, new hb_WAEval() function,
new xpp (Xbase++ compatibility) lib, .hrb loading enhancements
- DBU, RL, SuperLib fixes.
- MinGW64 updated to 4.4.1

106
harbour/tests/regex.prg Normal file
View File

@@ -0,0 +1,106 @@
/*
* $Id$
*/
// Test for regular expression functions
// Giancarlo Niccolai
PROCEDURE Main()
LOCAL regex
LOCAL aMatch
LOCAL cStr, nRow := 2, nCol
LOCAL aSource := { ;
"First date to match: 2001-3-21", ;
"2002-12/2", ;
"Another can be 1999/5/12, and succeeds", ;
"Could be 1999/534/12, but this will fail" }
CLS
@ 0, 15 SAY "Regular expression scan tests"
/*
* Standard regex to get the ISO date format:
* ([0-9]{4}): exactly four digits (year); it is in brackets,
* this means that we want it back as a group
* [-/]: one bar or a minus
* ([0-9]{1,2}): one or two digits
*/
regex := hb_regexComp( "([0-9]{4})[-/]([0-9]{1,2})[-/]([0-9]{1,2})" )
FOR EACH cStr IN aSource
@ nRow, 5 SAY "String is '" + cStr + "'"
nRow++
aMatch := hb_regex( regex, cStr )
IF ! Empty( aMatch )
@ nRow, 10 SAY "Matched: " + aMatch[ 1 ] + " ( Year: " + aMatch[ 2 ] + ", Month: " + ;
aMatch[ 3 ] + ", Day: " + aMatch[ 4 ] + ")"
ELSE
@ nRow, 10 SAY "Match FAILED!"
ENDIF
nRow += 2
NEXT
cStr := "searching 'regex' here:"
@ nRow, 5 SAY "A test of a regex compiled on the fly; " + cStr
aMatch := hb_regex( "(.*)regex(.*)", cStr )
nRow++
IF Empty( aMatch )
@ nRow, 10 SAY "NOT FOUND!"
ELSE
@ nRow, 10 SAY "Found (Before: <<" + aMatch[ 2 ] + ">>, After: <<" + aMatch[ 3 ] + ">>)"
ENDIF
nRow += 2
cStr := "A str; with: separators :; here "
@ nRow, 5 SAY "Split test; splitting '" + cStr + "' by ':|;'"
nRow++
aMatch := hb_regexSplit( ":|;", cStr )
IF Empty( aMatch )
@ nRow++, 10 SAY "Test failed"
ELSE
nCol := 10
FOR EACH cStr IN aMatch
@ nRow, nCol SAY cStr + "/"
nCol += Len( cStr ) + 1
NEXT
nRow++
ENDIF
cStr := "A string without separators"
@ nRow, 5 SAY "Split test; splitting '" + cStr + "' by ':|;'"
nRow++
aMatch := hb_regexSplit( ":|;", cStr )
IF Empty( aMatch )
@ nRow++, 10 SAY "Test failed"
ELSE
nCol := 10
FOR EACH cStr IN aMatch
@ nRow, nCol SAY cStr + "/"
nCol += Len( cStr ) + 1
NEXT
nRow++
ENDIF
cStr := "Test for RegexAtx"
@ nRow, 5 SAY "RegexAtx test; scanning '" + cStr + "' by 'Reg(.x)'"
nRow++
aMatch := hb_regexAtX( "Reg(.x)", cStr )
IF Empty( aMatch )
@ nRow++, 10 SAY "Test failed"
ELSE
nCol := 15
FOR EACH cStr in aMatch
@ nRow, nCol SAY "FOUND: '" + cStr[ 1 ] + "' Start: " + hb_ntos( cStr[ 2 ] ) + ;
" End: " + hb_ntos( cStr[ 3 ] )
nRow++
NEXT
nRow++
ENDIF
@ nRow, 1
@ 24, 25 SAY "Press a key to continue"
Inkey( 0 )
RETURN

View File

@@ -0,0 +1,63 @@
/*
* $Id$
*/
// Test for regular expression functions -
// This allows to use a fine tune regex to use them in programs
// Giancarlo Niccolai
#include "inkey.ch"
PROCEDURE Main()
LOCAL pCompiled
LOCAL cRegex
LOCAL cSentence
LOCAL nRow, oErr
LOCAL aMatch, cMatch
LOCAL GetList := {}
SET CONFIRM ON
CLS
@ 2, 15 SAY "Regular expression test"
@ 4, 5 SAY "Insert regular expression(s) and strings to test for."
@ 5, 5 SAY "Press <Esc> to exit"
cRegex := Space( 60 )
cSentence := Space( 120 )
DO WHILE LastKey() != K_ESC
@ 8, 5 SAY "REGEX : " GET cRegex PICTURE "@S30"
@ 9, 5 SAY "PHRASE: " GET cSentence PICTURE "@S60"
READ
IF LastKey() != K_ESC
@ 12, 5 CLEAR TO 24, 79
BEGIN SEQUENCE WITH {| oErr | Break( oErr ) }
pCompiled := hb_regexComp( RTrim( cRegex ) )
RECOVER USING oErr
@ 12, 5 SAY "Invalid REGEX expression"
LOOP
END SEQUENCE
aMatch := hb_regex( pCompiled, RTrim( cSentence ) )
IF aMatch != NIL
@ 12, 5 SAY "MATCHES:"
nRow := 13
FOR EACH cMatch IN aMatch
@ nRow++, 5 SAY ">" + cMatch
NEXT
ELSE
@ 12, 5 SAY "No matches"
ENDIF
ENDIF
ENDDO
CLS
RETURN