00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef APT_TEXT_STREAM_H
00020 #define APT_TEXT_STREAM_H
00021
00022
00023
00024
00025
00026
00027 #include "apt_string_table.h"
00028 #include "apt_pair.h"
00029
00030 APT_BEGIN_EXTERN_C
00031
00032
00033 #define APT_TOKEN_SP 0x20
00034
00035 #define APT_TOKEN_HTAB 0x09
00036
00037 #define APT_TOKEN_CR 0x0D
00038
00039 #define APT_TOKEN_LF 0x0A
00040
00041
00042 typedef struct apt_text_stream_t apt_text_stream_t;
00043
00044
00045 struct apt_text_stream_t {
00046
00047 apt_str_t text;
00048
00049
00050 char *pos;
00051
00052 const char *end;
00053
00054 apt_bool_t is_eos;
00055 };
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 APT_DECLARE(apt_bool_t) apt_text_line_read(apt_text_stream_t *stream, apt_str_t *line);
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 APT_DECLARE(apt_bool_t) apt_text_header_read(apt_text_stream_t *stream, apt_pair_t *pair);
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 APT_DECLARE(apt_bool_t) apt_text_field_read(apt_text_stream_t *stream, char separator, apt_bool_t skip_spaces, apt_str_t *field);
00087
00088
00089 APT_DECLARE(apt_bool_t) apt_text_name_value_insert(apt_text_stream_t *stream, const apt_str_t *name, const apt_str_t *value);
00090
00091
00092 APT_DECLARE(apt_bool_t) apt_text_header_name_insert(apt_text_stream_t *stream, const apt_str_t *name);
00093
00094
00095 APT_DECLARE(apt_bool_t) apt_pair_array_parse(apt_pair_arr_t *arr, const apt_str_t *value, apr_pool_t *pool);
00096
00097 APT_DECLARE(apt_bool_t) apt_pair_array_generate(const apt_pair_arr_t *arr, apt_str_t *str, apr_pool_t *pool);
00098
00099
00100 APT_DECLARE(apt_bool_t) apt_text_pair_array_insert(apt_text_stream_t *stream, const apt_pair_arr_t *arr);
00101
00102
00103
00104 APT_DECLARE(apt_bool_t) apt_boolean_value_parse(const apt_str_t *str, apt_bool_t *value);
00105
00106 APT_DECLARE(apt_bool_t) apt_boolean_value_generate(apt_bool_t value, apt_str_t *str, apr_pool_t *pool);
00107
00108
00109 APT_DECLARE(apt_bool_t) apt_text_boolean_value_insert(apt_text_stream_t *stream, apt_bool_t value);
00110
00111
00112 APT_DECLARE(apr_size_t) apt_size_value_parse(const apt_str_t *str);
00113
00114 APT_DECLARE(apt_bool_t) apt_size_value_generate(apr_size_t value, apt_str_t *str, apr_pool_t *pool);
00115
00116
00117 APT_DECLARE(apt_bool_t) apt_text_size_value_insert(apt_text_stream_t *stream, apr_size_t value);
00118
00119
00120 APT_DECLARE(float) apt_float_value_parse(const apt_str_t *str);
00121
00122 APT_DECLARE(apt_bool_t) apt_float_value_generate(float value, apt_str_t *str, apr_pool_t *pool);
00123
00124
00125 APT_DECLARE(apt_bool_t) apt_text_float_value_insert(apt_text_stream_t *stream, float value);
00126
00127 APT_DECLARE(apt_bool_t) apt_text_string_insert(apt_text_stream_t *stream, const apt_str_t *str);
00128
00129
00130 static APR_INLINE void apt_text_stream_reset(apt_text_stream_t *stream)
00131 {
00132 stream->pos = stream->text.buf;
00133 stream->end = stream->text.buf + stream->text.length;
00134 stream->is_eos = FALSE;
00135 }
00136
00137
00138 static APR_INLINE void apt_text_stream_init(apt_text_stream_t *stream, char *buffer, apr_size_t size)
00139 {
00140 stream->text.buf = buffer;
00141 stream->text.length = size;
00142 apt_text_stream_reset(stream);
00143 }
00144
00145
00146 static APR_INLINE apt_bool_t apt_text_eol_insert(apt_text_stream_t *stream)
00147 {
00148 if(stream->pos + 2 < stream->end) {
00149 *stream->pos++ = APT_TOKEN_CR;
00150 *stream->pos++ = APT_TOKEN_LF;
00151 return TRUE;
00152 }
00153 return FALSE;
00154 }
00155
00156
00157 static APR_INLINE apt_bool_t apt_text_char_insert(apt_text_stream_t *stream, char ch)
00158 {
00159 if(stream->pos + 1 < stream->end) {
00160 *stream->pos++ = ch;
00161 return TRUE;
00162 }
00163 return FALSE;
00164 }
00165
00166
00167 static APR_INLINE apt_bool_t apt_text_space_insert(apt_text_stream_t *stream)
00168 {
00169 return apt_text_char_insert(stream,APT_TOKEN_SP);
00170 }
00171
00172
00173 static APR_INLINE apt_bool_t apt_text_htab_insert(apt_text_stream_t *stream)
00174 {
00175 return apt_text_char_insert(stream,APT_TOKEN_HTAB);
00176 }
00177
00178
00179 static APR_INLINE apt_bool_t apt_text_is_wsp(char ch)
00180 {
00181 return (ch == APT_TOKEN_SP || ch == APT_TOKEN_HTAB) ? TRUE : FALSE;
00182 }
00183
00184
00185 static APR_INLINE void apt_text_spaces_skip(apt_text_stream_t *stream)
00186 {
00187 while(stream->pos < stream->end && *stream->pos == APT_TOKEN_SP)
00188 stream->pos++;
00189 }
00190
00191
00192 static APR_INLINE void apt_text_white_spaces_skip(apt_text_stream_t *stream)
00193 {
00194 while(stream->pos < stream->end && apt_text_is_wsp(*stream->pos) == TRUE)
00195 stream->pos++;
00196 }
00197
00198
00199 static APR_INLINE void apt_text_char_skip(apt_text_stream_t *stream, char ch)
00200 {
00201 if(stream->pos < stream->end && *stream->pos == ch) stream->pos++;
00202 }
00203
00204
00205 static APR_INLINE void apt_text_chars_skip(apt_text_stream_t *stream, char ch)
00206 {
00207 while(stream->pos < stream->end && *stream->pos == ch) stream->pos++;
00208 }
00209
00210
00211 static APR_INLINE void apt_text_skip_to_char(apt_text_stream_t *stream, char ch)
00212 {
00213 while(stream->pos < stream->end && *stream->pos != ch) stream->pos++;
00214 }
00215
00216
00217 static APR_INLINE apt_bool_t apt_text_is_eos(const apt_text_stream_t *stream)
00218 {
00219 return (stream->pos >= stream->end || stream->is_eos == TRUE) ? TRUE : FALSE;
00220 }
00221
00222
00223 APT_DECLARE(apt_bool_t) apt_text_stream_scroll(apt_text_stream_t *stream);
00224
00225
00226 APT_DECLARE(apt_bool_t) apt_id_resource_parse(const apt_str_t *str, char separator, apt_str_t *id, apt_str_t *resource, apr_pool_t *pool);
00227
00228 APT_DECLARE(apt_bool_t) apt_id_resource_generate(const apt_str_t *id, const apt_str_t *resource, char separator, apt_str_t *str, apr_pool_t *pool);
00229
00230
00231 APT_DECLARE(apt_bool_t) apt_var_length_value_generate(apr_size_t *value, apr_size_t max_count, apt_str_t *str);
00232
00233
00234 APT_DECLARE(apt_bool_t) apt_completion_cause_generate(const apt_str_table_item_t table[], apr_size_t size, apr_size_t cause, apt_str_t *str, apr_pool_t *pool);
00235
00236
00237
00238
00239
00240
00241
00242 APT_DECLARE(apt_bool_t) apt_unique_id_generate(apt_str_t *id, apr_size_t length, apr_pool_t *pool);
00243
00244
00245 APT_END_EXTERN_C
00246
00247 #endif