wtanaka.praya.yahoo
Class MemTok

java.lang.Object
  |
  +--wtanaka.praya.yahoo.LibC
        |
        +--wtanaka.praya.yahoo.MemTok

public class MemTok
extends LibC

memtok from libyahoo's memtok.c. memtok differs from strtok in a few ways: The pointer to the buffer to be scanned AND the pointer to the delimiters are NOT NULL terminated strings but are each a pair of a pointer and byte count (so that NIL characters can be contained in either of these buffers! Also memtok does not replace the "found" delimiter with a NIL character, but places the number of bytes delimited by that delimiter into the location of the size_t pointer to by found. The whole **real** point of this function was that strtok skips any repeating delimiters, but we need a function that retuns "empty strings" should there be two delimiters in a row. For some sense of consistency, the byte count of the buffer to be searched through is ALSO ignored by memtok iff the buffer to be scanned is NULL Here's an example: size_t found = 0; char *tok = 0, *buffer = malloc (COUNT); fill_buffer_with_some_data (buffer, COUNT); tok = memtok (buffer, COUNT, "\000\002", 2, &found); if tok != NULL then the bytes from tok to (tok + found) are the token You can then look for more tokens with: tok = memtok (NULL, 0, "\000\002", 2, &found); If tmp == NULL noone of the delimiters were found, however tmp can != NULL and found CAN == 0 This means that although a delimiter was found it was immediately preceded by another delimiter and thus delimited an empty token. ( As it happens, if one of the delimiters you want to search for is a NIL character, you can put the other delimiter characters in a string literal and "lie" about how many delimiter characters there are because all string literals are NIL terminated! Therefor the above example could have been written: tok = memtok (buffer, COUNT, "\002", 2, &found); There are also two supplimentary functions that make using these tokens easier memdup is akin to strdup except that instead of it looking for a NIL termination character it simply mallocs copies the specified number of bytes memdupasstr does as memdup except that it mallocs 1 more byte and makes it a NIL char so that you can treat it as a string (as long as you're sure that the memory being described by the pointer and byte count don't already contain any NIL characters)

Return to Sourceforge or the Praya Homepage

Version:
$Name: $ $Date: 2002/07/08 13:20:53 $
Author:
Wesley Tanaka

Field Summary
(package private) static java.lang.String c
           
(package private) static int limit
           
(package private) static java.lang.String mem
           
(package private) static int offset
           
(package private) static int offset_now
           
(package private) static java.lang.String ret
           
 
Fields inherited from class wtanaka.praya.yahoo.LibC
FALSE, NULL, s_tokenizer, TRUE
 
Constructor Summary
MemTok()
           
 
Method Summary
(package private) static java.lang.String memdupasstr(java.lang.String mem, int bytes)
           
(package private) static java.lang.String memtok(java.lang.String m, int bytes, java.lang.String delims, int delim_count, int[] found)
           
 
Methods inherited from class wtanaka.praya.yahoo.LibC
atoi, close, equal, free, fromCStyleByteArray, isdigit, isprint, main, memchr, printf, snprintf, strcasecmp, strcasecmp, strcat, strcmp, strcmp, strcpy, strcpy, strdup, strdup, strdup, strlen, strlen, strlen, strncasecmp, strncmp, strncmp, strncpy, strstr, strtok_r, strtok
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

mem

static java.lang.String mem

c

static java.lang.String c

ret

static java.lang.String ret

offset

static int offset

offset_now

static int offset_now

limit

static int limit
Constructor Detail

MemTok

public MemTok()
Method Detail

memtok

static java.lang.String memtok(java.lang.String m,
                               int bytes,
                               java.lang.String delims,
                               int delim_count,
                               int[] found)

memdupasstr

static java.lang.String memdupasstr(java.lang.String mem,
                                    int bytes)