SILC Runtime Toolkit 1.2 Beta 1
[runtime.git] / lib / silcutil / silcstrutil.h
1 /*
2
3   silcstrutil.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2002 - 2008 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcutil/String Utilities
21  *
22  * DESCRIPTION
23  *
24  * Various string utility routines.
25  *
26  ***/
27
28 #ifndef SILCSTRUTIL_H
29 #define SILCSTRUTIL_H
30
31 /****d* silcutil/SilcStringEncoding
32  *
33  * NAME
34  *
35  *    typedef enum { ... } SilcStringEncoding;
36  *
37  * DESCRIPTION
38  *
39  *    String encoding definitions used with various string manipulation
40  *    routines.  By default, applications are suggested to use
41  *    SILC_STRING_LOCALE since it encodes and decodes correctly according
42  *    to local system language and character set (locale).
43  *
44  * SOURCE
45  */
46 typedef enum {
47   SILC_STRING_ASCII         = 0,  /* Any 8 bit ASCII encoding (default) */
48   SILC_STRING_ASCII_ESC     = 1,  /* 7 bit ASCII (>0x7f escaped) */
49   SILC_STRING_BMP           = 2,  /* 16 bit, UCS-2, BMP, ISO/IEC 10646 */
50   SILC_STRING_BMP_LSB       = 3,  /* BMP, least significant byte first */
51   SILC_STRING_UNIVERSAL     = 4,  /* 32 bit, UCS-4, Universal, ISO/IEC 10646 */
52   SILC_STRING_UNIVERSAL_LSB = 5,  /* Universal, least significant byte first */
53   SILC_STRING_LOCALE        = 6,  /* A locale specific conversion on
54                                      those platforms that support iconv().
55                                      Fallback is SILC_STRING_ASCII. */
56   SILC_STRING_UTF8          = 7,  /* UTF-8 encoding */
57   SILC_STRING_PRINTABLE     = 8,  /* Printable ASCII (no escaping) */
58   SILC_STRING_VISIBLE       = 9,  /* Visible ASCII string */
59   SILC_STRING_TELETEX       = 10, /* Teletex ASCII string */
60   SILC_STRING_NUMERICAL     = 11, /* Numerical ASCII string (digits) */
61   SILC_STRING_LDAP_DN       = 12, /* Strings for LDAP DNs, RFC 2253 */
62   SILC_STRING_UTF8_ESCAPE   = 12, /* Escaped UTF-8 as defined in RFC 2253 */
63
64   SILC_STRING_LANGUAGE      = 6,  /* _Deprecated_, use SILC_STRING_LOCALE. */
65 } SilcStringEncoding;
66 /***/
67
68 /****f* silcutil/silc_strncat
69  *
70  * SYNOPSIS
71  *
72  *    char *silc_strncat(char *dest, SilcUInt32 dest_size,
73  *                       const char *src, SilcUInt32 src_len);
74  *
75  * DESCRIPTION
76  *
77  *    Concatenates the `src' into `dest'.  If `src_len' is more than the
78  *    size of the `dest' (minus NULL at the end) the `src' will be
79  *    truncated to fit.
80  *
81  ***/
82 char *silc_strncat(char *dest, SilcUInt32 dest_size,
83                    const char *src, SilcUInt32 src_len);
84
85 /****f* silcutil/silc_string_regexify
86  *
87  * SYNOPSIS
88  *
89  *    char *silc_string_regexify(const char *string);
90  *
91  * DESCRIPTION
92  *
93  *    Inspects the `string' for wildcards and returns regex string that can
94  *    be used by the GNU regex library. A comma (`,') in the `string' means
95  *    that the string is list.
96  *
97  ***/
98 char *silc_string_regexify(const char *string);
99
100 /****f* silcutil/silc_string_match
101  *
102  * SYNOPSIS
103  *
104  *    int silc_string_match(const char *string1, const char *string2);
105  *
106  * DESCRIPTION
107  *
108  *    Do regex match to the two strings `string1' and `string2'. If the
109  *    `string2' matches the `string1' this returns TRUE.
110  *
111  ***/
112 int silc_string_match(const char *string1, const char *string2);
113
114 /****f* silcutil/silc_string_compare
115  *
116  * SYNOPSIS
117  *
118  *    int silc_string_compare(char *string1, char *string2);
119  *
120  * DESCRIPTION
121  *
122  *    Compares two strings. Strings may include wildcards '*' and '?'.
123  *    Returns TRUE if strings match.
124  *
125  ***/
126 int silc_string_compare(char *string1, char *string2);
127
128 /****f* silcutil/silc_string_split
129  *
130  * SYNOPSIS
131  *
132  *    char **silc_string_split(const char *string, char ch, int *ret_count);
133  *
134  * DESCRIPTION
135  *
136  *    Splits a `string' that has a separator `ch' into an array of strings
137  *    and returns the array.  The `ret_count' will contain the number of
138  *    strings in the array.  Caller must free the strings and the array.
139  *    Returns NULL on error.  If the string does not have `ch' separator
140  *    this returns the `string' in the array.
141  *
142  ***/
143 char **silc_string_split(const char *string, char ch, int *ret_count);
144
145 #endif /* SILCSTRUTIL_H */