Browse Source

Add "size" functions for maps and "matchedNum" for regexps

* Fix Makefile issue

* 

* add "matchedNum" function for regexps

* Undo Makefile changes

* Don't error if not matched
theangryepicbanana 4 years ago
parent
commit
720b50952a
3 changed files with 15 additions and 1 deletions
  1. 3 0
      src/std/maps.c
  2. 4 0
      src/std/maps.h
  3. 8 1
      src/std/regexp.c

+ 3 - 0
src/std/maps.c

@@ -234,6 +234,7 @@ DEFINE_PRIM( _BOOL, hiremove, _IMAP _I32 );
 DEFINE_PRIM( _ARR, hikeys, _IMAP );
 DEFINE_PRIM( _ARR, hivalues, _IMAP );
 DEFINE_PRIM( _VOID, hiclear, _IMAP );
+DEFINE_PRIM( _I32, hisize, _IMAP );
 
 #define _BMAP _ABSTRACT(hl_bytes_map)
 DEFINE_PRIM( _BMAP, hballoc, _NO_ARG );
@@ -244,6 +245,7 @@ DEFINE_PRIM( _BOOL, hbremove, _BMAP _BYTES );
 DEFINE_PRIM( _ARR, hbkeys, _BMAP );
 DEFINE_PRIM( _ARR, hbvalues, _BMAP );
 DEFINE_PRIM( _VOID, hbclear, _BMAP );
+DEFINE_PRIM( _I32, hbsize, _BMAP );
 
 #define _OMAP _ABSTRACT(hl_obj_map)
 DEFINE_PRIM( _OMAP, hoalloc, _NO_ARG );
@@ -254,3 +256,4 @@ DEFINE_PRIM( _BOOL, horemove, _OMAP _DYN );
 DEFINE_PRIM( _ARR, hokeys, _OMAP );
 DEFINE_PRIM( _ARR, hovalues, _OMAP );
 DEFINE_PRIM( _VOID, hoclear, _OMAP );
+DEFINE_PRIM( _I32, hosize, _OMAP );

+ 4 - 0
src/std/maps.h

@@ -188,6 +188,10 @@ HL_PRIM void _MNAME(clear)( t_map *m ) {
 	memset(m,0,sizeof(t_map));
 }
 
+HL_PRIM int _MNAME(size)( t_map *m ) {
+	return m->nentries;
+}
+
 
 #undef hlt_key
 #undef hl_hbhash

+ 8 - 1
src/std/regexp.c

@@ -103,6 +103,13 @@ HL_PRIM int hl_regexp_matched_pos( ereg *e, int m, int *len ) {
 	return start;
 }
 
+HL_PRIM int hl_regexp_matched_num( ereg *e ) {
+	if( !e->matched )
+		return -1;
+	else
+		return e->nmatches;
+}
+
 HL_PRIM bool hl_regexp_match( ereg *e, vbyte *s, int pos, int len ) {
 	int res = pcre16_exec(e->p,&limit,(PCRE_SPTR16)s,pos+len,pos,PCRE_NO_UTF16_CHECK,e->matches,e->nmatches * 3);
 	e->matched = res >= 0;
@@ -116,5 +123,5 @@ HL_PRIM bool hl_regexp_match( ereg *e, vbyte *s, int pos, int len ) {
 #define _EREG _ABSTRACT(ereg)
 DEFINE_PRIM( _EREG, regexp_new_options, _BYTES _BYTES);
 DEFINE_PRIM( _I32, regexp_matched_pos, _EREG _I32 _REF(_I32));
+DEFINE_PRIM( _I32, regexp_matched_num, _EREG );
 DEFINE_PRIM( _BOOL, regexp_match, _EREG _BYTES _I32 _I32);
-