00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUTEXT_UCS4SRC_H
00019 #define CUTEXT_UCS4SRC_H
00020
00021 #include <cu/sref.h>
00022 #include <cutext/src.h>
00023 #include <cucon/pmap.h>
00024 #include <cu/cstr.h>
00025 #include <cutext/conv.h>
00026
00027 CU_BEGIN_DECLARATIONS
00028
00029 struct cutext_ucs4src
00030 {
00031 struct cutext_src src;
00032 struct cu_sref srf;
00033 int indentation;
00034 cutext_status_t st;
00035 cucon_pmap_t properties;
00036 };
00037
00038
00039
00040 void cutext_ucs4src_init(cutext_ucs4src_t ucs4src, cutext_producer_t producer,
00041 cu_str_t path, int line, int column);
00042 cutext_ucs4src_t cutext_ucs4src_new(cutext_producer_t producer,
00043 cu_str_t path, int line, int column);
00044
00045
00046
00047 void cutext_ucs4src_init_detect(cutext_ucs4src_t usc4src,
00048 cutext_producer_t producer,
00049 cu_str_t path, int line, int column);
00050 cutext_ucs4src_t cutext_ucs4src_new_detect(cutext_producer_t producer,
00051 cu_str_t path,
00052 int line, int column);
00053 CU_SINLINE cucon_pmap_t
00054 cutext_ucs4src_properties(cutext_ucs4src_t ucs4src)
00055 {
00056 return ucs4src->properties;
00057 }
00058
00059 CU_SINLINE cu_str_t
00060 cutext_ucs4src_getprop_by_key(cutext_ucs4src_t ucs4src, char const *key)
00061 {
00062 if (!ucs4src->properties)
00063 return NULL;
00064 return (cu_str_t)cucon_pmap_find_ptr(ucs4src->properties, key);
00065 }
00066
00067 CU_SINLINE cu_str_t
00068 cutext_ucs4src_getprop_by_cstr(cutext_ucs4src_t ucs4src, char const *key)
00069 {
00070 if (!ucs4src->properties)
00071 return NULL;
00072 return (cu_str_t)cucon_pmap_find_ptr(ucs4src->properties, cu_struniq(key));
00073 }
00074
00075 CU_SINLINE cu_sref_t
00076 cutext_ucs4src_sref(cutext_ucs4src_t ucs4src)
00077 {
00078 return &ucs4src->srf;
00079 }
00080
00081 CU_SINLINE cu_sref_t
00082 cutext_ucs4src_sref_copy(cutext_ucs4src_t ucs4src)
00083 {
00084 return cu_sref_new_copy(&ucs4src->srf);
00085 }
00086
00087
00088
00089 CU_SINLINE int
00090 cutext_ucs4src_indentation(cutext_ucs4src_t ucs4src)
00091 {
00092 return ucs4src->indentation;
00093 }
00094
00095 CU_SINLINE cu_bool_t
00096 cutext_ucs4src_is_ok(cutext_ucs4src_t ucs4src)
00097 { return ucs4src->st == cutext_status_ok; }
00098
00099 CU_SINLINE cu_bool_t
00100 cutext_ucs4src_is_eof(cutext_ucs4src_t ucs4src)
00101 { return cutext_src_data_size(&ucs4src->src) == 0; }
00102
00103
00104 CU_SINLINE cu_wchar_t
00105 cutext_ucs4src_peek(cutext_ucs4src_t ucs4src)
00106 {
00107 return *(cu_wchar_t *)ucs4src->src.buf.content_start;
00108 }
00109
00110
00111 cu_wchar_t *
00112 cutextP_ucs4src_peek_arr(cutext_ucs4src_t ucs4src, size_t size);
00113
00114
00115 CU_SINLINE cu_wchar_t *
00116 cutext_ucs4src_peek_arr(cutext_ucs4src_t ucs4src, size_t size)
00117 {
00118 size_t avail = cutext_src_data_size(&ucs4src->src)/4;
00119 if (size > avail)
00120 return cutextP_ucs4src_peek_arr(ucs4src, size);
00121 else
00122 return (cu_wchar_t *)ucs4src->src.buf.content_start;
00123 }
00124
00125
00126 void cutextP_ucs4src_terminate(cutext_ucs4src_t ucs4src);
00127
00128 cutext_status_t cutext_ucs4src_advance(cutext_ucs4src_t ucs4src, size_t size);
00129
00130
00131 CU_SINLINE cu_wchar_t
00132 cutext_ucs4src_get(cutext_ucs4src_t ucs4src)
00133 {
00134 cu_wchar_t ch = cutext_ucs4src_peek(ucs4src);
00135 cutext_ucs4src_advance(ucs4src, 1);
00136 return ch;
00137 }
00138
00139
00140 #define cutext_ucs4src_cct cutext_ucs4src_init
00141 #define cutext_ucs4src_cct_detect cutext_ucs4src_init_detect
00142
00143 CU_END_DECLARATIONS
00144
00145 #endif