ReactOS  r73918
mpg123 metadata handling

Classes

struct  mpg123_string
 
struct  mpg123_text
 
struct  mpg123_picture
 
struct  mpg123_id3v2
 
struct  mpg123_id3v1
 

Macros

#define MPG123_ID3   0x3
 
#define MPG123_NEW_ID3   0x1
 
#define MPG123_ICY   0xc
 
#define MPG123_NEW_ICY   0x4
 

Enumerations

enum  mpg123_text_encoding {
  mpg123_text_unknown = 0, mpg123_text_utf8 = 1, mpg123_text_latin1 = 2, mpg123_text_icy = 3,
  mpg123_text_cp1252 = 4, mpg123_text_utf16 = 5, mpg123_text_utf16bom = 6, mpg123_text_utf16be = 7,
  mpg123_text_max = 7
}
 
enum  mpg123_id3_enc {
  mpg123_id3_latin1 = 0, mpg123_id3_utf16bom = 1, mpg123_id3_utf16be = 2, mpg123_id3_utf8 = 3,
  mpg123_id3_enc_max = 3
}
 
enum  mpg123_id3_pic_type {
  mpg123_id3_pic_other = 0, mpg123_id3_pic_icon = 1, mpg123_id3_pic_other_icon = 2, mpg123_id3_pic_front_cover = 3,
  mpg123_id3_pic_back_cover = 4, mpg123_id3_pic_leaflet = 5, mpg123_id3_pic_media = 6, mpg123_id3_pic_lead = 7,
  mpg123_id3_pic_artist = 8, mpg123_id3_pic_conductor = 9, mpg123_id3_pic_orchestra = 10, mpg123_id3_pic_composer = 11,
  mpg123_id3_pic_lyricist = 12, mpg123_id3_pic_location = 13, mpg123_id3_pic_recording = 14, mpg123_id3_pic_performance = 15,
  mpg123_id3_pic_video = 16, mpg123_id3_pic_fish = 17, mpg123_id3_pic_illustration = 18, mpg123_id3_pic_artist_logo = 19,
  mpg123_id3_pic_publisher_logo = 20
}
 

Functions

MPG123_EXPORT void mpg123_init_string (mpg123_string *sb)
 
MPG123_EXPORT void mpg123_free_string (mpg123_string *sb)
 
MPG123_EXPORT int mpg123_resize_string (mpg123_string *sb, size_t news)
 
MPG123_EXPORT int mpg123_grow_string (mpg123_string *sb, size_t news)
 
MPG123_EXPORT int mpg123_copy_string (mpg123_string *from, mpg123_string *to)
 
MPG123_EXPORT int mpg123_add_string (mpg123_string *sb, const char *stuff)
 
MPG123_EXPORT int mpg123_add_substring (mpg123_string *sb, const char *stuff, size_t from, size_t count)
 
MPG123_EXPORT int mpg123_set_string (mpg123_string *sb, const char *stuff)
 
MPG123_EXPORT int mpg123_set_substring (mpg123_string *sb, const char *stuff, size_t from, size_t count)
 
MPG123_EXPORT size_t mpg123_strlen (mpg123_string *sb, int utf8)
 
MPG123_EXPORT int mpg123_chomp_string (mpg123_string *sb)
 
MPG123_EXPORT enum
mpg123_text_encoding 
mpg123_enc_from_id3 (unsigned char id3_enc_byte)
 
MPG123_EXPORT int mpg123_store_utf8 (mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size)
 
MPG123_EXPORT int mpg123_meta_check (mpg123_handle *mh)
 
MPG123_EXPORT void mpg123_meta_free (mpg123_handle *mh)
 
MPG123_EXPORT int mpg123_id3 (mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2)
 
MPG123_EXPORT int mpg123_icy (mpg123_handle *mh, char **icy_meta)
 
MPG123_EXPORT charmpg123_icy2utf8 (const char *icy_text)
 

