| 1 |
[CCode (cprefix="u_")] |
| 2 |
namespace ICU { |
| 3 |
|
| 4 |
[CCode (cname = "UChar")] |
| 5 |
[IntegerType (rank = 5, min = 0, max = 65535)] |
| 6 |
struct Char {} |
| 7 |
|
| 8 |
[CCode (cname = "UChar*", destroy_function="g_free", has_type_id = false, cheader_filename = "unicode/ustring.h")] |
| 9 |
[SimpleType] |
| 10 |
struct String { |
| 11 |
public static String alloc(int32 length) { |
| 12 |
return (String) (Char*) new Char[length]; |
| 13 |
} |
| 14 |
|
| 15 |
public static String from_string(string src) throws GLib.ConvertError { |
| 16 |
ErrorCode status = ErrorCode.ZERO_ERROR; |
| 17 |
int32 dest_capacity = src.length * 2 + 1; |
| 18 |
String dest = alloc(dest_capacity); |
| 19 |
int32 dest_length; |
| 20 |
strFromUTF8(dest, dest_capacity, out dest_length, src, src.length, ref status); |
| 21 |
if (status.is_failure()) { |
| 22 |
throw new GLib.ConvertError.FAILED(status.errorName()); |
| 23 |
} |
| 24 |
return dest; |
| 25 |
} |
| 26 |
|
| 27 |
public string to_string() throws GLib.ConvertError { |
| 28 |
ErrorCode status = ErrorCode.ZERO_ERROR; |
| 29 |
char[] dest = new char[len() * 4 + 1]; |
| 30 |
int32 dest_length; |
| 31 |
strToUTF8(dest, out dest_length, this, -1, ref status); |
| 32 |
if (status.is_failure()) { |
| 33 |
throw new GLib.ConvertError.FAILED(status.errorName()); |
| 34 |
} |
| 35 |
dest[dest_length] = 0; |
| 36 |
return (string) dest; |
| 37 |
} |
| 38 |
|
| 39 |
[CCode (cname = "u_strlen")] |
| 40 |
public int32 len(); |
| 41 |
|
| 42 |
[CCode (cname="u_strFromUTF8")] |
| 43 |
private static void strFromUTF8(String dest, int32 dest_capacity, out int32 dest_length, string src, int32 src_length, ref ErrorCode status); |
| 44 |
[CCode (cname="u_strToUTF8")] |
| 45 |
private static void strToUTF8(char[] dest, out int32 dest_length, String src, int32 src_length, ref ErrorCode status); |
| 46 |
} |
| 47 |
|
| 48 |
[CCode (cname = "UErrorCode", cprefix = "U_", cheader_filename = "unicode/utypes.h")] |
| 49 |
enum ErrorCode { |
| 50 |
ZERO_ERROR, |
| 51 |
INVALID_CHAR_FOUND, |
| 52 |
INDEX_OUTOFBOUNDS_ERROR, |
| 53 |
BUFFER_OVERFLOW_ERROR, |
| 54 |
STRINGPREP_PROHIBITED_ERROR, |
| 55 |
UNASSIGNED_CODE_POINT_FOUND, |
| 56 |
IDNA_STD3_ASCII_RULES_ERROR |
| 57 |
; |
| 58 |
[CCode (cname = "u_errorName")] |
| 59 |
public unowned string errorName(); |
| 60 |
[CCode (cname = "U_SUCCESS")] |
| 61 |
public bool is_success(); |
| 62 |
[CCode (cname = "U_FAILURE")] |
| 63 |
public bool is_failure(); |
| 64 |
} |
| 65 |
|
| 66 |
[CCode (cname = "UParseError", cprefix = "U_", cheader_filename = "unicode/parseerr.h")] |
| 67 |
struct ParseError {} |
| 68 |
|
| 69 |
[CCode (cname = "UStringPrepProfile", cprefix = "usprep_", free_function = "usprep_close", cheader_filename = "unicode/usprep.h")] |
| 70 |
[Compact] |
| 71 |
class PrepProfile { |
| 72 |
public static PrepProfile open(string path, string file_name, ref ErrorCode status); |
| 73 |
public static PrepProfile openByType(PrepType type, ref ErrorCode status); |
| 74 |
public int32 prepare(String src, int32 src_length, String dest, int32 dest_capacity, PrepOptions options, out ParseError parse_error, ref ErrorCode status); |
| 75 |
} |
| 76 |
[CCode (cname = "UStringPrepProfileType", cprefix = "USPREP_")] |
| 77 |
enum PrepType { |
| 78 |
RFC3491_NAMEPREP, |
| 79 |
RFC3920_NODEPREP, |
| 80 |
RFC3920_RESOURCEPREP |
| 81 |
} |
| 82 |
[CCode (cname = "int32_t", cprefix = "USPREP_")] |
| 83 |
enum PrepOptions { |
| 84 |
DEFAULT, |
| 85 |
ALLOW_UNASSIGNED |
| 86 |
} |
| 87 |
|
| 88 |
[CCode (cname = "UIDNA", cprefix = "uidna_", free_function = "uidna_close", cheader_filename = "unicode/uidna.h")] |
| 89 |
[Compact] |
| 90 |
class IDNA { |
| 91 |
public static IDNA openUTS46(IDNAOptions options, ref ErrorCode status); |
| 92 |
public static int32 IDNToUnicode(Char* src, int32 src_length, Char* dest, int32 dest_capacity, IDNAOptions options, out ParseError parse_error, ref ErrorCode status); |
| 93 |
public static int32 IDNToASCII(Char* src, int32 src_length, Char* dest, int32 dest_capacity, IDNAOptions options, out ParseError parse_error, ref ErrorCode status); |
| 94 |
public int32 nameToUnicode(Char* src, int32 src_length, Char* dest, int32 dest_capacity, out IDNAInfo info, ref ErrorCode status); |
| 95 |
public int32 nameToASCII(Char* src, int32 src_length, Char* dest, int32 dest_capacity, out IDNAInfo info, ref ErrorCode status); |
| 96 |
public int32 nameToASCII_UTF8(string name, int32 name_length, char[] dest, out IDNAInfo info, ref ErrorCode status); |
| 97 |
public int32 nameToUnicodeUTF8(string name, int32 name_length, char[] dest, out IDNAInfo info, ref ErrorCode status); |
| 98 |
} |
| 99 |
|
| 100 |
[CCode (cname = "UIDNAInfo", default_value = "UIDNA_INFO_INITIALIZER", has_type_id = false, cheader_filename = "unicode/uidna.h")] |
| 101 |
struct IDNAInfo { |
| 102 |
public static IDNAInfo INITIAL; |
| 103 |
public uint32 errors; |
| 104 |
public bool isTransitionalDifferent; |
| 105 |
} |
| 106 |
|
| 107 |
[CCode (cname = "uint32_t", cprefix = "UIDNA_")] |
| 108 |
enum IDNAOptions { |
| 109 |
DEFAULT, |
| 110 |
ALLOW_UNASSIGNED, |
| 111 |
USE_STD3_RULES |
| 112 |
} |
| 113 |
|
| 114 |
} |