00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef APT_STRING_H
00020 #define APT_STRING_H
00021
00022
00023
00024
00025
00026
00027 #include "apt.h"
00028
00029 APT_BEGIN_EXTERN_C
00030
00031
00032 #define APT_EMPTY_STRING ""
00033
00034
00035 typedef struct apt_str_t apt_str_t;
00036
00037
00038 struct apt_str_t {
00039
00040 char *buf;
00041
00042 apr_size_t length;
00043 };
00044
00045
00046 static APR_INLINE void apt_string_reset(apt_str_t *str)
00047 {
00048 str->buf = NULL;
00049 str->length = 0;
00050 }
00051
00052
00053 static APR_INLINE const char* apt_string_buffer_get(const apt_str_t *str)
00054 {
00055 if(str->buf) {
00056 return str->buf;
00057 }
00058 return APT_EMPTY_STRING;
00059 }
00060
00061
00062 static APR_INLINE apr_size_t apt_string_length_get(const apt_str_t *str)
00063 {
00064 return str->length;
00065 }
00066
00067
00068 static APR_INLINE apr_size_t apt_string_is_empty(const apt_str_t *str)
00069 {
00070 return str->length ? FALSE : TRUE;
00071 }
00072
00073
00074
00075
00076
00077
00078 static APR_INLINE void apt_string_set(apt_str_t *str, const char *src)
00079 {
00080 str->buf = (char*)src;
00081 str->length = src ? strlen(src) : 0;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 static APR_INLINE void apt_string_assign(apt_str_t *str, const char *src, apr_pool_t *pool)
00091 {
00092 str->buf = NULL;
00093 str->length = src ? strlen(src) : 0;
00094 if(str->length) {
00095 str->buf = apr_pstrmemdup(pool,src,str->length);
00096 }
00097 }
00098
00099
00100
00101
00102
00103
00104
00105 static APR_INLINE void apt_string_assign_n(apt_str_t *str, const char *src, apr_size_t length, apr_pool_t *pool)
00106 {
00107 str->buf = NULL;
00108 str->length = length;
00109 if(str->length) {
00110 str->buf = apr_pstrmemdup(pool,src,str->length);
00111 }
00112 }
00113
00114
00115
00116
00117
00118
00119
00120 static APR_INLINE void apt_string_copy(apt_str_t *str, const apt_str_t *src_str, apr_pool_t *pool)
00121 {
00122 str->buf = NULL;
00123 str->length = src_str->length;
00124 if(str->length) {
00125 str->buf = apr_pstrmemdup(pool,src_str->buf,src_str->length);
00126 }
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 static APR_INLINE apt_bool_t apt_string_compare(const apt_str_t *str1, const apt_str_t *str2)
00136 {
00137 if(str1->length != str2->length || !str1->length) {
00138 return FALSE;
00139 }
00140 return (strncasecmp(str1->buf,str2->buf,str1->length) == 0) ? TRUE : FALSE;
00141 }
00142
00143 APT_END_EXTERN_C
00144
00145 #endif