Detailed Description

Functions to retrieve the metadata from MPEG Audio files and streams. Also includes string handling functions.

Macro Definition Documentation

#define MPG123_ICY   0xc

1100 There is some ICY info. Also matches 0100 or NEW_ICY.

Definition at line 1062 of file mpg123.h.

Referenced by mpg123_icy().

#define MPG123_ID3   0x3

0011 There is some ID3 info. Also matches 0010 or NEW_ID3.

Definition at line 1060 of file mpg123.h.

Referenced by handle_id3v2(), mpg123_id3(), and wetwork().

#define MPG123_NEW_ICY   0x4

0100 There is ICY info that changed since last call to mpg123_icy.

Definition at line 1063 of file mpg123.h.

Referenced by icy_fullread(), and mpg123_icy().

#define MPG123_NEW_ID3   0x1

0001 There is ID3 info that changed since last call to mpg123_id3.

Definition at line 1061 of file mpg123.h.

Referenced by default_init(), handle_id3v2(), mpg123_id3(), and wetwork().

Enumeration Type Documentation

The encoding byte values from ID3v2.

Enumerator
mpg123_id3_latin1 

Note: This sometimes can mean anything in practice...

mpg123_id3_utf16bom 

UTF16, UCS-2 ... it's all the same for practical purposes.

mpg123_id3_utf16be 

Big-endian UTF-16, BOM see note for mpg123_text_utf16be.

mpg123_id3_utf8 

Our lovely overly ASCII-compatible 8 byte encoding for the world.

mpg123_id3_enc_max 

Placeholder to check valid range of encoding byte.

Definition at line 944 of file mpg123.h.

The picture type values from ID3v2.

Enumerator
mpg123_id3_pic_other 
mpg123_id3_pic_icon 
mpg123_id3_pic_other_icon 
mpg123_id3_pic_front_cover 
mpg123_id3_pic_back_cover 
mpg123_id3_pic_leaflet 
mpg123_id3_pic_media 
mpg123_id3_pic_lead 
mpg123_id3_pic_artist 
mpg123_id3_pic_conductor 
mpg123_id3_pic_orchestra 
mpg123_id3_pic_composer 
mpg123_id3_pic_lyricist 
mpg123_id3_pic_location 
mpg123_id3_pic_recording 
mpg123_id3_pic_performance 
mpg123_id3_pic_video 
mpg123_id3_pic_fish 
mpg123_id3_pic_illustration 
mpg123_id3_pic_artist_logo 
mpg123_id3_pic_publisher_logo 

Definition at line 981 of file mpg123.h.

982 {
1000  ,mpg123_id3_pic_fish = 17
1004 };

The mpg123 text encodings. This contains encodings we encounter in ID3 tags or ICY meta info.

Enumerator
mpg123_text_unknown 

Unkown encoding... mpg123_id3_encoding can return that on invalid codes.

mpg123_text_utf8 

UTF-8

mpg123_text_latin1 

ISO-8859-1. Note that sometimes latin1 in ID3 is abused for totally different encodings.

mpg123_text_icy 

ICY metadata encoding, usually CP-1252 but we take it as UTF-8 if it qualifies as such.

mpg123_text_cp1252 

Really CP-1252 without any guessing.

mpg123_text_utf16 

Some UTF-16 encoding. The last of a set of leading BOMs (byte order mark) rules. When there is no BOM, big endian ordering is used. Note that UCS-2 qualifies as UTF-8 when you don't mess with the reserved code points. If you want to decode little endian data without BOM you need to prepend 0xff 0xfe yourself.

mpg123_text_utf16bom 

Just an alias for UTF-16, ID3v2 has this as distinct code.

mpg123_text_utf16be 

Another alias for UTF16 from ID3v2. Note, that, because of the mess that is reality, BOMs are used if encountered. There really is not much distinction between the UTF16 types for mpg123 One exception: Since this is seen in ID3v2 tags, leading null bytes are skipped for all other UTF16 types (we expect a BOM before real data there), not so for utf16be!

