Commits

Ruslan Osmanov committed 725cd04

Change: make EventBuffer::search/searchEol return FALSE if string not found(instead of -1)

Comments (0)

Files changed (3)

 }
 /* }}} */
 
-/* {{{ proto int EventBuffer::search(int what[, int start = -1[, int end = -1]]);
+/* {{{ proto mixed EventBuffer::search(int what[, int start = -1[, int end = -1]]);
  *
  * Scans the buffer for an occurrence of the len-character string what. It
  * returns object representing the position of the string, or NULL if the
  * start and end buffer positions.
  *
  * Returns position of the first occurance of the string
- * in the buffer, or -1 if string is not found.
+ * in the buffer, or &false; if string is not found.
  */
 PHP_METHOD(EventBuffer, search)
 {
 				(start_pos != -1 ? &ptr_start : NULL));
 	}
 
+	if (ptr_res.pos == -1) {
+		RETURN_FALSE;
+	}
 	RETVAL_LONG(ptr_res.pos);
 }
 /* }}} */
 	ptr_res = evbuffer_search_eol(b->buf, (start_pos != -1 ? &ptr_start : NULL),
 			NULL, eol_style);
 
+	if (ptr_res.pos == -1) {
+		RETURN_FALSE;
+	}
 	RETVAL_LONG(ptr_res.pos);
 }
 /* }}} */

examples/buffer_position.php

 /* Count total occurances of 'str' in 'buf' */
 function count_instances($buf, $str) {
     $total = 0;
-	$p = new EventBufferPosition();
-
-    $buf->setPosition($p, 0, EventBuffer::PTR_SET);
+	$p = 0;
 
 	$i = 0;
     while (1) {
         $p = $buf->search($str, $p);
-        if (!$p) {
+        if ($p === FALSE) {
             break;
 		}
         ++$total;
-        $buf->setPosition($p, 1, EventBuffer::PTR_ADD);
+		++$p;
     }
 
     return $total;

tests/05-buffer-pos.phpt

 	$i = 0;
     while (1) {
         $p = $buf->search($str, $p);
-        if ($p == -1) {
+        if ($p === FALSE) {
             break;
 		}
         ++$total;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.