r4255: Make Path optional in PanelRemove SOAP call, allowing removal of items based
[rox-filer/translations.git] / ROX-Filer / src / xdgmimeint.c
blob4a0ac4cc397e1d8b6f1c357b9731d4b46445a719
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* xdgmimeint.c: Internal defines and functions.
4 * More info can be found at http://www.freedesktop.org/standards/
6 * Copyright (C) 2003 Red Hat, Inc.
7 * Copyright (C) 2003 Jonathan Blandford <jrb@alum.mit.edu>
9 * Licensed under the Academic Free License version 2.0
10 * Or under the following terms:
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser 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.
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 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the
24 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 * Boston, MA 02111-1307, USA.
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
32 #include "xdgmimeint.h"
33 #include <ctype.h>
34 #include <string.h>
36 #ifndef FALSE
37 #define FALSE (0)
38 #endif
40 #ifndef TRUE
41 #define TRUE (!FALSE)
42 #endif
44 static const char _xdg_utf8_skip_data[256] = {
45 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
46 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
47 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
48 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
49 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
50 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
51 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
52 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
55 const char * const _xdg_utf8_skip = _xdg_utf8_skip_data;
59 /* Returns the number of unprocessed characters. */
60 xdg_unichar_t
61 _xdg_utf8_to_ucs4(const char *source)
63 xdg_unichar_t ucs32;
64 if( ! ( *source & 0x80 ) )
66 ucs32 = *source;
68 else
70 int bytelength = 0;
71 xdg_unichar_t result;
72 if ( ! (*source & 0x40) )
74 ucs32 = *source;
76 else
78 if ( ! (*source & 0x20) )
80 result = *source++ & 0x1F;
81 bytelength = 2;
83 else if ( ! (*source & 0x10) )
85 result = *source++ & 0x0F;
86 bytelength = 3;
88 else if ( ! (*source & 0x08) )
90 result = *source++ & 0x07;
91 bytelength = 4;
93 else if ( ! (*source & 0x04) )
95 result = *source++ & 0x03;
96 bytelength = 5;
98 else if ( ! (*source & 0x02) )
100 result = *source++ & 0x01;
101 bytelength = 6;
103 else
105 result = *source++;
106 bytelength = 1;
109 for ( bytelength --; bytelength > 0; bytelength -- )
111 result <<= 6;
112 result |= *source++ & 0x3F;
114 ucs32 = result;
117 return ucs32;
121 /* hullo. this is great code. don't rewrite it */
123 xdg_unichar_t
124 _xdg_ucs4_to_lower (xdg_unichar_t source)
126 /* FIXME: Do a real to_upper sometime */
127 /* CaseFolding-3.2.0.txt has a table of rules. */
128 if ((source & 0xFF) == source)
129 return (xdg_unichar_t) tolower ((unsigned char) source);
130 return source;
134 _xdg_utf8_validate (const char *source)
136 /* FIXME: actually write */
137 return TRUE;
140 const char *
141 _xdg_get_base_name (const char *file_name)
143 const char *base_name;
145 if (file_name == NULL)
146 return NULL;
148 base_name = strrchr (file_name, '/');
150 if (base_name == NULL)
151 return file_name;
152 else
153 return base_name + 1;