mpg123_text_max 

Placeholder for the maximum encoding value.

Definition at line 924 of file mpg123.h.

Function Documentation

MPG123_EXPORT int mpg123_add_string ( mpg123_string sb,
const char stuff 
)

Append a C-String to an mpg123_string

Returns
0 on error, 1 on success

Definition at line 88 of file stringbuf.c.

Referenced by mpg123_set_string().

89 {
90  debug1("adding %s", stuff);
91  return mpg123_add_substring(sb, stuff, 0, strlen(stuff));
92 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define debug1(s, a)
Definition: debug.h:45
int attribute_align_arg mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count)
Definition: stringbuf.c:94
MPG123_EXPORT int mpg123_add_substring ( mpg123_string sb,
const char stuff,
size_t  from,
size_t  count 
)

Append a C-substring to an mpg123 string

Returns
0 on error, 1 on success
Parameters
fromoffset to copy from
countnumber of characters to copy (a null-byte is always appended)

Definition at line 94 of file stringbuf.c.

Referenced by mpg123_add_string(), and mpg123_set_substring().

95 {
96  debug("adding a substring");
97  if(sb->fill) /* includes zero byte... */
98  {
99  if( (SIZE_MAX - sb->fill >= count) /* Avoid overflow. */
100  && (sb->size >= sb->fill+count || mpg123_grow_string(sb, sb->fill+count)) )
101  {
102  memcpy(sb->p+sb->fill-1, stuff+from, count);
103  sb->fill += count;
104  sb->p[sb->fill-1] = 0; /* Terminate! */
105  }
106  else return 0;
107  }
108  else
109  {
110  if( count < SIZE_MAX && mpg123_grow_string(sb, count+1) )
111  {
112  memcpy(sb->p, stuff+from, count);
113  sb->fill = count+1;
114  sb->p[sb->fill-1] = 0; /* Terminate! */
115  }
116  else return 0;
117  }
118  return 1;
119 }
#define SIZE_MAX
Definition: limits.h:75
size_t size
Definition: mpg123.h:865
#define debug(s)
Definition: debug.h:44
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
CardRegion * from
Definition: spigame.cpp:19
size_t fill
Definition: mpg123.h:866
int attribute_align_arg mpg123_grow_string(mpg123_string *sb, size_t new)
Definition: stringbuf.c:29
char * p
Definition: mpg123.h:864
MPG123_EXPORT int mpg123_chomp_string ( mpg123_string sb)

Remove trailing and
, if present.

Returns
0 on error, 1 on success
Parameters
sbthe string

Definition at line 165 of file stringbuf.c.

