Mercurial > vim
comparison src/blob.c @ 15466:435fcefd2c8e v8.1.0741
patch 8.1.0741: viminfo with Blob is not tested
commit https://github.com/vim/vim/commit/8c8b8bb56c724cc1bfc3d8520eec33f2d399697c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 13 17:48:04 2019 +0100
patch 8.1.0741: viminfo with Blob is not tested
Problem: Viminfo with Blob is not tested.
Solution: Extend the viminfo test. Fix reading a blob. Fixed storing a
special variable value.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 13 Jan 2019 18:00:05 +0100 |
parents | f01eb1aed348 |
children | 55ccc2d353bd |
comparison
equal
deleted
inserted
replaced
15465:0f076f6c5356 | 15466:435fcefd2c8e |
---|---|
165 return FAIL; | 165 return FAIL; |
166 } | 166 } |
167 return OK; | 167 return OK; |
168 } | 168 } |
169 | 169 |
170 /* | |
171 * Convert a blob to a readable form: "[0x11,0x34]" | |
172 */ | |
173 char_u * | |
174 blob2string(blob_T *blob, char_u **tofree, char_u *numbuf) | |
175 { | |
176 int i; | |
177 garray_T ga; | |
178 | |
179 if (blob == NULL) | |
180 { | |
181 *tofree = NULL; | |
182 return (char_u *)"[]"; | |
183 } | |
184 | |
185 // Store bytes in the growarray. | |
186 ga_init2(&ga, 1, 4000); | |
187 ga_append(&ga, '['); | |
188 for (i = 0; i < blob_len(blob); i++) | |
189 { | |
190 if (i > 0) | |
191 ga_concat(&ga, (char_u *)","); | |
192 vim_snprintf((char *)numbuf, NUMBUFLEN, "0x%02X", (int)blob_get(blob, i)); | |
193 ga_concat(&ga, numbuf); | |
194 } | |
195 ga_append(&ga, ']'); | |
196 *tofree = ga.ga_data; | |
197 return *tofree; | |
198 } | |
199 | |
200 /* | |
201 * Convert a string variable, in the format of blob2string(), to a blob. | |
202 * Return NULL when conversion failed. | |
203 */ | |
204 blob_T * | |
205 string2blob(char_u *str) | |
206 { | |
207 blob_T *blob = blob_alloc(); | |
208 char_u *s = str; | |
209 | |
210 if (*s != '[') | |
211 goto failed; | |
212 s = skipwhite(s + 1); | |
213 while (*s != ']') | |
214 { | |
215 if (s[0] != '0' || s[1] != 'x' | |
216 || !vim_isxdigit(s[2]) || !vim_isxdigit(s[3])) | |
217 goto failed; | |
218 ga_append(&blob->bv_ga, (hex2nr(s[2]) << 4) + hex2nr(s[3])); | |
219 s += 4; | |
220 if (*s == ',') | |
221 s = skipwhite(s + 1); | |
222 else if (*s != ']') | |
223 goto failed; | |
224 } | |
225 s = skipwhite(s + 1); | |
226 if (*s != NUL) | |
227 goto failed; // text after final ']' | |
228 | |
229 ++blob->bv_refcount; | |
230 return blob; | |
231 | |
232 failed: | |
233 blob_free(blob); | |
234 return NULL; | |
235 } | |
236 | |
170 #endif /* defined(FEAT_EVAL) */ | 237 #endif /* defined(FEAT_EVAL) */ |