···570570 string. If it is, we convert it to a UTF-8 string. If it's not unicode,
571571 we convert from the default codepage */
572572static void unicode_munge(char* string, char* utf8buf, int *len) {
573573- long tmp;
574574- bool le = false;
575573 int i = 0;
576574 unsigned char *str = (unsigned char *)string;
577575 int templen = 0;
···590588 case 0x02:
591589 (*len)--;
592590 str++;
591591+ bool le;
592592+593593594594 /* Handle frames with more than one string
595595 (needed for TXXX frames).*/
596596 do {
597597- tmp = bytes2int(0, 0, str[0], str[1]);
598598-599599- /* Now check if there is a BOM
600600- (zero-width non-breaking space, 0xfeff)
601601- and if it is in little or big endian format */
602602- if(tmp == 0xfffe) { /* Little endian? */
603603- le = true;
604604- str += 2;
605605- (*len)-=2;
606606- } else if(tmp == 0xfeff) { /* Big endian? */
607607- str += 2;
608608- (*len)-=2;
609609- } else
610610- /* If there is no BOM (which is a specification violation),
611611- let's try to guess it. If one of the bytes is 0x00, it is
612612- probably the most significant one. */
613613- if(str[1] == 0)
614614- le = true;
597597+ if (utf16_has_bom(str, &le))
598598+ {
599599+ str += BOM_UTF_16_SIZE;
600600+ *len -= BOM_UTF_16_SIZE;
601601+ }
615602616603 while ((i < *len) && (str[0] || str[1])) {
617604 if(le)
···734721 switch (*(tag++))
735722 {
736723 case 0x01:
737737- if (!memcmp(tag, BOM_UTF_16_BE, BOM_UTF_16_SIZE))
738738- *char_enc = CHAR_ENC_UTF_16_BE;
739739- else if (!memcmp(tag, BOM_UTF_16_LE, BOM_UTF_16_SIZE))
740740- *char_enc = CHAR_ENC_UTF_16_LE;
741741- else
724724+ {
725725+ bool le;
726726+ if (!utf16_has_bom(tag, &le))
742727 return false;
743728729729+ *char_enc = le ? CHAR_ENC_UTF_16_LE: CHAR_ENC_UTF_16_BE;
744730 tag+= BOM_UTF_16_SIZE;
745731 /* \1 + BOM(2) + C0U0E0S0H0E0E0T000 = 21 */
746732 *cuesheet_offset = 21;
747733 break;
734734+ }
748735749736 case 0x02:
750737 *char_enc = CHAR_ENC_UTF_16_BE;