| | 107 | UBinary* ur_seriesMem( UThread* ut, const UCell* cell, |
| | 108 | char** cpA, char** cpB ) |
| | 109 | { |
| | 110 | UBinary* bin; |
| | 111 | int end; |
| | 112 | |
| | 113 | switch( ur_type(cell) ) |
| | 114 | { |
| | 115 | case UT_BINARY: |
| | 116 | bin = ur_bin(cell); |
| | 117 | if( ! bin->used ) |
| | 118 | goto empty; |
| | 119 | end = bin->used; |
| | 120 | goto set_pointers; |
| | 121 | |
| | 122 | case UT_STRING: |
| | 123 | bin = ur_bin(cell); |
| | 124 | if( ! bin->used ) |
| | 125 | goto empty; |
| | 126 | end = bin->used; |
| | 127 | if( ur_encoding(cell) == UR_ENC_UTF16 ) |
| | 128 | goto set_pointers2; |
| | 129 | goto set_pointers; |
| | 130 | |
| | 131 | case UT_SLICE: |
| | 132 | if( ur_sliceDT(cell) == UT_BINARY ) |
| | 133 | { |
| | 134 | bin = ur_bin(cell); |
| | 135 | if( ! bin->used ) |
| | 136 | goto empty; |
| | 137 | end = ur_sliceEnd(cell, bin); |
| | 138 | goto set_pointers; |
| | 139 | } |
| | 140 | else if( ur_sliceDT(cell) == UT_STRING ) |
| | 141 | { |
| | 142 | bin = ur_bin(cell); |
| | 143 | if( ! bin->used ) |
| | 144 | goto empty; |
| | 145 | end = ur_sliceEnd(cell, bin); |
| | 146 | if( ur_encoding(cell) == UR_ENC_UTF16 ) |
| | 147 | goto set_pointers2; |
| | 148 | goto set_pointers; |
| | 149 | } |
| | 150 | break; |
| | 151 | |
| | 152 | case UT_VECTOR: |
| | 153 | bin = ur_bin(cell); |
| | 154 | if( ! bin->used ) |
| | 155 | goto empty; |
| | 156 | end = bin->used; |
| | 157 | goto set_pointers4; |
| | 158 | } |
| | 159 | return 0; |
| | 160 | |
| | 161 | set_pointers: |
| | 162 | |
| | 163 | *cpA = bin->ptr.c + cell->series.it; |
| | 164 | *cpB = bin->ptr.c + end; |
| | 165 | return bin; |
| | 166 | |
| | 167 | set_pointers2: |
| | 168 | |
| | 169 | *cpA = (char*) (bin->ptr.u16 + cell->series.it); |
| | 170 | *cpB = (char*) (bin->ptr.u16 + end); |
| | 171 | return bin; |
| | 172 | |
| | 173 | set_pointers4: |
| | 174 | |
| | 175 | *cpA = (char*) (bin->ptr.i + cell->series.it); |
| | 176 | *cpB = (char*) (bin->ptr.i + end); |
| | 177 | return bin; |
| | 178 | |
| | 179 | empty: |
| | 180 | |
| | 181 | *cpA = *cpB = 0; |
| | 182 | return bin; |
| | 183 | } |
| | 184 | |
| | 185 | |
| | 186 | /** |
| | 187 | Get pointers to the start and end characters of a string! or string slice!. |
| | 188 | |
| | 189 | \see ur_seriesMem() |
| | 190 | */ |
| 110 | | UString* str; |
| 111 | | int end; |
| 112 | | |
| 113 | | if( ur_is(cell, UT_STRING) ) |
| 114 | | { |
| 115 | | str = ur_bin(cell); |
| 116 | | if( ! str->used ) |
| 117 | | goto empty; |
| 118 | | end = str->used; |
| 119 | | |
| 120 | | set_pointers: |
| 121 | | |
| 122 | | if( ur_encoding(cell) == UR_ENC_UTF16 ) |
| 123 | | { |
| 124 | | *cpA = (char*) (str->ptr.u16 + cell->series.it); |
| 125 | | *cpB = (char*) (str->ptr.u16 + end); |
| 126 | | } |
| 127 | | else |
| 128 | | { |
| 129 | | *cpA = str->ptr.c + cell->series.it; |
| 130 | | *cpB = str->ptr.c + end; |
| 131 | | } |
| 132 | | return str; |
| 133 | | } |
| 134 | | else if( ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_STRING) ) |
| 135 | | { |
| 136 | | str = ur_bin(cell); |
| 137 | | if( ! str->used ) |
| 138 | | goto empty; |
| 139 | | end = ur_sliceEnd(cell, str); |
| 140 | | goto set_pointers; |
| 141 | | } |
| | 194 | if( ur_is(cell, UT_STRING) || |
| | 195 | (ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_STRING)) ) |
| | 196 | return ur_seriesMem( ut, cell, cpA, cpB ); |
| 159 | | UBinary* str; |
| 160 | | int end; |
| 161 | | |
| 162 | | if( ur_is(cell, UT_BINARY) ) |
| 163 | | { |
| 164 | | str = ur_bin(cell); |
| 165 | | if( ! str->used ) |
| 166 | | goto empty; |
| 167 | | end = str->used; |
| 168 | | |
| 169 | | set_pointers: |
| 170 | | |
| 171 | | *cpA = str->ptr.c + cell->series.it; |
| 172 | | *cpB = str->ptr.c + end; |
| 173 | | return str; |
| 174 | | } |
| 175 | | else if( ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_BINARY) ) |
| 176 | | { |
| 177 | | str = ur_bin(cell); |
| 178 | | if( ! str->used ) |
| 179 | | goto empty; |
| 180 | | end = ur_sliceEnd(cell, str); |
| 181 | | goto set_pointers; |
| 182 | | } |
| | 209 | if( ur_is(cell, UT_BINARY) || |
| | 210 | (ur_is(cell, UT_SLICE) && (ur_sliceDT(cell) == UT_BINARY)) ) |
| | 211 | return ur_seriesMem( ut, cell, cpA, cpB ); |