/*
        Copyright (c) 1996, NeXT Software, Inc.
        All rights reserved.

        You may freely copy, distribute and reuse the code in this example.
        NeXT disclaims any warranty of any kind, expressed or implied,
        as to its fitness for any particular use.
*/
#import "FileScanning.h"
#import <string.h>

char *FFNextTokenIn(char *begin, int *length, char *end, char *delimiter)
{
    char *current = begin, delimiterStart = *delimiter;
    int delimiterLength = strlen(delimiter++) - 1;

    while (current <= end) {
        if (*current == delimiterStart)
            if (delimiterLength > end - current) {
                *length = 1 + end - begin;
                return NULL;
            } else if (!delimiterLength || !strncmp(current + 1, delimiter, delimiterLength)) {
                *length = current - begin;
                current += (delimiterLength + 1);
                return (current <= end) ? current : NULL;
            }
        current++;
    }
    *length = current - begin;
    return NULL;
}
