From: <ny...@us...> - 2007-02-09 01:55:34
|
Revision: 315 http://svn.sourceforge.net/pmplib/?rev=315&view=rev Author: nyaochi Date: 2007-02-08 17:55:34 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/pmplib/include/pmplib/ucs2char.h Removed Paths: ------------- trunk/pmplib/include/ucs2char.h Copied: trunk/pmplib/include/pmplib/ucs2char.h (from rev 314, trunk/pmplib/include/ucs2char.h) =================================================================== --- trunk/pmplib/include/pmplib/ucs2char.h (rev 0) +++ trunk/pmplib/include/pmplib/ucs2char.h 2007-02-09 01:55:34 UTC (rev 315) @@ -0,0 +1,682 @@ +/* + * UCS-2 character set library. + * + * Copyright (c) 2005-2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id$ */ + +#ifndef __UCS2CHAR_H__ +#define __UCS2CHAR_H__ + +#include <stdio.h> + +#ifdef UCS2_EXPORTS +#define UCS2API __declspec(dllexport) +#else +#define UCS2API +#endif + +#ifdef __cplusplus +extern "C" { +#endif/*__cplusplus*/ + +/** + * \addtogroup ucs2 UCS-2 Character/String API + * @{ + * + * The PMPlib UCS-2 character/string API provides a manupulation utility + * for characters/strings in UCS-2 encoding. As a number of portable media + * players support Unicode for displaying song information, PMPlib deals + * with Unicode characters/strings encoded in UCS-2. + * + * The byte order of UCS-2 character is dependent on the CPU architecture + * on which this code runs: e.g., little-endian on Intel IA-32/IA-64 and + * big-endian on IBM PowerPC. + */ + +/** + * Type definition of a UCS-2 character. + */ +typedef uint16_t ucs2char_t; + +/** + * Initialize the UCS-2 library. + * + * This function initializes internal variables used in the UCS-2 library. + * Call this function before using any other functions in this API. + * + * @retval int Zero if succeeded, otherwise non-zero value. + */ +UCS2API int ucs2init(); + + +/** + * @defgroup ucs2_conv Character encoding converter + * @{ + * + * This API subset converts the character encoding of a string from one to + * another. It supports mutual conversions between: + * UCS-2 and multi-byte character (i.e., \c char); + * UCS-2 and UTF-8. + * + * By default, this library detects the character encoding of multi-byte + * characters on the current system based on the value of LANG variable + * (for POSIX) or via GetACP() function (for Win32). + */ + +/** + * Set the encoding for multi-byte characters (for iconv/libiconv). + * + * This function change the default encoding for multi-byte characters to the + * character encoding specified by the \a encoding argument. + * + * @param encoding The pointer to the string specifying the character + * encoding. + * + * @note + * This function is effective only on environments with iconv (libiconv). + */ +UCS2API int ucs2setenc(const char *encoding); + +/** + * Get the encoding for multi-byte characters (for iconv/libiconv). + * + * This function returns the default encoding for multi-byte characters used + * in the UCS-2 API. + * + * @retval const char* The pointer to the string of the character encoding. + * + * @note + * This function is effective only on environments with iconv (libiconv). + */ +UCS2API const char *ucs2getenc(); + +/** + * Set the code page for multi-byte characters (for Win32). + * + * This function change the default encoding for multi-byte characters to the + * code page specified by the \a cp argument. + * + * @param cp The code page. + * + * @note + * This function is effective only on Win32 environments. + */ +UCS2API void ucs2setcp(int cp); + +/** + * Get the code page for multi-byte characters (for Win32). + * + * This function returns the default code page for multi-byte characters. + * + * @param cp The code page. + * + * @note + * This function is effective only on Win32 environments. + */ +UCS2API int ucs2getcp(); + +/** + * Convert a UCS-2 string to multi-byte characters. + * + * @param mbstr The pointer to the buffer for receiving multi-byte + * characters converted from the UCS-2 string. If + * \a mbs_size is zero, this argument is not be used. + * @param mbs_size The size, in bytes, of the buffer pointed to by the + * \a mbstr argument. If this value is zero, the function + * returns the number of bytes required for the buffer. + * @param ucs2str The pointer to the UCS-2 string to be converted. + * @param ucs_size The size, in number of UCS-2 characters, of the UCS-2 + * string, \a ucs2str. + * @retval size_t The number of bytes written to \a mbstr buffer if + * the conversion is successful. If \a mbs_size is zero, + * the return value is the required size, in bytes, for a + * buffer to receive the converted string. This function + * returns zero if an error occurred. + */ +UCS2API size_t ucs2tombs(char *mbstr, size_t mbs_size, const ucs2char_t *ucs2str, size_t ucs_size); + +/** + * Convert multi-byte characters to a UCS-2 string. + * + * @param ucs2str The pointer to the buffer for receiving UCS-2 string + * converted from the multi-byte characters. If + * \a ucs_size is zero, this argument is not be used. + * @param ucs_size The size, in number of UCS-2 characters, of the buffer + * pointed to by the \a ucs2str argument. If this value is + * zero, the function returns the number of UCS-2 + * characters required for the buffer. + * @param mbstr The pointer to the multi-byte characters to be + * converted. + * @param mbs_size The size, in bytes, of the multi-byte characters, + * \a mbstr. + * @retval size_t The number of UCS-2 characters written to \a ucs2str + * buffer if the conversion is successful. If \a ucs_size + * is zero, the return value is the required size, in + * number of UCS-2 characters, for a buffer to receive the + * converted string. This function returns zero if an error + * occurred. + */ +UCS2API size_t mbstoucs2(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size); + +/** + * Convert multi-byte characters in a specific encoding to a UCS-2 string. + * + * @param ucs2str The pointer to the buffer for receiving UCS-2 string + * converted from the multi-byte characters. If + * \a ucs_size is zero, this argument is not be used. + * @param ucs_size The size, in number of UCS-2 characters, of the buffer + * pointed to by the \a ucs2str argument. If this value is + * zero, the function returns the number of UCS-2 + * characters required for the buffer. + * @param mbstr The pointer to the multi-byte characters to be + * converted. + * @param mbs_size The size, in bytes, of the multi-byte characters, + * \a mbstr. + * @param charset The pointer to the string specifying the encoding of + * the multi-byte characters. + * @retval size_t The number of UCS-2 characters written to \a ucs2str + * buffer if the conversion is successful. If \a ucs_size + * is zero, the return value is the required size, in + * number of UCS-2 characters, for a buffer to receive the + * converted string. This function returns zero if an error + * occurred. + * @note + * \a charset is ignored on Win32 environments. + */ +UCS2API size_t mbstoucs2_charset(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size, const char *charset); + +/** + * Convert a UCS-2 string to multi-byte characters. + * + * @param mbstr The pointer to the buffer for receiving UTF-8 string + * converted from the UCS-2 string. If \a mbs_size is + * zero, this argument is not be used. + * @param mbs_size The size, in bytes, of the buffer pointed to by the + * \a mbstr argument. If this value is zero, the function + * returns the number of bytes required for the buffer. + * @param ucs2str The pointer to the UCS-2 string to be converted. + * @param ucs_size The size, in number of UCS-2 characters, of the UCS-2 + * string, \a ucs2str. + * @retval size_t The number of bytes written to \a mbstr buffer if + * the conversion is successful. If \a mbs_size is zero, + * the return value is the required size, in bytes, for a + * buffer to receive the converted string. This function + * returns zero if an error occurred. + */ +UCS2API size_t ucs2toutf8(char *mbstr, size_t mbs_size, const ucs2char_t *ucs2str, size_t ucs_size); + +/** + * Convert a UTF-8 string to a UCS-2 string. + * + * @param ucs2str The pointer to the buffer for receiving UCS-2 string + * converted from the UTF-8 string. If \a ucs_size is + * zero, this argument is not be used. + * @param ucs_size The size, in number of UCS-2 characters, of the buffer + * pointed to by the \a ucs2str argument. If this value is + * zero, the function returns the number of UCS-2 + * characters required for the buffer. + * @param mbstr The pointer to the UTF-8 string to be converted. + * @param mbs_size The size, in bytes, of the UTF-8 string, \a mbstr. + * @retval size_t The number of UCS-2 characters written to \a ucs2str + * buffer if the conversion is successful. If \a ucs_size + * is zero, the return value is the required size, in + * number of UCS-2 characters, for a buffer to receive the + * converted string. This function returns zero if an error + * occurred. + */ +UCS2API size_t utf8toucs2(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size); + +/** + * Convert and duplicate a UCS-2 string to multi-byte characters. + * + * @param ucs2str The pointer to a UCS-2 string. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API char *ucs2dupmbs(const ucs2char_t *ucs2str); + +/** + * Convert and duplicate multi-byte characters to a UCS-2 string. + * + * @param mbstr The pointer to multi-byte characters. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* mbsdupucs2(const char *mbstr); + +/** + * Convert and duplicate multi-byte characters in a specific encoding + * to a UCS-2 string. + * + * @param mbstr The pointer to multi-byte characters. + * @param charset The pointer to the string specifying the encoding of + * the multi-byte characters. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* mbsdupucs2_charset(const char *mbstr, const char *charset); + +/** + * Convert and duplicate a UCS-2 string to a UTF-8 string. + * + * @param ucs2str The pointer to a UCS-2 string. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API char *ucs2duputf8(const ucs2char_t *ucs2str); + +/** + * Convert and duplicate a UTF-8 string to a UCS-2 string. + * + * @param mbstr The pointer to multi-byte characters. + * @retval char* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* utf8dupucs2(const char *utf8str); + +/** + * @} + */ + + + +/** + * @defgroup ucs2_memory Memory manager routines + * @{ + */ + +/** + * Allocate a memory block. + * + * @param size The size, in bytes, of the memory block. + * @retval void* The pointer to the allocated memory block. + */ +UCS2API void *ucs2malloc(size_t size); + +/** + * Allocate a memory block with values initialized as zero. + * + * @param size The size, in bytes, of the memory block. + * @retval void* The pointer to the allocated memory block. + */ +UCS2API void *ucs2calloc(size_t size); + +/** + * Resize a memory block. + * + * @param ptr The pointer to the memory block to be resized. + * @param size The size, in bytes, of the new memory block. + * @retval void* The pointer to the new memory block. + */ +UCS2API void *ucs2realloc(void *ptr, size_t size); + +/** + * Free a memory block. + * + * @param ptr The pointer to the memory block to be freed. + */ +UCS2API void ucs2free(void* ptr); + +/** + * @} + */ + +/** + * @defgroup ucs2_char UCS-2 character routines + * @{ + */ + +/** + * Test whether a USC-2 character is a surrogate-pair character in UTF-16. + * @param c The UCS-2 character to be tested. + * @retval int Non-zero value if the test is true, zero otherwise. + */ +UCS2API int ucs2issurrogate(ucs2char_t c); + +/** + * Test whether a USC-2 character is a whitespace character. + * @param c The UCS-2 character to be tested. + * @retval int Non-zero value if the test is true, zero otherwise. + */ +UCS2API int ucs2isspace(ucs2char_t c); + +/** + * Test whether a USC-2 character is a numeric character. + * @param c The UCS-2 character to be tested. + * @retval int Non-zero value if the test is true, zero otherwise. + */ +UCS2API int ucs2isdigit(ucs2char_t c); + +/** + * Convert a UCS-2 character to lower case. + * @param c The UCS-2 character to be coverted. + * @retval ucs2char_t The resultant UCS-2 character. + */ +UCS2API ucs2char_t ucs2lower(ucs2char_t c); + +/** + * Convert a UCS-2 character to upper case. + * @param c The UCS-2 character to be coverted. + * @retval ucs2char_t The resultant UCS-2 character. + */ +UCS2API ucs2char_t ucs2upper(ucs2char_t c); + +/** + * @} + */ + + + + + +/** + * @defgroup ucs2_string_ansi ANSI C compatible string routines + * @{ + * + * This is the subset of the UCS-2 Character/String API that corresponds + * to string manupulation routines in the ANSI C standard. The following + * ANSI C functions are not defined in this subset: + * strcoll, strerror, strtok, strxfrm. + */ + +/** + * Concatenate two strings. + * + * @param dst The pointer to the destination of a string. + * @param src The pointer to the source of a string. + * @retval ucs2char_t* The pointer to the destination string. + */ +UCS2API ucs2char_t* ucs2cat(ucs2char_t* dst, const ucs2char_t* src); + +/** + * Search for the first occurrence of a character in a string. + * + * @param str The pointer to the string in which \a c is searched. + * @param c The target character. + * @retval ucs2char_t* The pointer to the character \a c in \a str, or \c NULL + * if \a c does not occur in \a str. + */ +UCS2API ucs2char_t* ucs2chr(const ucs2char_t* str, ucs2char_t c); + +/** + * Compare two strings. + * + * @param x The pointer to a string. + * @param y The pointer to another string. + * @retval int A positive value if \a x is greater than \a y; + * a negative value if \a x is smaller than \a y; + * zero if \a x is identical to \a y. + */ +UCS2API int ucs2cmp(const ucs2char_t* x, const ucs2char_t* y); + +/** + * Copy a string. + * + * @param dst The pointer to the destination of a string. + * @param src The pointer to the source of a string. + * @retval ucs2char_t* The pointer to the destination string. + */ +UCS2API ucs2char_t* ucs2cpy(ucs2char_t* dst, const ucs2char_t* src); + +/** + * Count the number of characters not appearing in a character set. + * + * @param str The pointer to a string. + * @param charset The pointer to a character set. + * @retval size_t The number of characters from the beginning of \a str + * in which any character in \a charset appear for the + * first time, or the length of \a str if such a character + * does not exist. + */ +UCS2API size_t ucs2cspn(const ucs2char_t *str, const ucs2char_t *charset); + +/** + * Count the length of a string. + * + * @param str The pointer to a string. + * @retval size_t The number of characters in \a str. + */ +UCS2API size_t ucs2len(const ucs2char_t* str); + +/** + * Concatenate two strings (no more than the maximum length). + * + * @param dst The pointer to the destination of a string. + * @param src The pointer to the source of a string. + * @param n The number of characters to be concatenated. + * @retval ucs2char_t* The pointer to the destination string. + */ +UCS2API ucs2char_t* ucs2ncat(ucs2char_t *dst, const ucs2char_t *src, size_t n); + +/** + * Compare two strings (no longer than the maximum length). + * + * @param x The pointer to a string. + * @param y The pointer to another string. + * @param n The number of characters to be compared. + * @retval int A positive value if \a x is greater than \a y; + * a negative value if \a x is smaller than \a y; + * zero if \a x is identical to \a y. + */ +UCS2API int ucs2ncmp(const ucs2char_t* x, const ucs2char_t* y, size_t n); + +/** + * Copy a string (no more than the maximum length). + * + * @param dst The pointer to the destination of a string. + * @param src The pointer to the source of a string. + * @param n The number of characters to be copied. + * @retval ucs2char_t* The pointer to the destination string. + */ +UCS2API ucs2char_t* ucs2ncpy(ucs2char_t* dst, const ucs2char_t* src, size_t n); + +/** + * Find a character in a string that belongs to a character set. + * + * @param str The pointer to the string where \a charset is searched. + * @param charset The pointer to a character set. + * @retval ucs2char_t* The pointer to the character in \a str that belongs + * to \a charset, or \c NULL if such a character does not + * exist. + */ +UCS2API ucs2char_t* ucs2pbrk(const ucs2char_t *str, const ucs2char_t *charset); + +/** + * Search for the last occurrence of a character in a string. + * + * @param str The pointer to the string in which \a c is searched. + * @param c The target character. + * @retval ucs2char_t* The pointer to the character \a c in \a str, or \c NULL + * if \a c does not occur in \a str. + */ +UCS2API ucs2char_t* ucs2rchr(const ucs2char_t* string, ucs2char_t c); + +/** + * Find a character in a string that does not belong to a character set. + * + * @param str The pointer to the string where \a charset is searched. + * @param charset The pointer to a character set. + * @retval ucs2char_t* The pointer to the character in \a str that does not + * belong to \a charset, or \c NULL if such a character + * does not exist. + */ +UCS2API size_t ucs2spn(const ucs2char_t *str, const ucs2char_t *charset); + +/** + * Find a substring in a string. + * + * @param str The pointer to the string where \a substr is searched. + * @param substr The pointer to the substring. + * @retval ucs2char_t* The pointer to the character where \a substr begins + * in \a str for the first time, or \c NULL if \a str + * does not contain \a substr. + */ +UCS2API ucs2char_t* ucs2str(const ucs2char_t* str, const ucs2char_t* substr); + +/** + * @} + */ + + + + + +/** + * @defgroup ucs2_string_non_ansi Miscellaneous string routines + * @{ + */ + +/** + * Duplicate a string. + * + * @param str The pointer to a string. + * @retval ucs2char_t* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* ucs2dup(const ucs2char_t* str); + +/** + * Duplicate a string no longer than the specified length. + * + * @param str The pointer to a string. + * @param length The maximum length of the duplicated string. + * @retval ucs2char_t* The pointer to the duplicated string. Call ucs2free() + * to free the memory block allocated by this function. + */ +UCS2API ucs2char_t* ucs2ndup(const ucs2char_t* src, size_t length); + +/** + * Convert a string to lowercase. + * + * Given \a str argument, this function converts uppercase letters in the + * string to lowercase and overwrites the resultant string on the same buffer + * pointed by the \a str argument. + * + * @param str The pointer to a string. + * @retval ucs2char_t* The pointer to the string, which is the same value as + * \a str. + */ +UCS2API ucs2char_t* ucs2lwr(ucs2char_t* str); + +/** + * Convert a string to uppercase. + * + * Given \a str argument, this function converts lowercase letters in the + * string to uppercase and overwrites the resultant string on the same buffer + * pointed by the \a str argument. + * + * @param str The pointer to a string. + * @retval ucs2char_t* The pointer to the string, which is the same value as + * \a str. + */ +UCS2API ucs2char_t* ucs2upr(ucs2char_t* str); + +/** + * Compare two strings incasesensitively. + * + * @param x The pointer to a string. + * @param y The pointer to another string. + * @retval int A positive value if \a x is greater than \a y; + * a negative value if \a x is smaller than \a y; + * zero if \a x is identical to \a y. + */ +UCS2API int ucs2icmp(const ucs2char_t* x, const ucs2char_t* y); + +/** + * Compare two strings incasesensitively (no longer than the maximum length). + * + * @param x The pointer to a string. + * @param y The pointer to another string. + * @param n The number of characters to be compared. + * @retval int A positive value if \a x is greater than \a y; + * a negative value if \a x is smaller than \a y; + * zero if \a x is identical to \a y. + */ +UCS2API int ucs2incmp(const ucs2char_t* x, const ucs2char_t* y, size_t n); + +/** + * Strip whitespace characters at the head and tail of a string. + * + * Given \a str argument, this function trims whilespace characters at the + * head and tail of the string and overwrites the resultant string on the + * same buffer pointed by the \a str argument. + * + * @param str The pointer to a string. + * @retval ucs2char_t* The pointer to the string, which is the same value as + * \a str. + */ +UCS2API ucs2char_t* ucs2strip(ucs2char_t* str); + +/** + * @} + */ + + + +/** + * @defgroup ucs2_std Wrapper for stdio/stdlib routines + * @{ + */ + +/** + * Convert a UCS-2 string to integer value. + * @param str The pointer to a string. + * @retval int The corresponding integer value. + */ +UCS2API int ucs2toi(const ucs2char_t* str); + +/** + * Convert an integer value to UCS-2 string. + * @param value The integer value. + * @param string The pointer to the buffer to receive the string. + * @param radix Radix of the \a value. + * @retval ucs2char_t* The pointer to the string, which is the same value as + * \a str. + */ +UCS2API ucs2char_t* itoucs2(int value, ucs2char_t *string, int radix); + +/** + * Open a stream from a file. + * @param filename The pointer to the UCS-2 string for the file name. + * @param mode The pointer to the C string for the open mode. + * @retval FILE* The pointer to the opened stream if successful, + * NULL otherwise. + */ +UCS2API FILE *ucs2fopen(const ucs2char_t *filename, const char *mode); + +/** + * Write a UCS-2 character to a stream. + * @param c The character to be written. + * @param fp The pointer to the output stream. + * @retval int Zero if successful, non-zero otherwise. + */ +UCS2API int fputucs2c(ucs2char_t c, FILE *fp); + + + +/** @} */ + +/** @} */ + +#ifdef __cplusplus +} +#endif/*__cplusplus*/ + +#endif/*__UCS2CHAR_H__*/ Deleted: trunk/pmplib/include/ucs2char.h =================================================================== --- trunk/pmplib/include/ucs2char.h 2007-02-09 01:55:12 UTC (rev 314) +++ trunk/pmplib/include/ucs2char.h 2007-02-09 01:55:34 UTC (rev 315) @@ -1,682 +0,0 @@ -/* - * UCS-2 character set library. - * - * Copyright (c) 2005-2006 Nyaochi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/* $Id$ */ - -#ifndef __UCS2CHAR_H__ -#define __UCS2CHAR_H__ - -#include <stdio.h> - -#ifdef UCS2_EXPORTS -#define UCS2API __declspec(dllexport) -#else -#define UCS2API -#endif - -#ifdef __cplusplus -extern "C" { -#endif/*__cplusplus*/ - -/** - * \addtogroup ucs2 UCS-2 Character/String API - * @{ - * - * The PMPlib UCS-2 character/string API provides a manupulation utility - * for characters/strings in UCS-2 encoding. As a number of portable media - * players support Unicode for displaying song information, PMPlib deals - * with Unicode characters/strings encoded in UCS-2. - * - * The byte order of UCS-2 character is dependent on the CPU architecture - * on which this code runs: e.g., little-endian on Intel IA-32/IA-64 and - * big-endian on IBM PowerPC. - */ - -/** - * Type definition of a UCS-2 character. - */ -typedef uint16_t ucs2char_t; - -/** - * Initialize the UCS-2 library. - * - * This function initializes internal variables used in the UCS-2 library. - * Call this function before using any other functions in this API. - * - * @retval int Zero if succeeded, otherwise non-zero value. - */ -UCS2API int ucs2init(); - - -/** - * @defgroup ucs2_conv Character encoding converter - * @{ - * - * This API subset converts the character encoding of a string from one to - * another. It supports mutual conversions between: - * UCS-2 and multi-byte character (i.e., \c char); - * UCS-2 and UTF-8. - * - * By default, this library detects the character encoding of multi-byte - * characters on the current system based on the value of LANG variable - * (for POSIX) or via GetACP() function (for Win32). - */ - -/** - * Set the encoding for multi-byte characters (for iconv/libiconv). - * - * This function change the default encoding for multi-byte characters to the - * character encoding specified by the \a encoding argument. - * - * @param encoding The pointer to the string specifying the character - * encoding. - * - * @note - * This function is effective only on environments with iconv (libiconv). - */ -UCS2API int ucs2setenc(const char *encoding); - -/** - * Get the encoding for multi-byte characters (for iconv/libiconv). - * - * This function returns the default encoding for multi-byte characters used - * in the UCS-2 API. - * - * @retval const char* The pointer to the string of the character encoding. - * - * @note - * This function is effective only on environments with iconv (libiconv). - */ -UCS2API const char *ucs2getenc(); - -/** - * Set the code page for multi-byte characters (for Win32). - * - * This function change the default encoding for multi-byte characters to the - * code page specified by the \a cp argument. - * - * @param cp The code page. - * - * @note - * This function is effective only on Win32 environments. - */ -UCS2API void ucs2setcp(int cp); - -/** - * Get the code page for multi-byte characters (for Win32). - * - * This function returns the default code page for multi-byte characters. - * - * @param cp The code page. - * - * @note - * This function is effective only on Win32 environments. - */ -UCS2API int ucs2getcp(); - -/** - * Convert a UCS-2 string to multi-byte characters. - * - * @param mbstr The pointer to the buffer for receiving multi-byte - * characters converted from the UCS-2 string. If - * \a mbs_size is zero, this argument is not be used. - * @param mbs_size The size, in bytes, of the buffer pointed to by the - * \a mbstr argument. If this value is zero, the function - * returns the number of bytes required for the buffer. - * @param ucs2str The pointer to the UCS-2 string to be converted. - * @param ucs_size The size, in number of UCS-2 characters, of the UCS-2 - * string, \a ucs2str. - * @retval size_t The number of bytes written to \a mbstr buffer if - * the conversion is successful. If \a mbs_size is zero, - * the return value is the required size, in bytes, for a - * buffer to receive the converted string. This function - * returns zero if an error occurred. - */ -UCS2API size_t ucs2tombs(char *mbstr, size_t mbs_size, const ucs2char_t *ucs2str, size_t ucs_size); - -/** - * Convert multi-byte characters to a UCS-2 string. - * - * @param ucs2str The pointer to the buffer for receiving UCS-2 string - * converted from the multi-byte characters. If - * \a ucs_size is zero, this argument is not be used. - * @param ucs_size The size, in number of UCS-2 characters, of the buffer - * pointed to by the \a ucs2str argument. If this value is - * zero, the function returns the number of UCS-2 - * characters required for the buffer. - * @param mbstr The pointer to the multi-byte characters to be - * converted. - * @param mbs_size The size, in bytes, of the multi-byte characters, - * \a mbstr. - * @retval size_t The number of UCS-2 characters written to \a ucs2str - * buffer if the conversion is successful. If \a ucs_size - * is zero, the return value is the required size, in - * number of UCS-2 characters, for a buffer to receive the - * converted string. This function returns zero if an error - * occurred. - */ -UCS2API size_t mbstoucs2(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size); - -/** - * Convert multi-byte characters in a specific encoding to a UCS-2 string. - * - * @param ucs2str The pointer to the buffer for receiving UCS-2 string - * converted from the multi-byte characters. If - * \a ucs_size is zero, this argument is not be used. - * @param ucs_size The size, in number of UCS-2 characters, of the buffer - * pointed to by the \a ucs2str argument. If this value is - * zero, the function returns the number of UCS-2 - * characters required for the buffer. - * @param mbstr The pointer to the multi-byte characters to be - * converted. - * @param mbs_size The size, in bytes, of the multi-byte characters, - * \a mbstr. - * @param charset The pointer to the string specifying the encoding of - * the multi-byte characters. - * @retval size_t The number of UCS-2 characters written to \a ucs2str - * buffer if the conversion is successful. If \a ucs_size - * is zero, the return value is the required size, in - * number of UCS-2 characters, for a buffer to receive the - * converted string. This function returns zero if an error - * occurred. - * @note - * \a charset is ignored on Win32 environments. - */ -UCS2API size_t mbstoucs2_charset(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size, const char *charset); - -/** - * Convert a UCS-2 string to multi-byte characters. - * - * @param mbstr The pointer to the buffer for receiving UTF-8 string - * converted from the UCS-2 string. If \a mbs_size is - * zero, this argument is not be used. - * @param mbs_size The size, in bytes, of the buffer pointed to by the - * \a mbstr argument. If this value is zero, the function - * returns the number of bytes required for the buffer. - * @param ucs2str The pointer to the UCS-2 string to be converted. - * @param ucs_size The size, in number of UCS-2 characters, of the UCS-2 - * string, \a ucs2str. - * @retval size_t The number of bytes written to \a mbstr buffer if - * the conversion is successful. If \a mbs_size is zero, - * the return value is the required size, in bytes, for a - * buffer to receive the converted string. This function - * returns zero if an error occurred. - */ -UCS2API size_t ucs2toutf8(char *mbstr, size_t mbs_size, const ucs2char_t *ucs2str, size_t ucs_size); - -/** - * Convert a UTF-8 string to a UCS-2 string. - * - * @param ucs2str The pointer to the buffer for receiving UCS-2 string - * converted from the UTF-8 string. If \a ucs_size is - * zero, this argument is not be used. - * @param ucs_size The size, in number of UCS-2 characters, of the buffer - * pointed to by the \a ucs2str argument. If this value is - * zero, the function returns the number of UCS-2 - * characters required for the buffer. - * @param mbstr The pointer to the UTF-8 string to be converted. - * @param mbs_size The size, in bytes, of the UTF-8 string, \a mbstr. - * @retval size_t The number of UCS-2 characters written to \a ucs2str - * buffer if the conversion is successful. If \a ucs_size - * is zero, the return value is the required size, in - * number of UCS-2 characters, for a buffer to receive the - * converted string. This function returns zero if an error - * occurred. - */ -UCS2API size_t utf8toucs2(ucs2char_t *ucs2str, size_t ucs_size, const char *mbstr, size_t mbs_size); - -/** - * Convert and duplicate a UCS-2 string to multi-byte characters. - * - * @param ucs2str The pointer to a UCS-2 string. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API char *ucs2dupmbs(const ucs2char_t *ucs2str); - -/** - * Convert and duplicate multi-byte characters to a UCS-2 string. - * - * @param mbstr The pointer to multi-byte characters. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* mbsdupucs2(const char *mbstr); - -/** - * Convert and duplicate multi-byte characters in a specific encoding - * to a UCS-2 string. - * - * @param mbstr The pointer to multi-byte characters. - * @param charset The pointer to the string specifying the encoding of - * the multi-byte characters. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* mbsdupucs2_charset(const char *mbstr, const char *charset); - -/** - * Convert and duplicate a UCS-2 string to a UTF-8 string. - * - * @param ucs2str The pointer to a UCS-2 string. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API char *ucs2duputf8(const ucs2char_t *ucs2str); - -/** - * Convert and duplicate a UTF-8 string to a UCS-2 string. - * - * @param mbstr The pointer to multi-byte characters. - * @retval char* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* utf8dupucs2(const char *utf8str); - -/** - * @} - */ - - - -/** - * @defgroup ucs2_memory Memory manager routines - * @{ - */ - -/** - * Allocate a memory block. - * - * @param size The size, in bytes, of the memory block. - * @retval void* The pointer to the allocated memory block. - */ -UCS2API void *ucs2malloc(size_t size); - -/** - * Allocate a memory block with values initialized as zero. - * - * @param size The size, in bytes, of the memory block. - * @retval void* The pointer to the allocated memory block. - */ -UCS2API void *ucs2calloc(size_t size); - -/** - * Resize a memory block. - * - * @param ptr The pointer to the memory block to be resized. - * @param size The size, in bytes, of the new memory block. - * @retval void* The pointer to the new memory block. - */ -UCS2API void *ucs2realloc(void *ptr, size_t size); - -/** - * Free a memory block. - * - * @param ptr The pointer to the memory block to be freed. - */ -UCS2API void ucs2free(void* ptr); - -/** - * @} - */ - -/** - * @defgroup ucs2_char UCS-2 character routines - * @{ - */ - -/** - * Test whether a USC-2 character is a surrogate-pair character in UTF-16. - * @param c The UCS-2 character to be tested. - * @retval int Non-zero value if the test is true, zero otherwise. - */ -UCS2API int ucs2issurrogate(ucs2char_t c); - -/** - * Test whether a USC-2 character is a whitespace character. - * @param c The UCS-2 character to be tested. - * @retval int Non-zero value if the test is true, zero otherwise. - */ -UCS2API int ucs2isspace(ucs2char_t c); - -/** - * Test whether a USC-2 character is a numeric character. - * @param c The UCS-2 character to be tested. - * @retval int Non-zero value if the test is true, zero otherwise. - */ -UCS2API int ucs2isdigit(ucs2char_t c); - -/** - * Convert a UCS-2 character to lower case. - * @param c The UCS-2 character to be coverted. - * @retval ucs2char_t The resultant UCS-2 character. - */ -UCS2API ucs2char_t ucs2lower(ucs2char_t c); - -/** - * Convert a UCS-2 character to upper case. - * @param c The UCS-2 character to be coverted. - * @retval ucs2char_t The resultant UCS-2 character. - */ -UCS2API ucs2char_t ucs2upper(ucs2char_t c); - -/** - * @} - */ - - - - - -/** - * @defgroup ucs2_string_ansi ANSI C compatible string routines - * @{ - * - * This is the subset of the UCS-2 Character/String API that corresponds - * to string manupulation routines in the ANSI C standard. The following - * ANSI C functions are not defined in this subset: - * strcoll, strerror, strtok, strxfrm. - */ - -/** - * Concatenate two strings. - * - * @param dst The pointer to the destination of a string. - * @param src The pointer to the source of a string. - * @retval ucs2char_t* The pointer to the destination string. - */ -UCS2API ucs2char_t* ucs2cat(ucs2char_t* dst, const ucs2char_t* src); - -/** - * Search for the first occurrence of a character in a string. - * - * @param str The pointer to the string in which \a c is searched. - * @param c The target character. - * @retval ucs2char_t* The pointer to the character \a c in \a str, or \c NULL - * if \a c does not occur in \a str. - */ -UCS2API ucs2char_t* ucs2chr(const ucs2char_t* str, ucs2char_t c); - -/** - * Compare two strings. - * - * @param x The pointer to a string. - * @param y The pointer to another string. - * @retval int A positive value if \a x is greater than \a y; - * a negative value if \a x is smaller than \a y; - * zero if \a x is identical to \a y. - */ -UCS2API int ucs2cmp(const ucs2char_t* x, const ucs2char_t* y); - -/** - * Copy a string. - * - * @param dst The pointer to the destination of a string. - * @param src The pointer to the source of a string. - * @retval ucs2char_t* The pointer to the destination string. - */ -UCS2API ucs2char_t* ucs2cpy(ucs2char_t* dst, const ucs2char_t* src); - -/** - * Count the number of characters not appearing in a character set. - * - * @param str The pointer to a string. - * @param charset The pointer to a character set. - * @retval size_t The number of characters from the beginning of \a str - * in which any character in \a charset appear for the - * first time, or the length of \a str if such a character - * does not exist. - */ -UCS2API size_t ucs2cspn(const ucs2char_t *str, const ucs2char_t *charset); - -/** - * Count the length of a string. - * - * @param str The pointer to a string. - * @retval size_t The number of characters in \a str. - */ -UCS2API size_t ucs2len(const ucs2char_t* str); - -/** - * Concatenate two strings (no more than the maximum length). - * - * @param dst The pointer to the destination of a string. - * @param src The pointer to the source of a string. - * @param n The number of characters to be concatenated. - * @retval ucs2char_t* The pointer to the destination string. - */ -UCS2API ucs2char_t* ucs2ncat(ucs2char_t *dst, const ucs2char_t *src, size_t n); - -/** - * Compare two strings (no longer than the maximum length). - * - * @param x The pointer to a string. - * @param y The pointer to another string. - * @param n The number of characters to be compared. - * @retval int A positive value if \a x is greater than \a y; - * a negative value if \a x is smaller than \a y; - * zero if \a x is identical to \a y. - */ -UCS2API int ucs2ncmp(const ucs2char_t* x, const ucs2char_t* y, size_t n); - -/** - * Copy a string (no more than the maximum length). - * - * @param dst The pointer to the destination of a string. - * @param src The pointer to the source of a string. - * @param n The number of characters to be copied. - * @retval ucs2char_t* The pointer to the destination string. - */ -UCS2API ucs2char_t* ucs2ncpy(ucs2char_t* dst, const ucs2char_t* src, size_t n); - -/** - * Find a character in a string that belongs to a character set. - * - * @param str The pointer to the string where \a charset is searched. - * @param charset The pointer to a character set. - * @retval ucs2char_t* The pointer to the character in \a str that belongs - * to \a charset, or \c NULL if such a character does not - * exist. - */ -UCS2API ucs2char_t* ucs2pbrk(const ucs2char_t *str, const ucs2char_t *charset); - -/** - * Search for the last occurrence of a character in a string. - * - * @param str The pointer to the string in which \a c is searched. - * @param c The target character. - * @retval ucs2char_t* The pointer to the character \a c in \a str, or \c NULL - * if \a c does not occur in \a str. - */ -UCS2API ucs2char_t* ucs2rchr(const ucs2char_t* string, ucs2char_t c); - -/** - * Find a character in a string that does not belong to a character set. - * - * @param str The pointer to the string where \a charset is searched. - * @param charset The pointer to a character set. - * @retval ucs2char_t* The pointer to the character in \a str that does not - * belong to \a charset, or \c NULL if such a character - * does not exist. - */ -UCS2API size_t ucs2spn(const ucs2char_t *str, const ucs2char_t *charset); - -/** - * Find a substring in a string. - * - * @param str The pointer to the string where \a substr is searched. - * @param substr The pointer to the substring. - * @retval ucs2char_t* The pointer to the character where \a substr begins - * in \a str for the first time, or \c NULL if \a str - * does not contain \a substr. - */ -UCS2API ucs2char_t* ucs2str(const ucs2char_t* str, const ucs2char_t* substr); - -/** - * @} - */ - - - - - -/** - * @defgroup ucs2_string_non_ansi Miscellaneous string routines - * @{ - */ - -/** - * Duplicate a string. - * - * @param str The pointer to a string. - * @retval ucs2char_t* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* ucs2dup(const ucs2char_t* str); - -/** - * Duplicate a string no longer than the specified length. - * - * @param str The pointer to a string. - * @param length The maximum length of the duplicated string. - * @retval ucs2char_t* The pointer to the duplicated string. Call ucs2free() - * to free the memory block allocated by this function. - */ -UCS2API ucs2char_t* ucs2ndup(const ucs2char_t* src, size_t length); - -/** - * Convert a string to lowercase. - * - * Given \a str argument, this function converts uppercase letters in the - * string to lowercase and overwrites the resultant string on the same buffer - * pointed by the \a str argument. - * - * @param str The pointer to a string. - * @retval ucs2char_t* The pointer to the string, which is the same value as - * \a str. - */ -UCS2API ucs2char_t* ucs2lwr(ucs2char_t* str); - -/** - * Convert a string to uppercase. - * - * Given \a str argument, this function converts lowercase letters in the - * string to uppercase and overwrites the resultant string on the same buffer - * pointed by the \a str argument. - * - * @param str The pointer to a string. - * @retval ucs2char_t* The pointer to the string, which is the same value as - * \a str. - */ -UCS2API ucs2char_t* ucs2upr(ucs2char_t* str); - -/** - * Compare two strings incasesensitively. - * - * @param x The pointer to a string. - * @param y The pointer to another string. - * @retval int A positive value if \a x is greater than \a y; - * a negative value if \a x is smaller than \a y; - * zero if \a x is identical to \a y. - */ -UCS2API int ucs2icmp(const ucs2char_t* x, const ucs2char_t* y); - -/** - * Compare two strings incasesensitively (no longer than the maximum length). - * - * @param x The pointer to a string. - * @param y The pointer to another string. - * @param n The number of characters to be compared. - * @retval int A positive value if \a x is greater than \a y; - * a negative value if \a x is smaller than \a y; - * zero if \a x is identical to \a y. - */ -UCS2API int ucs2incmp(const ucs2char_t* x, const ucs2char_t* y, size_t n); - -/** - * Strip whitespace characters at the head and tail of a string. - * - * Given \a str argument, this function trims whilespace characters at the - * head and tail of the string and overwrites the resultant string on the - * same buffer pointed by the \a str argument. - * - * @param str The pointer to a string. - * @retval ucs2char_t* The pointer to the string, which is the same value as - * \a str. - */ -UCS2API ucs2char_t* ucs2strip(ucs2char_t* str); - -/** - * @} - */ - - - -/** - * @defgroup ucs2_std Wrapper for stdio/stdlib routines - * @{ - */ - -/** - * Convert a UCS-2 string to integer value. - * @param str The pointer to a string. - * @retval int The corresponding integer value. - */ -UCS2API int ucs2toi(const ucs2char_t* str); - -/** - * Convert an integer value to UCS-2 string. - * @param value The integer value. - * @param string The pointer to the buffer to receive the string. - * @param radix Radix of the \a value. - * @retval ucs2char_t* The pointer to the string, which is the same value as - * \a str. - */ -UCS2API ucs2char_t* itoucs2(int value, ucs2char_t *string, int radix); - -/** - * Open a stream from a file. - * @param filename The pointer to the UCS-2 string for the file name. - * @param mode The pointer to the C string for the open mode. - * @retval FILE* The pointer to the opened stream if successful, - * NULL otherwise. - */ -UCS2API FILE *ucs2fopen(const ucs2char_t *filename, const char *mode); - -/** - * Write a UCS-2 character to a stream. - * @param c The character to be written. - * @param fp The pointer to the output stream. - * @retval int Zero if successful, non-zero otherwise. - */ -UCS2API int fputucs2c(ucs2char_t c, FILE *fp); - - - -/** @} */ - -/** @} */ - -#ifdef __cplusplus -} -#endif/*__cplusplus*/ - -#endif/*__UCS2CHAR_H__*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |