]> git.sur5r.net Git - glabels/blob - libglabels/str.c
Imported Upstream version 2.2.8
[glabels] / libglabels / str.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (LIBGLABELS) Template library for GLABELS
5  *
6  *  str.c:  libGLabels string utilities
7  *
8  *  Copyright (C) 2007  Jim Evins <evins@snaught.com>.
9  *
10  *  This file is part of the LIBGLABELS library.
11  *
12  *  This library is free software; you can redistribute it and/or
13  *  modify it under the terms of the GNU Library General Public
14  *  License as published by the Free Software Foundation; either
15  *  version 2 of the License, or (at your option) any later version.
16  *
17  *  This library is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  *  Library General Public License for more details.
21  *
22  *  You should have received a copy of the GNU Library General Public
23  *  License along with this library; if not, write to the Free
24  *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  *  MA 02111-1307, USA
26  */
27 #include <config.h>
28
29 #include "str.h"
30
31
32 /*===========================================*/
33 /* Private types                             */
34 /*===========================================*/
35
36
37 /*===========================================*/
38 /* Private globals                           */
39 /*===========================================*/
40
41
42 /*===========================================*/
43 /* Local function prototypes                 */
44 /*===========================================*/
45
46
47 /*===========================================*/
48 /* Functions.                                */
49 /*===========================================*/
50
51 /**
52  * lgl_str_utf8_casecmp:
53  * @s1: string to compare with s2.
54  * @s2: string to compare with s1.
55  *
56  * Compare two UTF-8 strings, ignoring the case of characters.
57  *
58  * This function should be used only on strings that are known to be encoded
59  * in UTF-8 or a compatible UTF-8 subset.
60  *
61  * Returns: 0 if the strings match, a negative value if s1 < s2,
62  *          or a positive value if s1 > s2.
63  *
64  */
65 gint
66 lgl_str_utf8_casecmp (const gchar *s1,
67                       const gchar *s2)
68 {
69         gchar *folded_s1;
70         gchar *folded_s2;
71         gint   result;
72
73         folded_s1 = g_utf8_casefold (s1, -1);
74         folded_s2 = g_utf8_casefold (s2, -1);
75
76         result = g_utf8_collate (folded_s1, folded_s2);
77
78         g_free (folded_s1);
79         g_free (folded_s2);
80
81         return result;
82 }
83
84