Convert hard-coded unicode byte order mark values to constants.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31374 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Nick Peskett 2011-12-20 08:15:36 +00:00
parent c24a36dd9d
commit 1b781df59c
4 changed files with 25 additions and 16 deletions

View file

@ -127,23 +127,23 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
/* Look for a Unicode BOM */ /* Look for a Unicode BOM */
unsigned char bom_read = 0; unsigned char bom_read = 0;
read(fd, line, 3); read(fd, line, BOM_UTF_8_SIZE);
if(!memcmp(line, "\xef\xbb\xbf", 3)) if(!memcmp(line, BOM_UTF_8, BOM_UTF_8_SIZE))
{ {
char_enc = CHAR_ENC_UTF_8; char_enc = CHAR_ENC_UTF_8;
bom_read = 3; bom_read = BOM_UTF_8_SIZE;
} }
else if(!memcmp(line, "\xff\xfe", 2)) else if(!memcmp(line, BOM_UTF_16_LE, BOM_UTF_16_SIZE))
{ {
char_enc = CHAR_ENC_UTF_16_LE; char_enc = CHAR_ENC_UTF_16_LE;
bom_read = 2; bom_read = BOM_UTF_16_SIZE;
} }
else if(!memcmp(line, "\xfe\xff", 2)) else if(!memcmp(line, BOM_UTF_16_BE, BOM_UTF_16_SIZE))
{ {
char_enc = CHAR_ENC_UTF_16_BE; char_enc = CHAR_ENC_UTF_16_BE;
bom_read = 2; bom_read = BOM_UTF_16_SIZE;
} }
if (bom_read < 3 ) if (bom_read < BOM_UTF_8_SIZE)
lseek(fd, cue_file->pos + bom_read, SEEK_SET); lseek(fd, cue_file->pos + bom_read, SEEK_SET);
if (is_embedded) if (is_embedded)
{ {

View file

@ -49,6 +49,7 @@
#include "metadata_common.h" #include "metadata_common.h"
#endif #endif
#include "metadata_parsers.h" #include "metadata_parsers.h"
#include "misc.h"
static unsigned long unsync(unsigned long b0, static unsigned long unsync(unsigned long b0,
unsigned long b1, unsigned long b1,
@ -1008,10 +1009,13 @@ void setid3v2title(int fd, struct mp3entry *entry)
break; break;
case 0x01: case 0x01:
tag++; tag++;
if (!memcmp(tag, "\xfe\xff", 2)) if (!memcmp(tag,
BOM_UTF_16_BE, BOM_UTF_16_SIZE)) {
char_enc = CHAR_ENC_UTF_16_BE; char_enc = CHAR_ENC_UTF_16_BE;
else if (!memcmp(tag, "\xff\xfe", 2)) } else if (!memcmp(tag,
BOM_UTF_16_LE, BOM_UTF_16_SIZE)) {
char_enc = CHAR_ENC_UTF_16_LE; char_enc = CHAR_ENC_UTF_16_LE;
}
/* \1 + BOM(2) + C0U0E0S0H0E0E0T000 = 21 */ /* \1 + BOM(2) + C0U0E0S0H0E0E0T000 = 21 */
cuesheet_offset = 21; cuesheet_offset = 21;
break; break;

View file

@ -1011,13 +1011,11 @@ void format_time(char* buf, int buf_size, long t)
* If the file is opened for writing and O_TRUNC is set, write a BOM to * If the file is opened for writing and O_TRUNC is set, write a BOM to
* the opened file and leave the file pointer set after the BOM. * the opened file and leave the file pointer set after the BOM.
*/ */
#define BOM "\xef\xbb\xbf"
#define BOM_SIZE 3
int open_utf8(const char* pathname, int flags) int open_utf8(const char* pathname, int flags)
{ {
int fd; int fd;
unsigned char bom[BOM_SIZE]; unsigned char bom[BOM_UTF_8_SIZE];
fd = open(pathname, flags, 0666); fd = open(pathname, flags, 0666);
if(fd < 0) if(fd < 0)
@ -1025,13 +1023,13 @@ int open_utf8(const char* pathname, int flags)
if(flags & (O_TRUNC | O_WRONLY)) if(flags & (O_TRUNC | O_WRONLY))
{ {
write(fd, BOM, BOM_SIZE); write(fd, BOM_UTF_8, BOM_UTF_8_SIZE);
} }
else else
{ {
read(fd, bom, BOM_SIZE); read(fd, bom, BOM_UTF_8_SIZE);
/* check for BOM */ /* check for BOM */
if(memcmp(bom, BOM, BOM_SIZE)) if(memcmp(bom, BOM_UTF_8, BOM_UTF_8_SIZE))
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
} }
return fd; return fd;

View file

@ -66,6 +66,13 @@ bool list_stop_handler(void);
void car_adapter_mode_init(void) INIT_ATTR; void car_adapter_mode_init(void) INIT_ATTR;
extern int show_logo(void); extern int show_logo(void);
/* Unicode byte order mark sequences and lengths */
#define BOM_UTF_8 "\xef\xbb\xbf"
#define BOM_UTF_8_SIZE 3
#define BOM_UTF_16_LE "\xff\xfe"
#define BOM_UTF_16_BE "\xfe\xff"
#define BOM_UTF_16_SIZE 2
int open_utf8(const char* pathname, int flags); int open_utf8(const char* pathname, int flags);
#ifdef BOOTFILE #ifdef BOOTFILE