2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2011, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 PHP_HTTP_API php_http_strlist_iterator_t
*php_http_strlist_iterator_init(php_http_strlist_iterator_t
*iter
, const char list
[], unsigned factor
)
18 iter
= emalloc(sizeof(*iter
));
20 memset(iter
, 0, sizeof(*iter
));
23 iter
->factor
= factor
;
28 PHP_HTTP_API
const char *php_http_strlist_iterator_this(php_http_strlist_iterator_t
*iter
, unsigned *id
)
31 *id
= (iter
->major
+ 1) * iter
->factor
+ iter
->minor
;
37 PHP_HTTP_API
const char *php_http_strlist_iterator_next(php_http_strlist_iterator_t
*iter
)
56 PHP_HTTP_API
void php_http_strlist_iterator_dtor(php_http_strlist_iterator_t
*iter
)
61 PHP_HTTP_API
void php_http_strlist_iterator_free(php_http_strlist_iterator_t
**iter
)
69 PHP_HTTP_API
const char *php_http_strlist_find(const char list
[], unsigned factor
, unsigned item
)
71 unsigned M
= 0, m
= 0, major
, minor
;
72 const char *p
= &list
[0];
75 major
= (item
/ factor
) - 1;
76 minor
= item
% factor
;
81 while (*p
&& major
!= M
++) {
91 while (*p
&& minor
!= m
++) {
106 * vim600: noet sw=4 ts=4 fdm=marker
107 * vim<600: noet sw=4 ts=4