static void do_woz_META(deark *c, struct de_iffctx *ictx, const struct de_iffchunkctx *chunkctx) { i64 k; int reading_val; de_ucstring *s = NULL; de_ucstring *name = NULL; de_ucstring *val = NULL; // Read the entire metadata string. s = ucstring_create(c); dbuf_read_to_ucstring_n(ictx->f, chunkctx->dpos, chunkctx->dlen, 65536, s, 0, DE_ENCODING_UTF8); // Parse out the individual metadata items name = ucstring_create(c); val = ucstring_create(c); reading_val = 0; for(k=0; k<s->len; k++) { i32 ch = s->str[k]; if(ch==0x0a) { // End of item do_woz_print_metadata_item(c, name, val); ucstring_empty(name); ucstring_empty(val); reading_val = 0; } else if(ch==0x09 && !reading_val) { // Name/value separator reading_val = 1; } else { // A non-special character if(reading_val) { ucstring_append_char(val, ch); } else { ucstring_append_char(name, ch); } } } do_woz_print_metadata_item(c, name, val); ucstring_destroy(s); ucstring_destroy(name); ucstring_destroy(val); }
// Append s2 to s1 void ucstring_append_ucstring(de_ucstring *s1, const de_ucstring *s2) { de_int64 i; if(!s2) return; // TODO: This could be done more efficiently. for(i=0; i<s2->len; i++) { ucstring_append_char(s1, s2->str[i]); } }
void ucstring_append_bytes(de_ucstring *s, const de_byte *buf, de_int64 buflen, unsigned int conv_flags, int encoding) { int ret; de_int64 pos = 0; de_int32 ch; de_int64 code_len; // Adjust buflen if necessary. if(conv_flags & DE_CONVFLAG_STOP_AT_NUL) { char *tmpp; tmpp = de_memchr(buf, 0, (size_t)buflen); if(tmpp) { buflen = (const de_byte*)tmpp - buf; } } while(pos<buflen) { if(encoding==DE_ENCODING_UTF8) { ret = de_utf8_to_uchar(&buf[pos], buflen-pos, &ch, &code_len); if(!ret) { ch = '_'; code_len = 1; } } else if(encoding==DE_ENCODING_UTF16LE) { ret = de_utf16x_to_uchar(&buf[pos], buflen-pos, &ch, &code_len, 1); if(!ret) { ch = '_'; code_len = 2; } } else if(encoding==DE_ENCODING_UTF16BE) { ret = de_utf16x_to_uchar(&buf[pos], buflen-pos, &ch, &code_len, 0); if(!ret) { ch = '_'; code_len = 2; } } else { ch = de_char_to_unicode(s->c, buf[pos], encoding); if(ch==DE_INVALID_CODEPOINT) { ch = '_'; } code_len = 1; } ucstring_append_char(s, ch); pos += code_len; } }