github.com/256dpi/max-go@v0.7.0/lib/max/ext_charset.h (about) 1 /* 2 * charset.h 3 * 4 * Created by Jeremy Bernstein on 24.05.06. 5 * Copyright 2006 Cycling '74. All rights reserved. 6 * 7 */ 8 9 #ifndef _EXT_CHARSET_H_ 10 #define _EXT_CHARSET_H_ 11 12 #include "ext_prefix.h" 13 #include "ext_mess.h" 14 15 BEGIN_USING_C_LINKAGE 16 17 #if C74_PRAGMA_STRUCT_PACKPUSH 18 #pragma pack(push, 2) 19 #elif C74_PRAGMA_STRUCT_PACK 20 #pragma pack(2) 21 #endif 22 23 24 /** The charset_converter object. This struct is provided for debugging convenience, 25 but should be considered opaque and is subject to change without notice. 26 27 @ingroup unicode 28 */ 29 typedef struct _charset_converter 30 { 31 t_object ob; 32 void *conv; 33 void *src_encoding; 34 void *dst_encoding; 35 } t_charset_converter; 36 37 38 /** A convenience function that simplifies usage by wrapping the other charset functions. 39 @ingroup unicode 40 41 @param src_encoding The name encoding of the input. 42 @param in The input string. 43 @param inbytes The number of bytes in the input string. 44 @param dest_encoding The name of the encoding to use for the output. 45 @param out The address of a char*, which will be allocated and filled with the string in the new encoding. 46 @param outbytes The address of a value that will hold the number of bytes long the output is upon return. 47 @return A Max error code. 48 @remark Remember to call sysmem_freeptr(*out) to free any allocated memory. 49 */ 50 t_max_err charset_convert(t_symbol *src_encoding, const char *in, long inbytes, t_symbol *dest_encoding, char **out, long *outbytes); 51 52 53 /** Convert a UTF8 C-String into a 16-bit-wide-character array. 54 @ingroup unicode 55 @param s The string to be converted to unicode. 56 @param outlen The address of a variable to hold the size of the number of chars 57 but does not include the NULL terminator in the count. 58 @return A pointer to the buffer of unicode (wide) characters. 59 */ 60 unsigned short *charset_utf8tounicode(char *s, long *outlen); 61 62 63 /** Convert a 16-bit-wide-character array into a UTF C-string. 64 Accepts either null termination, or not (len is zero in the latter case). 65 @ingroup unicode 66 @param s An array of wide (16-bit) unicode characters. 67 @param len The length of s. 68 @param outlen The address of a variable to hold the size of the number of chars 69 but does not include the NULL terminator in the count. 70 @return A UTF8-encoded C-string. 71 72 */ 73 char *charset_unicodetoutf8(unsigned short *s, long len, long *outlen); 74 75 76 /** Returns utf8 character count, and optionally bytecount. 77 @ingroup unicode 78 @param utf8 The UTF-8 encoded string whose characters are to be counted. 79 @param bytecount The address of a variable to hold the byte count on return. 80 Pass NULL if you don't require the byte count. 81 @return The number of characters in the UTF8 string. 82 */ 83 long charset_utf8_count(char *utf8, long *bytecount); 84 85 86 /** Returns utf8 character offset (positive or negative), and optionally byte offset. 87 @ingroup unicode 88 @param utf8 A UTF-8 encoded string. 89 @param charoffset The char offset into the string at which to find the byte offset. 90 @param byteoffset The address of a variable to hold the byte offset on return. 91 Pass NULL if you don't require the byte offset. 92 @return The character offset. 93 */ 94 char *charset_utf8_offset(char *utf8, long charoffset, long *byteoffset); 95 96 97 #if C74_PRAGMA_STRUCT_PACKPUSH 98 #pragma pack(pop) 99 #elif C74_PRAGMA_STRUCT_PACK 100 #pragma pack() 101 #endif 102 103 END_USING_C_LINKAGE 104 105 #endif // _EXT_CHARSET_H_