166 {
167  ssize_t i;
168  if(!sb || !sb->fill) return 0;
169 
170  /* Ensure that it is zero-terminated. */
171  sb->p[sb->fill-1] = 0;
172  for(i=sb->fill-2; i>=0; --i)
173  {
174  char *c = sb->p+i;
175  /* Stop at the first proper character. */
176  if(*c && *c != '\r' && *c != '\n') break;
177  else *c = 0;
178  }
179  /* initial fill at least 1, so i at least -1,
180  +2 means nothing happened for fill=1 .
181  With i=0, we got one non-null character, fill shall be 2
182  to accomodate the trailing zero. */
183  sb->fill = (size_t)i+2;
184 
185  return 1;
186 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
__kernel_size_t size_t
Definition: linux.h:237
const GLubyte * c
Definition: glext.h:8905
int ssize_t
Definition: rosdhcp.h:48
size_t fill
Definition: mpg123.h:866
char * p
Definition: mpg123.h:864
MPG123_EXPORT int mpg123_copy_string ( mpg123_string from,
mpg123_string to 
)

Copy the contents of one mpg123_string string to another.

Returns
0 on error, 1 on success

Definition at line 61 of file stringbuf.c.

62 {
63  size_t fill;
64  char *text;
65  if(to == NULL) return -1;
66 
67  debug2("called copy_string with %p -> %p", (void*)from, (void*)to);
68  if(from == NULL)
69  {
70  fill = 0;
71  text = NULL;
72  }
73  else
74  {
75  fill = from->fill;
76  text = from->p;
77  }
78 
79  if(mpg123_resize_string(to, fill))
80  {
81  memcpy(to->p, text, fill);
82  to->fill = fill;
83  return 1;
84  }
85  else return 0;
86 }
#define debug2(s, a, b)
Definition: debug.h:46
#define NULL
Definition: mystdio.h:57
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LPCSTR text
Definition: menu.c:130
int attribute_align_arg mpg123_resize_string(mpg123_string *sb, size_t new)
Definition: stringbuf.c:35
size_t fill
Definition: mpg123.h:866
char * p
Definition: mpg123.h:864
MPG123_EXPORT enum mpg123_text_encoding mpg123_enc_from_id3 ( unsigned char  id3_enc_byte)

Convert ID3 encoding byte to mpg123 encoding index.

Definition at line 1454 of file libmpg123.c.

1455 {
1456  switch(id3_enc_byte)
1457  {
1459  case mpg123_id3_utf16bom: return mpg123_text_utf16bom; /* ID3v2.3 has UCS-2 with BOM here. */
1461  case mpg123_id3_utf8: return mpg123_text_utf8;
1462  default: return mpg123_text_unknown;
1463  }
1464 }
MPG123_EXPORT void mpg123_free_string ( mpg123_string sb)

Free-up mempory for an existing mpg123_string

Definition at line 23 of file stringbuf.c.

Referenced by convert_latin1(), convert_utf16bom(), convert_utf8(), free_mpg123_picture(), free_mpg123_text(), id3_to_utf8(), and mpg123_store_utf8().

24 {
25  if(sb->p != NULL) free(sb->p);
27 }
#define free
Definition: debug_ros.c:5
#define NULL
Definition: mystdio.h:57
void attribute_align_arg mpg123_init_string(mpg123_string *sb)
Definition: stringbuf.c:16
char * p
Definition: mpg123.h:864
MPG123_EXPORT int mpg123_grow_string ( mpg123_string sb,
size_t  news 
)

Increase size of a mpg123_string if necessary (it may stay larger). Note that the functions for adding and setting in current libmpg123 use this instead of mpg123_resize_string(). That way, you can preallocate memory and safely work afterwards with pieces.

Returns
0 on error, 1 on success

Definition at line 29 of file stringbuf.c.

Referenced by mpg123_add_substring().

30 {
31  if(sb->size < new) return mpg123_resize_string(sb, new);
32  else return 1;
33 }
size_t size
Definition: mpg123.h:865
int attribute_align_arg mpg123_resize_string(mpg123_string *sb, size_t new)
Definition: stringbuf.c:35
MPG123_EXPORT int mpg123_icy ( mpg123_handle mh,
char **  icy_meta 
)

Point icy_meta to existing data structure wich may change on any next read/decode function call.

Returns
MPG123_OK on success

Definition at line 1420 of file libmpg123.c.

1421 {
1422  if(mh == NULL) return MPG123_BAD_HANDLE;
1423 #ifndef NO_ICY
1424  if(icy_meta == NULL)
1425  {
1426  mh->err = MPG123_NULL_POINTER;
1427  return MPG123_ERR;
1428  }
1429  *icy_meta = NULL;
1430 
1431  if(mh->metaflags & MPG123_ICY)
1432  {
1433  *icy_meta = mh->icy.data;
1434  mh->metaflags |= MPG123_ICY;
1435  mh->metaflags &= ~MPG123_NEW_ICY;
1436  }
1437  return MPG123_OK;
1438 #else
1440  return MPG123_ERR;
1441 #endif
1442 }
Definition: icy.h:16
#define MPG123_NEW_ICY
Definition: mpg123.h:1063
#define NULL
Definition: mystdio.h:57
struct icy_meta icy
Definition: frame.h:298
#define MPG123_ICY
Definition: mpg123.h:1062
MPG123_EXPORT char* mpg123_icy2utf8 ( const char icy_text)

Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8. Note that this is very similar to mpg123_store_utf8(&sb, mpg123_text_icy, icy_text, strlen(icy_text+1)) .

Parameters
icy_textThe input data in ICY encoding
Returns
pointer to newly allocated buffer with UTF-8 data (You free() it!)

Definition at line 1444 of file libmpg123.c.

1445 {
1446 #ifndef NO_ICY
1447  return icy2utf8(icy_text, 0);
1448 #else
1449  return NULL;
1450 #endif
1451 }
#define NULL
Definition: mystdio.h:57
#define icy2utf8
Definition: intsym.h:182
MPG123_EXPORT int mpg123_id3 ( mpg123_handle mh,
mpg123_id3v1 **  v1,
mpg123_id3v2 **  v2 
)

Point v1 and v2 to existing data structures wich may change on any next read/decode function call. v1 and/or v2 can be set to NULL when there is no corresponding data.

Returns
MPG123_OK on success

Definition at line 1397 of file libmpg123.c.

1398 {
1399  if(v1 != NULL) *v1 = NULL;
1400  if(v2 != NULL) *v2 = NULL;
1401  if(mh == NULL) return MPG123_BAD_HANDLE;
1402 
1403  if(mh->metaflags & MPG123_ID3)
1404  {
1405  id3_link(mh);
1406  if(v1 != NULL && mh->rdat.flags & READER_ID3TAG) *v1 = (mpg123_id3v1*) mh->id3buf;
1407  if(v2 != NULL)
1408 #ifdef NO_ID3V2
1409  *v2 = NULL;
1410 #else
1411  *v2 = &mh->id3v2;
1412 #endif
1413 
1414  mh->metaflags |= MPG123_ID3;
1415  mh->metaflags &= ~MPG123_NEW_ID3;
1416  }
1417  return MPG123_OK;
1418 }
struct reader_data rdat
Definition: frame.h:285
#define id3_link
Definition: intsym.h:189
#define MPG123_NEW_ID3
Definition: mpg123.h:1061
#define NULL
Definition: mystdio.h:57
#define READER_ID3TAG
Definition: reader.h:114
#define MPG123_ID3
Definition: mpg123.h:1060
mpg123_id3v2 id3v2
Definition: frame.h:295
unsigned char id3buf[128]
Definition: frame.h:293
MPG123_EXPORT void mpg123_init_string ( mpg123_string sb)

Create and allocate memory for a new mpg123_string

Definition at line 16 of file stringbuf.c.

Referenced by init_mpg123_picture(), init_mpg123_text(), mpg123_free_string(), and mpg123_resize_string().

17 {
18  sb->p = NULL;
19  sb->size = 0;
20  sb->fill = 0;
21 }
size_t size
Definition: mpg123.h:865
#define NULL
Definition: mystdio.h:57
size_t fill
Definition: mpg123.h:866
char * p
Definition: mpg123.h:864
MPG123_EXPORT int mpg123_meta_check ( mpg123_handle mh)

Query if there is (new) meta info, be it ID3 or ICY (or something new in future). The check function returns a combination of flags.

Definition at line 1383 of file libmpg123.c.

1384 {
1385  if(mh != NULL) return mh->metaflags;
1386  else return 0;
1387 }
#define NULL
Definition: mystdio.h:57
MPG123_EXPORT void mpg123_meta_free ( mpg123_handle mh)

Clean up meta data storage (ID3v2 and ICY), freeing memory.

Definition at line 1389 of file libmpg123.c.

1390 {
1391  if(mh == NULL) return;
1392 
1393  reset_id3(mh);
1394  reset_icy(&mh->icy);
1395 }
#define reset_id3
Definition: intsym.h:188
#define reset_icy
Definition: intsym.h:185
#define NULL
Definition: mystdio.h:57
struct icy_meta icy
Definition: frame.h:298
MPG123_EXPORT int mpg123_resize_string ( mpg123_string sb,
size_t  news 
)

Change the size of a mpg123_string

Returns
0 on error, 1 on success

Definition at line 35 of file stringbuf.c.

Referenced by convert_latin1(), convert_utf16bom(), convert_utf8(), mpg123_copy_string(), mpg123_grow_string(), and store_id3_text().

36 {
37  debug3("resizing string pointer %p from %lu to %lu", (void*) sb->p, (unsigned long)sb->size, (unsigned long)new);
38  if(new == 0)
39  {
40  if(sb->size && sb->p != NULL) free(sb->p);
42  return 1;
43  }
44  if(sb->size != new)
45  {
46  char* t;
47  debug("really!");
48  t = (char*) safe_realloc(sb->p, new*sizeof(char));
49  debug1("safe_realloc returned %p", (void*) t);
50  if(t != NULL)
51  {
52  sb->p = t;
53  sb->size = new;
54  return 1;
55  }
56  else return 0;
57  }
58  else return 1; /* success */
59 }
#define free
Definition: debug_ros.c:5
GLdouble GLdouble t
Definition: gl.h:2047
#define safe_realloc
Definition: intsym.h:7
size_t size
Definition: mpg123.h:865
#define debug3(s, a, b, c)
Definition: debug.h:47
#define NULL
Definition: mystdio.h:57
void attribute_align_arg mpg123_init_string(mpg123_string *sb)
Definition: stringbuf.c:16
#define debug(s)
Definition: debug.h:44
#define debug1(s, a)
Definition: debug.h:45
char * p
Definition: mpg123.h:864
MPG123_EXPORT int mpg123_set_string ( mpg123_string sb,
const char stuff 
)

Set the conents of a mpg123_string to a C-string

Returns
0 on error, 1 on success

Definition at line 127 of file stringbuf.c.

Referenced by mpg123_store_utf8().

128 {
129  sb->fill = 0;
130  return mpg123_add_string(sb, stuff);
131 }
int attribute_align_arg mpg123_add_string(mpg123_string *sb, const char *stuff)
Definition: stringbuf.c:88
size_t fill
Definition: mpg123.h:866
MPG123_EXPORT int mpg123_set_substring ( mpg123_string sb,
const char stuff,
size_t  from,
size_t  count 
)

Set the contents of a mpg123_string to a C-substring

Returns
0 on error, 1 on success
Parameters
fromoffset to copy from
countnumber of characters to copy (a null-byte is always appended)

Definition at line 121 of file stringbuf.c.

122 {
123  sb->fill = 0;
124  return mpg123_add_substring(sb, stuff, from, count);
125 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
CardRegion * from
Definition: spigame.cpp:19
size_t fill
Definition: mpg123.h:866
int attribute_align_arg mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count)
Definition: stringbuf.c:94
MPG123_EXPORT int mpg123_store_utf8 ( mpg123_string sb,
enum mpg123_text_encoding  enc,
const unsigned char source,
size_t  source_size 
)

Store text data in string, after converting to UTF-8 from indicated encoding

Returns
0 on error, 1 on success (on error, mpg123_free_string is called on sb)
Parameters
sbtarget string
encmpg123 text encoding value
sourcesource buffer with plain unsigned bytes (you might need to cast from char *)
source_sizenumber of bytes in the source buffer

A prominent error can be that you provided an unknown encoding value, or this build of libmpg123 lacks support for certain encodings (ID3 or ICY stuff missing). Also, you might want to take a bit of care with preparing the data; for example, strip leading zeroes (I have seen that).

Definition at line 1467 of file libmpg123.c.

1468 {
1469  switch(enc)
1470  {
1471 #ifndef NO_ID3V2
1472  /* The encodings we get from ID3v2 tags. */
1473  case mpg123_text_utf8:
1474  id3_to_utf8(sb, mpg123_id3_utf8, source, source_size, 0);
1475  break;
1476  case mpg123_text_latin1:
1477  id3_to_utf8(sb, mpg123_id3_latin1, source, source_size, 0);
1478  break;
1479  case mpg123_text_utf16bom:
1480  case mpg123_text_utf16:
1481  id3_to_utf8(sb, mpg123_id3_utf16bom, source, source_size, 0);
1482  break;
1483  /* Special because one cannot skip zero bytes here. */
1484  case mpg123_text_utf16be:
1485  id3_to_utf8(sb, mpg123_id3_utf16be, source, source_size, 0);
1486  break;
1487 #endif
1488 #ifndef NO_ICY
1489  /* ICY encoding... */
1490  case mpg123_text_icy:
1491  case mpg123_text_cp1252:
1492  {
1493  mpg123_free_string(sb);
1494  /* Paranoia: Make sure that the string ends inside the buffer... */
1495  if(source[source_size-1] == 0)
1496  {
1497  /* Convert from ICY encoding... with force applied or not. */
1498  char *tmpstring = icy2utf8((const char*)source, enc == mpg123_text_cp1252 ? 1 : 0);
1499  if(tmpstring != NULL)
1500  {
1501  mpg123_set_string(sb, tmpstring);
1502  free(tmpstring);
1503  }
1504  }
1505  }
1506  break;
1507 #endif
1508  default:
1509  mpg123_free_string(sb);
1510  }
1511  /* At least a trailing null of some form should be there... */
1512  return (sb->fill > 0) ? 1 : 0;
1513 }
#define free
Definition: debug_ros.c:5
MPG123_EXPORT void mpg123_free_string(mpg123_string *sb)
Definition: stringbuf.c:23
#define id3_to_utf8
Definition: intsym.h:191
#define NULL
Definition: mystdio.h:57
MPG123_EXPORT int mpg123_set_string(mpg123_string *sb, const char *stuff)
Definition: stringbuf.c:127
#define icy2utf8
Definition: intsym.h:182
size_t fill
Definition: mpg123.h:866
MPG123_EXPORT size_t mpg123_strlen ( mpg123_string sb,
int  utf8 
)

Count characters in a mpg123 string (non-null bytes or UTF-8 characters).

Returns
character count
Parameters
sbthe string
utf8a flag to tell if the string is in utf8 encoding Even with the fill property, the character count is not obvious as there could be multiple trailing null bytes.

Definition at line 133 of file stringbuf.c.

134 {
135  size_t i;
136  size_t bytelen;
137 
138  /* Notions of empty string. If there's only a single character, it has to be the trailing zero, and if the first is the trailing zero anyway, we got empty. */
139  if(sb->fill < 2 || sb->p[0] == 0) return 0;
140 
141  /* Find the first non-null character from the back.
142  We already established that the first character is non-null
143  That at fill-2 has to be null, though. */
144  for(i=sb->fill-2; i>0; --i)
145  if(sb->p[i] != 0) break;
146 
147  /* For simple byte strings, we are done now. */
148  bytelen = i+1;
149 
150  if(!utf8) return bytelen;
151  else
152  {
153  /* Work out the actual count of UTF8 bytes.
154  This employs no particular encoding error checking. */
155  size_t len = 0;
156  for(i=0; i<bytelen; ++i)
157  {
158  /* Every byte that is not a continuation byte ( 0xc0 == 10xx xxxx ) stands for a character. */
159  if((sb->p[i] & 0xc0) != 0x80) len++;
160  }
161  return len;
162  }
163 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLenum GLsizei len
Definition: glext.h:6722
size_t fill
Definition: mpg123.h:866
char * p
Definition: mpg123.h:864