ReactOS  0.4.14-dev-833-g5f692ed
icy2utf8.c File Reference
#include "config.h"
#include "intsym.h"
#include "compat.h"
Include dependency graph for icy2utf8.c:

Go to the source code of this file.

Macros

#define uint8_t   unsigned char
 
#define uint16_t   unsigned short
 

Functions

static int is_utf8 (const char *src)
 
charicy2utf8 (const char *src, int force)
 

Variables

static const uint8_t cp1252_utf8 []
 
static const uint16_t tblofs [257]
 

Macro Definition Documentation

◆ uint16_t

Definition at line 37 of file icy2utf8.c.

◆ uint8_t

Definition at line 36 of file icy2utf8.c.

Function Documentation

◆ icy2utf8()

char* icy2utf8 ( const char src,
int  force 
)

Definition at line 378 of file icy2utf8.c.

379 {
380  const uint8_t *s = (const uint8_t *)src;
381  size_t srclen, dstlen, i, k;
382  uint8_t ch, *d;
383  char *dst;
384 
385  /* Some funny streams from Apple/iTunes give ICY info in UTF-8 already.
386  So, be prepared and don't try to re-encode such. Unless forced. */
387  if(!force && is_utf8(src)) return (compat_strdup(src));
388 
389  srclen = strlen(src) + 1;
390  /* allocate conservatively */
391  if ((d = malloc(srclen * 3)) == NULL)
392  return (NULL);
393 
394  i = 0;
395  dstlen = 0;
396  while (i < srclen) {
397  ch = s[i++];
398  k = tblofs[ch];
399  while (k < tblofs[ch + 1])
400  d[dstlen++] = cp1252_utf8[k++];
401  }
402 
403  /* dstlen includes trailing NUL since srclen also does */
404  if ((dst = realloc(d, dstlen)) == NULL) {
405  free(d);
406  return (NULL);
407  }
408  return (dst);
409 }
#define realloc
Definition: debug_ros.c:6
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
#define d
Definition: ke_i.h:81
static const uint8_t cp1252_utf8[]
Definition: icy2utf8.c:39
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:51
GLdouble s
Definition: gl.h:2039
GLenum src
Definition: glext.h:6340
BYTE uint8_t
Definition: msvideo1.c:66
static int is_utf8(const char *src)
Definition: icy2utf8.c:336
#define compat_strdup
Definition: intsym.h:11
static DWORD dstlen
Definition: directory.c:51
GLenum GLenum dst
Definition: glext.h:6340
#define malloc
Definition: debug_ros.c:4
static const uint16_t tblofs[257]
Definition: icy2utf8.c:298
int k
Definition: mpi.c:3369

◆ is_utf8()

static int is_utf8 ( const char src)
static

Definition at line 336 of file icy2utf8.c.

337 {
338  uint8_t ch;
339  size_t i;
340  const uint8_t* s = (const uint8_t*) src;
341 
342  /* We make a loop over every character, until we find a null one.
343  Remember: The string is supposed to end with a NUL, so ahead checks are safe. */
344  while ((ch = *s++)) {
345  /* Ye olde 7bit ASCII chars 'rr fine for anything */
346  if(ch < 0x80) continue;
347 
348  /* Now, we watch out for non-UTF conform sequences. */
349  else if ((ch < 0xC2) || (ch > 0xFD))
350  return 0;
351  /* check for some misformed sequences */
352  if (((ch == 0xC2) && (s[0] < 0xA0)) ||
353  ((ch == 0xEF) && (s[0] == 0xBF) && (s[1] > 0xBD)))
354  /* XXX add more for outside the BMP */
355  return 0;
356 
357  /* Check the continuation bytes. */
358  if (ch < 0xE0) i = 1;
359  else if (ch < 0xF0) i = 2;
360  else if (ch < 0xF8) i = 3;
361  else if (ch < 0xFC) i = 4;
362  else
363  i = 5;
364 
365  while (i--)
366  if ((*s++ & 0xC0) != 0x80)
367  return 0;
368  }
369 
370  /* If no check failed, the string indeed looks like valid UTF-8. */
371  return 1;
372 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLdouble s
Definition: gl.h:2039
GLenum src
Definition: glext.h:6340
BYTE uint8_t
Definition: msvideo1.c:66

Referenced by icy2utf8().

Variable Documentation

◆ cp1252_utf8

const uint8_t cp1252_utf8[]
static

Definition at line 39 of file icy2utf8.c.

Referenced by icy2utf8().

◆ tblofs

const uint16_t tblofs[257]
static

Definition at line 298 of file icy2utf8.c.

Referenced by icy2utf8().