~ubuntu-branches/ubuntu/oneiric/rhythmbox/oneiric

« back to all changes in this revision

Viewing changes to lib/rb-cut-and-paste-code.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-06-26 19:06:10 UTC
  • mto: (2.1.1 lenny) (1.1.37 upstream)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20060626190610-08x8lgvvfs0gr619
Tags: upstream-0.9.5
ImportĀ upstreamĀ versionĀ 0.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 *  arch-tag: File containing code cut and pasted from elsewhere
4
4
 *
 
5
 *  Copyright (C) 2000 Eazel, Inc.
5
6
 *  Copyright (C) 2002 Jorn Baayen
6
7
 *
7
8
 *  This program is free software; you can redistribute it and/or modify
16
17
 *
17
18
 *  You should have received a copy of the GNU General Public License
18
19
 *  along with this program; if not, write to the Free Software
19
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
20
21
 *
 
22
 *  Authors: John Sullivan <sullivan@eazel.com>
 
23
 *           Jorn Baayen
21
24
 */
22
25
 
23
26
#include <config.h>
80
83
/* Legal conversion specifiers, as specified in the C standard. */
81
84
#define C_STANDARD_STRFTIME_CHARACTERS "aAbBcdHIjmMpSUwWxXyYZ"
82
85
#define C_STANDARD_NUMERIC_STRFTIME_CHARACTERS "dHIjmMSUwWyY"
 
86
#define SUS_EXTENDED_STRFTIME_MODIFIERS "EO"
83
87
 
84
88
/**
85
89
 * eel_strdup_strftime:
109
113
{
110
114
        GString *string;
111
115
        const char *remainder, *percent;
112
 
        char code[3], buffer[512];
 
116
        char code[4], buffer[512];
113
117
        char *piece, *result, *converted;
114
118
        size_t string_length;
115
119
        gboolean strip_leading_zeros, turn_leading_zeros_to_spaces;
 
120
        char modifier;
 
121
        int i;
116
122
 
117
123
        /* Format could be translated, and contain UTF-8 chars,
118
124
         * so convert to locale encoding which strftime uses */
158
164
                        turn_leading_zeros_to_spaces = FALSE;
159
165
                        break;
160
166
                }
 
167
 
 
168
                modifier = 0;
 
169
                if (strchr (SUS_EXTENDED_STRFTIME_MODIFIERS, *remainder) != NULL) {
 
170
                        modifier = *remainder;
 
171
                        remainder++;
 
172
 
 
173
                        if (*remainder == 0) {
 
174
                                g_warning ("Unfinished %%%c modifier passed to eel_strdup_strftime", modifier);
 
175
                                break;
 
176
                        }
 
177
                } 
161
178
                
162
179
                if (strchr (C_STANDARD_STRFTIME_CHARACTERS, *remainder) == NULL) {
163
180
                        g_warning ("eel_strdup_strftime does not support "
170
187
                 * of 512 bytes, which is probably OK. There's no
171
188
                 * limit on the total size of the result string.
172
189
                 */
173
 
                code[0] = '%';
174
 
                code[1] = *remainder;
175
 
                code[2] = '\0';
 
190
                i = 0;
 
191
                code[i++] = '%';
 
192
                if (modifier != 0) {
 
193
#ifdef HAVE_STRFTIME_EXTENSION
 
194
                        code[i++] = modifier;
 
195
#endif
 
196
                }
 
197
                code[i++] = *remainder;
 
198
                code[i++] = '\0';
176
199
                string_length = strftime (buffer, sizeof (buffer),
177
200
                                          code, time_pieces);
178
201
                if (string_length == 0) {