Max 5 API Reference
00001 /* 00002 * charset.h 00003 * 00004 * Created by Jeremy Bernstein on 24.05.06. 00005 * Copyright 2006 Cycling '74. All rights reserved. 00006 * 00007 */ 00008 00009 #ifndef __CHARSET_H__ 00010 #define __CHARSET_H__ 00011 00012 #ifdef __cplusplus 00013 extern "C" { 00014 #endif 00015 00016 #if C74_PRAGMA_STRUCT_PACKPUSH 00017 #pragma pack(push, 2) 00018 #elif C74_PRAGMA_STRUCT_PACK 00019 #pragma pack(2) 00020 #endif 00021 00022 00023 /** The charset_converter object. This struct is provided for debugging convenience, 00024 but should be considered opaque and is subject to change without notice. 00025 00026 @ingroup unicode 00027 */ 00028 typedef struct _charset_converter 00029 { 00030 t_object ob; 00031 void *conv; 00032 void *src_encoding; 00033 void *dst_encoding; 00034 } t_charset_converter; 00035 00036 00037 // private 00038 t_max_err charset_init(void); 00039 00040 00041 /** A convenience function that simplifies usage by wrapping the other charset functions. 00042 @ingroup unicode 00043 00044 @param src_encoding The name encoding of the input. 00045 @param in The input string. 00046 @param inbytes The number of bytes in the input string. 00047 @param dest_encoding The name of the encoding to use for the output. 00048 @param out The address of a char*, which will be allocated and filled with the string in the new encoding. 00049 @param outbytes The address of a value that will hold the number of bytes long the output is upon return. 00050 @return A Max error code. 00051 @remark Remember to call sysmem_freeptr(*out) to free any allocated memory. 00052 */ 00053 t_max_err charset_convert(t_symbol *src_encoding, const char *in, long inbytes, t_symbol *dest_encoding, char **out, long *outbytes); 00054 00055 00056 /** Convert a UTF8 C-String into a 16-bit-wide-character array. 00057 @ingroup unicode 00058 @param s The string to be converted to unicode. 00059 @param outlen The address of a variable to hold the size of the number of chars 00060 but does not include the NULL terminator in the count. 00061 @return A pointer to the buffer of unicode (wide) characters. 00062 */ 00063 unsigned short *charset_utf8tounicode(char *s, long *outlen); 00064 00065 00066 /** Convert a 16-bit-wide-character array into a UTF C-string. 00067 Accepts either null termination, or not (len is zero in the latter case). 00068 @ingroup unicode 00069 @param s An array of wide (16-bit) unicode characters. 00070 @param len The length of s. 00071 @param outlen The address of a variable to hold the size of the number of chars 00072 but does not include the NULL terminator in the count. 00073 @return A UTF8-encoded C-string. 00074 00075 */ 00076 char *charset_unicodetoutf8(unsigned short *s, long len, long *outlen); 00077 00078 00079 /** Returns utf8 character count, and optionally bytecount. 00080 @ingroup unicode 00081 @param utf8 The UTF-8 encoded string whose characters are to be counted. 00082 @param bytecount The address of a variable to hold the byte count on return. 00083 Pass NULL if you don't require the byte count. 00084 @return The number of characters in the UTF8 string. 00085 */ 00086 long charset_utf8_count(char *utf8, long *bytecount); 00087 00088 00089 /** Returns utf8 character offset (positive or negative), and optionally byte offset. 00090 @ingroup unicode 00091 @param utf8 A UTF-8 encoded string. 00092 @param charoffset The char offset into the string at which to find the byte offset. 00093 @param byteoffset The address of a variable to hold the byte offset on return. 00094 Pass NULL if you don't require the byte offset. 00095 @return The character offset. 00096 */ 00097 char *charset_utf8_offset(char *utf8, long charoffset, long *byteoffset); 00098 00099 00100 #if C74_PRAGMA_STRUCT_PACKPUSH 00101 #pragma pack(pop) 00102 #elif C74_PRAGMA_STRUCT_PACK 00103 #pragma pack() 00104 #endif 00105 00106 #ifdef __cplusplus 00107 } 00108 #endif 00109 00110 #endif // __CHARSET_H__
Copyright © 2008, Cycling '74