]> gitweb.factorcode.org Git - factor.git/commitdiff
pcre: using private to hide implementation details.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 20 Nov 2013 21:06:49 +0000 (13:06 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 20 Nov 2013 21:06:49 +0000 (13:06 -0800)
extra/pcre/info/info-tests.factor [deleted file]
extra/pcre/info/info.factor [deleted file]
extra/pcre/pcre-tests.factor
extra/pcre/pcre.factor
extra/pcre/utils/utils-tests.factor [deleted file]
extra/pcre/utils/utils.factor [deleted file]

diff --git a/extra/pcre/info/info-tests.factor b/extra/pcre/info/info-tests.factor
deleted file mode 100644 (file)
index be689fd..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-USING: accessors pcre pcre.info pcre.utils sequences tools.test ;
-
-[ { { 3 "day" } { 2 "month" } { 1 "year" } } ]
-[
-    "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})" <compiled-pcre>
-    nametable>>
-] unit-test
-
-[ { 100 110 120 130 } ] [ 100 10 4 gen-array-addrs ] unit-test
diff --git a/extra/pcre/info/info.factor b/extra/pcre/info/info.factor
deleted file mode 100644 (file)
index faad079..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-USING:
-    accessors
-    alien alien.accessors alien.c-types alien.data alien.strings
-    arrays
-    io.encodings.utf8
-    kernel
-    math math.bitwise
-    pcre.ffi pcre.utils
-    sequences ;
-IN: pcre.info
-
-! Mostly internal
-: fullinfo ( pcre extra what -- obj )
-    { int } [ pcre_fullinfo ] with-out-parameters nip ;
-
-: name-count ( pcre extra -- n )
-    PCRE_INFO_NAMECOUNT fullinfo ;
-
-: name-table ( pcre extra -- addr )
-    [ drop alien-address 32 on-bits unmask ]
-    [ PCRE_INFO_NAMETABLE fullinfo ] 2bi + ;
-
-: name-entry-size ( pcre extra -- size )
-    PCRE_INFO_NAMEENTRYSIZE fullinfo ;
-
-: name-table-entry ( addr -- group-index group-name )
-    [ <alien> 1 alien-unsigned-1 ]
-    [ 2 + <alien> utf8 alien>string ] bi ;
-
-: options ( pcre -- opts )
-    f PCRE_INFO_OPTIONS fullinfo ;
-
-! Exported
-: name-table-entries ( pcre extra -- addrs )
-    [ name-table ] [ name-entry-size ] [ name-count ] 2tri
-    gen-array-addrs [ name-table-entry 2array ] map ;
index 2a78fa4a0befbf7343829cb11bf92bb9d7ac53c9..3d51014c26cae4f595496aeef946b872594d6051 100644 (file)
@@ -1,18 +1,19 @@
-USING:
-    accessors
-    arrays
-    assocs
-    http.client
-    kernel
-    math math.ranges
-    pcre pcre.ffi pcre.info
-    random
-    sequences
-    system
-    tools.test ;
+USING: accessors arrays assocs http.client kernel math.ranges
+pcre pcre.ffi pcre.private random sequences system tools.test ;
 QUALIFIED: regexp
 IN: pcre.tests
 
+[ { "Bords" "words" "word" } ] [
+    "Bords, words, word." { ", " ", " "." } split-subseqs
+] unit-test
+
+[ { { 3 "day" } { 2 "month" } { 1 "year" } } ] [
+    "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"
+    <compiled-pcre> nametable>>
+] unit-test
+
+[ { 100 110 120 130 } ] [ 100 10 4 gen-array-addrs ] unit-test
+
 CONSTANT: iso-date "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"
 
 ! On windows the erroffset appears to be set to 0 despite there being
index 008a04a90a3a11769de024ed12052feda8b50327..e66e1ad769a6094579dc51ecf883b9ceee93a792 100644 (file)
@@ -1,18 +1,51 @@
-USING:
-    accessors
-    alien.c-types alien.data alien.enums alien.strings
-    arrays
-    assocs
-    io.encodings.utf8 io.encodings.string
-    kernel
-    math
-    mirrors
-    pcre.ffi pcre.info pcre.utils
-    sequences sequences.generalizations
-    strings ;
+USING: accessors alien alien.accessors alien.c-types alien.data
+alien.enums alien.strings arrays assocs fry io.encodings.string
+io.encodings.utf8 kernel math math.bitwise mirrors pcre.ffi
+sequences sequences.generalizations splitting strings ;
 QUALIFIED: regexp
 IN: pcre
 
+<PRIVATE
+
+: 2with ( param1 param2 obj quot -- obj curry )
+    [ -rot ] dip [ [ rot ] dip call ] 3curry ; inline
+
+: gen-array-addrs ( base size n -- addrs )
+    iota [ * + ] 2with map ;
+
+: utf8-start-byte? ( byte -- ? )
+    0xc0 bitand 0x80 = not ;
+
+: next-utf8-char ( byte-array pos -- pos' )
+    1 + 2dup swap ?nth
+    [ utf8-start-byte? [ nip ] [ next-utf8-char ] if ] [ 2drop f ] if* ;
+
+: fullinfo ( pcre extra what -- obj )
+    { int } [ pcre_fullinfo ] with-out-parameters nip ;
+
+: name-count ( pcre extra -- n )
+    PCRE_INFO_NAMECOUNT fullinfo ;
+
+: name-table ( pcre extra -- addr )
+    [ drop alien-address 32 on-bits unmask ]
+    [ PCRE_INFO_NAMETABLE fullinfo ] 2bi + ;
+
+: name-entry-size ( pcre extra -- size )
+    PCRE_INFO_NAMEENTRYSIZE fullinfo ;
+
+: name-table-entry ( addr -- group-index group-name )
+    [ <alien> 1 alien-unsigned-1 ] 
+    [ 2 + <alien> utf8 alien>string ] bi ; 
+
+: options ( pcre -- opts ) 
+    f PCRE_INFO_OPTIONS fullinfo ;
+
+: name-table-entries ( pcre extra -- addrs )
+    [ name-table ] [ name-entry-size ] [ name-count ] 2tri
+    gen-array-addrs [ name-table-entry 2array ] map ;
+
+PRIVATE>
+
 ERROR: malformed-regexp expr error ;
 ERROR: pcre-error value ;
 
@@ -86,7 +119,7 @@ GENERIC: findall ( subject obj -- matches )
 
 M: compiled-pcre findall
     [ <matcher> [ findnext ] follow [ match>> ] map harvest ]
-    [ nametable>> rot [ parse-match ] 2with map ] 2bi >array ;
+    [ nametable>> rot [ parse-match ] 2with { } map-as ] 2bi ;
 
 M: string findall
     <compiled-pcre> findall ;
@@ -97,5 +130,15 @@ M: regexp:regexp findall
 : matches? ( subject obj -- ? )
     dupd findall [ nip length 1 = ] [ ?first ?first ?last = ] 2bi and ;
 
+<PRIVATE
+
+: replace-all ( seq subseqs new -- seq )
+    swapd '[ _ replace ] reduce ;
+
+: split-subseqs ( seq subseqs -- seqs )
+    dup first [ replace-all ] keep split-subseq [ >string ] map harvest ;
+
+PRIVATE>
+
 : split ( subject obj -- strings )
     dupd findall [ first second ] map split-subseqs ;
diff --git a/extra/pcre/utils/utils-tests.factor b/extra/pcre/utils/utils-tests.factor
deleted file mode 100644 (file)
index f53b823..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-USING: pcre.utils tools.test ;
-IN: pcre.utils.tests
-
-[ { "Bords" "words" "word" } ] [
-    "Bords, words, word." { ", " ", " "." } split-subseqs
-] unit-test
diff --git a/extra/pcre/utils/utils.factor b/extra/pcre/utils/utils.factor
deleted file mode 100644 (file)
index f5fea26..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-USING: assocs fry kernel math mirrors sequences splitting strings ;
-IN: pcre.utils
-
-: replace-all ( seq subseqs new -- seq )
-    swapd '[ _ replace ] reduce ;
-
-: split-subseqs ( seq subseqs -- seqs )
-    dup first [ replace-all ] keep split-subseq [ >string ] map harvest ;
-
-: 2with ( param1 param2 obj quot -- obj curry )
-    [ -rot ] dip [ [ rot ] dip call ] 3curry ; inline
-
-: gen-array-addrs ( base size n -- addrs )
-    iota [ * + ] 2with map ;
-
-: utf8-start-byte? ( byte -- ? )
-    0xc0 bitand 0x80 = not ;
-
-: next-utf8-char ( byte-array pos -- pos' )
-    1 + 2dup swap ?nth
-    [ utf8-start-byte? [ nip ] [ next-utf8-char ] if ] [ 2drop f ] if* ;