[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

formatted output functions for Unicode strings

From: Bruno Haible
Subject: formatted output functions for Unicode strings
Date: Mon, 2 Jul 2007 03:35:20 +0200
User-agent: KMail/1.5.4

Here I'm adding the first part of the Unicode string library: the
formatted output functions.

The modifications to lib/vasnprintf.c were already committed three weeks ago.

2007-07-01  Bruno Haible  <address@hidden>

        * lib/unistdio.h: New file.
        * lib/unistdio/u-asnprintf.h: New file.
        * lib/unistdio/u-asprintf.h: New file.
        * lib/unistdio/u-printf-args.c: New file.
        * lib/unistdio/u-printf-args.h: New file.
        * lib/unistdio/u-printf-parse.h: New file.
        * lib/unistdio/u-snprintf.h: New file.
        * lib/unistdio/u-sprintf.h: New file.
        * lib/unistdio/u-vasprintf.h: New file.
        * lib/unistdio/u-vsnprintf.h: New file.
        * lib/unistdio/u-vsprintf.h: New file.
        * lib/unistdio/ulc-asnprintf.c: New file.
        * lib/unistdio/ulc-asprintf.c: New file.
        * lib/unistdio/ulc-fprintf.c: New file, based on lib/fprintf.c.
        * lib/unistdio/ulc-printf-parse.c: New file.
        * lib/unistdio/ulc-snprintf.c: New file.
        * lib/unistdio/ulc-sprintf.c: New file.
        * lib/unistdio/ulc-vasnprintf.c: New file.
        * lib/unistdio/ulc-vasprintf.c: New file.
        * lib/unistdio/ulc-vfprintf.c: New file, based on lib/vfprintf.c.
        * lib/unistdio/ulc-vsnprintf.c: New file.
        * lib/unistdio/ulc-vsprintf.c: New file.
        * lib/unistdio/u8-asnprintf.c: New file.
        * lib/unistdio/u8-asprintf.c: New file.
        * lib/unistdio/u8-printf-parse.c: New file.
        * lib/unistdio/u8-snprintf.c: New file.
        * lib/unistdio/u8-sprintf.c: New file.
        * lib/unistdio/u8-vasnprintf.c: New file.
        * lib/unistdio/u8-vasprintf.c: New file.
        * lib/unistdio/u8-vsnprintf.c: New file.
        * lib/unistdio/u8-vsprintf.c: New file.
        * lib/unistdio/u8-u8-asnprintf.c: New file.
        * lib/unistdio/u8-u8-asprintf.c: New file.
        * lib/unistdio/u8-u8-snprintf.c: New file.
        * lib/unistdio/u8-u8-sprintf.c: New file.
        * lib/unistdio/u8-u8-vasnprintf.c: New file.
        * lib/unistdio/u8-u8-vasprintf.c: New file.
        * lib/unistdio/u8-u8-vsnprintf.c: New file.
        * lib/unistdio/u8-u8-vsprintf.c: New file.
        * lib/unistdio/u16-asnprintf.c: New file.
        * lib/unistdio/u16-asprintf.c: New file.
        * lib/unistdio/u16-printf-parse.c: New file.
        * lib/unistdio/u16-snprintf.c: New file.
        * lib/unistdio/u16-sprintf.c: New file.
        * lib/unistdio/u16-vasnprintf.c: New file.
        * lib/unistdio/u16-vasprintf.c: New file.
        * lib/unistdio/u16-vsnprintf.c: New file.
        * lib/unistdio/u16-vsprintf.c: New file.
        * lib/unistdio/u16-u16-asnprintf.c: New file.
        * lib/unistdio/u16-u16-asprintf.c: New file.
        * lib/unistdio/u16-u16-snprintf.c: New file.
        * lib/unistdio/u16-u16-sprintf.c: New file.
        * lib/unistdio/u16-u16-vasnprintf.c: New file.
        * lib/unistdio/u16-u16-vasprintf.c: New file.
        * lib/unistdio/u16-u16-vsnprintf.c: New file.
        * lib/unistdio/u16-u16-vsprintf.c: New file.
        * lib/unistdio/u32-asnprintf.c: New file.
        * lib/unistdio/u32-asprintf.c: New file.
        * lib/unistdio/u32-printf-parse.c: New file.
        * lib/unistdio/u32-snprintf.c: New file.
        * lib/unistdio/u32-sprintf.c: New file.
        * lib/unistdio/u32-vasnprintf.c: New file.
        * lib/unistdio/u32-vasprintf.c: New file.
        * lib/unistdio/u32-vsnprintf.c: New file.
        * lib/unistdio/u32-vsprintf.c: New file.
        * lib/unistdio/u32-u32-asnprintf.c: New file.
        * lib/unistdio/u32-u32-asprintf.c: New file.
        * lib/unistdio/u32-u32-snprintf.c: New file.
        * lib/unistdio/u32-u32-sprintf.c: New file.
        * lib/unistdio/u32-u32-vasnprintf.c: New file.
        * lib/unistdio/u32-u32-vasprintf.c: New file.
        * lib/unistdio/u32-u32-vsnprintf.c: New file.
        * lib/unistdio/u32-u32-vsprintf.c: New file.
        * tests/unistdio/test-ulc-asnprintf1.c: New file.
        * tests/unistdio/test-ulc-asnprintf1.h: New file.
        * tests/unistdio/test-ulc-printf1.h: New file.
        * tests/unistdio/test-ulc-vasnprintf1.c: New file.
        * tests/unistdio/test-ulc-vasnprintf2.c: New file.
        * tests/unistdio/test-ulc-vasnprintf2.sh: New file.
        * tests/unistdio/test-ulc-vasnprintf3.c: New file.
        * tests/unistdio/test-ulc-vasnprintf3.sh: New file.
        * tests/unistdio/test-ulc-vasprintf1.c: New file.
        * tests/unistdio/test-ulc-vsnprintf1.c: New file.
        * tests/unistdio/test-ulc-vsprintf1.c: New file.
        * tests/unistdio/test-u8-asnprintf1.c: New file.
        * tests/unistdio/test-u8-asnprintf1.h: New file.
        * tests/unistdio/test-u8-printf1.h: New file.
        * tests/unistdio/test-u8-vasnprintf1.c: New file.
        * tests/unistdio/test-u8-vasnprintf2.c: New file.
        * tests/unistdio/test-u8-vasnprintf2.sh: New file.
        * tests/unistdio/test-u8-vasnprintf3.c: New file.
        * tests/unistdio/test-u8-vasnprintf3.sh: New file.
        * tests/unistdio/test-u8-vasprintf1.c: New file.
        * tests/unistdio/test-u8-vsnprintf1.c: New file.
        * tests/unistdio/test-u8-vsprintf1.c: New file.
        * tests/unistdio/test-u16-asnprintf1.c: New file.
        * tests/unistdio/test-u16-asnprintf1.h: New file.
        * tests/unistdio/test-u16-printf1.h: New file.
        * tests/unistdio/test-u16-vasnprintf1.c: New file.
        * tests/unistdio/test-u16-vasnprintf2.c: New file.
        * tests/unistdio/test-u16-vasnprintf2.sh: New file.
        * tests/unistdio/test-u16-vasnprintf3.c: New file.
        * tests/unistdio/test-u16-vasnprintf3.sh: New file.
        * tests/unistdio/test-u16-vasprintf1.c: New file.
        * tests/unistdio/test-u16-vsnprintf1.c: New file.
        * tests/unistdio/test-u16-vsprintf1.c: New file.
        * tests/unistdio/test-u32-asnprintf1.c: New file.
        * tests/unistdio/test-u32-asnprintf1.h: New file.
        * tests/unistdio/test-u32-printf1.h: New file.
        * tests/unistdio/test-u32-vasnprintf1.c: New file.
        * tests/unistdio/test-u32-vasnprintf2.c: New file.
        * tests/unistdio/test-u32-vasnprintf2.sh: New file.
        * tests/unistdio/test-u32-vasnprintf3.c: New file.
        * tests/unistdio/test-u32-vasnprintf3.sh: New file.
        * tests/unistdio/test-u32-vasprintf1.c: New file.
        * tests/unistdio/test-u32-vsnprintf1.c: New file.
        * tests/unistdio/test-u32-vsprintf1.c: New file.
        * modules/unistdio/base: New file.
        * modules/unistdio/u-printf-args: New file.
        * modules/unistdio/ulc-asnprintf: New file.
        * modules/unistdio/ulc-asprintf: New file.
        * modules/unistdio/ulc-fprintf: New file.
        * modules/unistdio/ulc-printf-parse: New file.
        * modules/unistdio/ulc-snprintf: New file.
        * modules/unistdio/ulc-sprintf: New file.
        * modules/unistdio/ulc-vasnprintf: New file.
        * modules/unistdio/ulc-vasprintf: New file.
        * modules/unistdio/ulc-vfprintf: New file.
        * modules/unistdio/ulc-vsnprintf: New file.
        * modules/unistdio/ulc-vsprintf: New file.
        * modules/unistdio/u8-asnprintf: New file.
        * modules/unistdio/u8-asprintf: New file.
        * modules/unistdio/u8-printf-parse: New file.
        * modules/unistdio/u8-snprintf: New file.
        * modules/unistdio/u8-sprintf: New file.
        * modules/unistdio/u8-vasnprintf: New file.
        * modules/unistdio/u8-vasprintf: New file.
        * modules/unistdio/u8-vsnprintf: New file.
        * modules/unistdio/u8-vsprintf: New file.
        * modules/unistdio/u8-u8-asnprintf: New file.
        * modules/unistdio/u8-u8-asprintf: New file.
        * modules/unistdio/u8-u8-snprintf: New file.
        * modules/unistdio/u8-u8-sprintf: New file.
        * modules/unistdio/u8-u8-vasnprintf: New file.
        * modules/unistdio/u8-u8-vasprintf: New file.
        * modules/unistdio/u8-u8-vsnprintf: New file.
        * modules/unistdio/u8-u8-vsprintf: New file.
        * modules/unistdio/u16-asnprintf: New file.
        * modules/unistdio/u16-asprintf: New file.
        * modules/unistdio/u16-printf-parse: New file.
        * modules/unistdio/u16-snprintf: New file.
        * modules/unistdio/u16-sprintf: New file.
        * modules/unistdio/u16-vasnprintf: New file.
        * modules/unistdio/u16-vasprintf: New file.
        * modules/unistdio/u16-vsnprintf: New file.
        * modules/unistdio/u16-vsprintf: New file.
        * modules/unistdio/u16-u16-asnprintf: New file.
        * modules/unistdio/u16-u16-asprintf: New file.
        * modules/unistdio/u16-u16-snprintf: New file.
        * modules/unistdio/u16-u16-sprintf: New file.
        * modules/unistdio/u16-u16-vasnprintf: New file.
        * modules/unistdio/u16-u16-vasprintf: New file.
        * modules/unistdio/u16-u16-vsnprintf: New file.
        * modules/unistdio/u16-u16-vsprintf: New file.
        * modules/unistdio/u32-asnprintf: New file.
        * modules/unistdio/u32-asprintf: New file.
        * modules/unistdio/u32-printf-parse: New file.
        * modules/unistdio/u32-snprintf: New file.
        * modules/unistdio/u32-sprintf: New file.
        * modules/unistdio/u32-vasnprintf: New file.
        * modules/unistdio/u32-vasprintf: New file.
        * modules/unistdio/u32-vsnprintf: New file.
        * modules/unistdio/u32-vsprintf: New file.
        * modules/unistdio/u32-u32-asnprintf: New file.
        * modules/unistdio/u32-u32-asprintf: New file.
        * modules/unistdio/u32-u32-snprintf: New file.
        * modules/unistdio/u32-u32-sprintf: New file.
        * modules/unistdio/u32-u32-vasnprintf: New file.
        * modules/unistdio/u32-u32-vasprintf: New file.
        * modules/unistdio/u32-u32-vsnprintf: New file.
        * modules/unistdio/u32-u32-vsprintf: New file.
        * modules/unistdio/ulc-asnprintf-tests: New file.
        * modules/unistdio/ulc-vasnprintf-tests: New file.
        * modules/unistdio/ulc-vasprintf-tests: New file.
        * modules/unistdio/ulc-vsnprintf-tests: New file.
        * modules/unistdio/ulc-vsprintf-tests: New file.
        * modules/unistdio/u8-asnprintf-tests: New file.
        * modules/unistdio/u8-vasnprintf-tests: New file.
        * modules/unistdio/u8-vasprintf-tests: New file.
        * modules/unistdio/u8-vsnprintf-tests: New file.
        * modules/unistdio/u8-vsprintf-tests: New file.
        * modules/unistdio/u16-asnprintf-tests: New file.
        * modules/unistdio/u16-vasnprintf-tests: New file.
        * modules/unistdio/u16-vasprintf-tests: New file.
        * modules/unistdio/u16-vsnprintf-tests: New file.
        * modules/unistdio/u16-vsprintf-tests: New file.
        * modules/unistdio/u32-asnprintf-tests: New file.
        * modules/unistdio/u32-vasnprintf-tests: New file.
        * modules/unistdio/u32-vasprintf-tests: New file.
        * modules/unistdio/u32-vsnprintf-tests: New file.
        * modules/unistdio/u32-vsprintf-tests: New file.
        * MODULES.html.sh (Unicode string functions): Add the new modules.

========================= lib/unistdio.h ============================
/* Elementary Unicode string functions.
   Copyright (C) 2002, 2005-2007 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU Library General Public License as published
   by the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
   USA.  */

#ifndef _UNISTDIO_H
#define _UNISTDIO_H

#include "unitypes.h"

/* Get size_t.  */
#include <stddef.h>

/* Get FILE.  */
#include <stdio.h>

/* Get va_list.  */
#include <stdarg.h>

#ifdef __cplusplus
extern "C" {

/* These work like the printf function family.
   In the format string:
   The format directive 'U' takes an UTF-8 string (const uint8_t *).
   The format directive 'lU' takes an UTF-16 string (const uint16_t *).
   The format directive 'llU' takes an UTF-32 string (const uint32_t *).

   The prefix (ulc_, u8_, u16_, u16_) indicates the type of the resulting
   string.  The prefix 'ulc' stands for "locale encoded".

   An infix 'v' indicates that a va_list is passed instead of multiple

   The functions *sprintf have a 'buf' argument that is assumed to be large
   enough.  (DANGEROUS!  Overflowing the buffer will crash the program.)
   The functions *snprintf have a 'buf' argument that is assumed to be 'size'
   units large.  (DANGEROUS!  The resulting string might be truncated in the
   middle of a multibyte character.)
   The functions *asprintf have a 'resultp' argument.  The result will be
   freshly allocated and stored in *resultp.
   The functions *asnprintf have a (resultbuf, lengthp) argument pair.  If
   resultbuf is not NULL and the result fits into *lengthp units, it is put
   in resultbuf, and resultbuf is returned.  Otherwise, a freshly allocated
   string is returned.  In both cases, *lengthp is set to the length (number
   of units) of the returned string.  In case of error, NULL is returned and
   errno is set.

/* ASCII format string, result in locale dependent encoded 'char *'.  */
extern int
       ulc_sprintf (char *buf,
                    const char *format, ...);
extern int
       ulc_snprintf (char *buf, size_t size,
                     const char *format, ...);
extern int
       ulc_asprintf (char **resultp,
                     const char *format, ...);
extern char *
       ulc_asnprintf (char *resultbuf, size_t *lengthp,
                      const char *format, ...);
extern int
       ulc_vsprintf (char *buf,
                     const char *format, va_list ap);
extern int
       ulc_vsnprintf (char *buf, size_t size,
                      const char *format, va_list ap);
extern int
       ulc_vasprintf (char **resultp,
                      const char *format, va_list ap);
extern char *
       ulc_vasnprintf (char *resultbuf, size_t *lengthp,
                       const char *format, va_list ap);

/* ASCII format string, result in UTF-8 format.  */
extern int
       u8_sprintf (uint8_t *buf,
                   const char *format, ...);
extern int
       u8_snprintf (uint8_t *buf, size_t size,
                    const char *format, ...);
extern int
       u8_asprintf (uint8_t **resultp,
                    const char *format, ...);
extern uint8_t *
       u8_asnprintf (uint8_t *resultbuf, size_t *lengthp,
                     const char *format, ...);
extern int
       u8_vsprintf (uint8_t *buf,
                    const char *format, va_list ap);
extern int
       u8_vsnprintf (uint8_t *buf, size_t size,
                     const char *format, va_list ap);
extern int
       u8_vasprintf (uint8_t **resultp,
                     const char *format, va_list ap);
extern uint8_t *
       u8_vasnprintf (uint8_t *resultbuf, size_t *lengthp,
                      const char *format, va_list ap);

/* UTF-8 format string, result in UTF-8 format.  */
extern int
       u8_u8_sprintf (uint8_t *buf,
                      const uint8_t *format, ...);
extern int
       u8_u8_snprintf (uint8_t *buf, size_t size,
                       const uint8_t *format, ...);
extern int
       u8_u8_asprintf (uint8_t **resultp,
                       const uint8_t *format, ...);
extern uint8_t *
       u8_u8_asnprintf (uint8_t *resultbuf, size_t *lengthp,
                        const uint8_t *format, ...);
extern int
       u8_u8_vsprintf (uint8_t *buf,
                       const uint8_t *format, va_list ap);
extern int
       u8_u8_vsnprintf (uint8_t *buf, size_t size,
                        const uint8_t *format, va_list ap);
extern int
       u8_u8_vasprintf (uint8_t **resultp,
                        const uint8_t *format, va_list ap);
extern uint8_t *
       u8_u8_vasnprintf (uint8_t *resultbuf, size_t *lengthp,
                         const uint8_t *format, va_list ap);

/* ASCII format string, result in UTF-16 format.  */
extern int
       u16_sprintf (uint16_t *buf,
                    const char *format, ...);
extern int
       u16_snprintf (uint16_t *buf, size_t size,
                     const char *format, ...);
extern int
       u16_asprintf (uint16_t **resultp,
                     const char *format, ...);
extern uint16_t *
       u16_asnprintf (uint16_t *resultbuf, size_t *lengthp,
                      const char *format, ...);
extern int
       u16_vsprintf (uint16_t *buf,
                     const char *format, va_list ap);
extern int
       u16_vsnprintf (uint16_t *buf, size_t size,
                      const char *format, va_list ap);
extern int
       u16_vasprintf (uint16_t **resultp,
                      const char *format, va_list ap);
extern uint16_t *
       u16_vasnprintf (uint16_t *resultbuf, size_t *lengthp,
                       const char *format, va_list ap);

/* UTF-16 format string, result in UTF-16 format.  */
extern int
       u16_u16_sprintf (uint16_t *buf,
                        const uint16_t *format, ...);
extern int
       u16_u16_snprintf (uint16_t *buf, size_t size,
                         const uint16_t *format, ...);
extern int
       u16_u16_asprintf (uint16_t **resultp,
                         const uint16_t *format, ...);
extern uint16_t *
       u16_u16_asnprintf (uint16_t *resultbuf, size_t *lengthp,
                          const uint16_t *format, ...);
extern int
       u16_u16_vsprintf (uint16_t *buf,
                         const uint16_t *format, va_list ap);
extern int
       u16_u16_vsnprintf (uint16_t *buf, size_t size,
                          const uint16_t *format, va_list ap);
extern int
       u16_u16_vasprintf (uint16_t **resultp,
                          const uint16_t *format, va_list ap);
extern uint16_t *
       u16_u16_vasnprintf (uint16_t *resultbuf, size_t *lengthp,
                           const uint16_t *format, va_list ap);

/* ASCII format string, result in UTF-32 format.  */
extern int
       u32_sprintf (uint32_t *buf,
                    const char *format, ...);
extern int
       u32_snprintf (uint32_t *buf, size_t size,
                     const char *format, ...);
extern int
       u32_asprintf (uint32_t **resultp,
                     const char *format, ...);
extern uint32_t *
       u32_asnprintf (uint32_t *resultbuf, size_t *lengthp,
                      const char *format, ...);
extern int
       u32_vsprintf (uint32_t *buf,
                     const char *format, va_list ap);
extern int
       u32_vsnprintf (uint32_t *buf, size_t size,
                      const char *format, va_list ap);
extern int
       u32_vasprintf (uint32_t **resultp,
                      const char *format, va_list ap);
extern uint32_t *
       u32_vasnprintf (uint32_t *resultbuf, size_t *lengthp,
                       const char *format, va_list ap);

/* UTF-32 format string, result in UTF-32 format.  */
extern int
       u32_u32_sprintf (uint32_t *buf,
                        const uint32_t *format, ...);
extern int
       u32_u32_snprintf (uint32_t *buf, size_t size,
                         const uint32_t *format, ...);
extern int
       u32_u32_asprintf (uint32_t **resultp,
                         const uint32_t *format, ...);
extern uint32_t *
       u32_u32_asnprintf (uint32_t *resultbuf, size_t *lengthp,
                          const uint32_t *format, ...);
extern int
       u32_u32_vsprintf (uint32_t *buf,
                         const uint32_t *format, va_list ap);
extern int
       u32_u32_vsnprintf (uint32_t *buf, size_t size,
                          const uint32_t *format, va_list ap);
extern int
       u32_u32_vasprintf (uint32_t **resultp,
                          const uint32_t *format, va_list ap);
extern uint32_t *
       u32_u32_vasnprintf (uint32_t *resultbuf, size_t *lengthp,
                           const uint32_t *format, va_list ap);

/* ASCII format string, output to FILE in locale dependent encoding.  */
extern int
       ulc_fprintf (FILE *stream,
                    const char *format, ...);
extern int
       ulc_vfprintf (FILE *stream,
                     const char *format, va_list ap);

#ifdef __cplusplus

#endif /* _UNISTDIO_H */
Please review the other files directly off the CVS.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]