~ubuntu-branches/ubuntu/precise/nautilus-actions/precise

« back to all changes in this revision

Viewing changes to src/core/na-core-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Christine Spang
  • Date: 2011-01-01 20:45:43 UTC
  • mfrom: (3.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20110101204543-1prwld2snlallc4r
Tags: 3.0.5-1
* New upstream maintenance release.
* Switch to dpkg-source 3.0 (quilt) format
* Fix building with binutils-gold (Closes: #555763)
  - Thanks to Bhavani Shankar for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Nautilus Actions
 
2
 * Nautilus-Actions
3
3
 * A Nautilus extension which offers configurable context menu actions.
4
4
 *
5
5
 * Copyright (C) 2005 The GNOME Foundation
6
6
 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7
 
 * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
 
7
 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
8
8
 *
9
9
 * This Program is free software; you can redistribute it and/or
10
10
 * modify it under the terms of the GNU General Public License as
52
52
 *
53
53
 * Returns: %TRUE if the string evaluates to "true" (case insensitive),
54
54
 * %FALSE else.
 
55
 *
 
56
 * Since: 2.30
55
57
 */
56
58
gboolean
57
59
na_core_utils_boolean_from_string( const gchar *string )
67
69
 * Appends a prefix to each line of the string.
68
70
 *
69
71
 * Returns: a new string which should be g_free() by the caller.
 
72
 *
 
73
 * Since: 2.30
70
74
 */
71
75
gchar *
72
76
na_core_utils_str_add_prefix( const gchar *prefix, const gchar *str )
91
95
 * @str1: an UTF-8 encoded string.
92
96
 * @str2: an UTF-8 encoded string.
93
97
 *
94
 
 * Returns: -1 if str1 < str2, 0 if str1 = str2, +1 if str1 > str2.
 
98
 * Returns:
 
99
 * <itemizedlist>
 
100
 *   <listitem>
 
101
 *     <para>-1 if str1 < str2,</para>
 
102
 *   </listitem>
 
103
 *   <listitem>
 
104
 *     <para>0 if str1 = str2,</para>
 
105
 *   </listitem>
 
106
 *   <listitem>
 
107
 *     <para>+1 if str1 > str2.</para>
 
108
 *   </listitem>
 
109
 * </itemizedlist>
 
110
 *
 
111
 * Since: 2.30
95
112
 */
96
113
int
97
114
na_core_utils_str_collate( const gchar *str1, const gchar *str2 )
100
117
 
101
118
        if( str1 && str2 ){
102
119
                res = g_utf8_collate( str1, str2 );
 
120
 
103
121
        } else if( !str1 && !str2 ){
104
122
                res = 0;
 
123
 
105
124
        } else if( !str1 ){
106
125
                res = -1;
 
126
 
107
127
        } else {
108
128
                g_return_val_if_fail( str2 == NULL, 0 );
109
129
                res = 1;
120
140
 * minus all the found occurrences of the given @to_remove char.
121
141
 *
122
142
 * The returned string should be g_free() by the caller.
 
143
 *
 
144
 * Since: 2.30
123
145
 */
124
146
gchar *
125
147
na_core_utils_str_remove_char( const gchar *string, const gchar *to_remove )
162
184
 * @suffix, then the returned string is equal to source @string.
163
185
 *
164
186
 * The returned string should be g_free() by the caller.
 
187
 *
 
188
 * Since: 2.30
165
189
 */
166
190
gchar *
167
191
na_core_utils_str_remove_suffix( const gchar *string, const gchar *suffix )
186
210
 * @other: a pointer to a gchar *.
187
211
 *
188
212
 * Split the @string string into two components:
189
 
 * - the first word which is allocated in @first,
190
 
 * - the rest of the string which is allocated in @other.
 
213
 * <itemizedlist>
 
214
 *   <listitem>
 
215
 *     <para>the first word which is allocated in @first,</para>
 
216
 *   </listitem>
 
217
 *   <listitem>
 
218
 *     <para>the rest of the string which is allocated in @other.</para>
 
219
 *   </listitem>
 
220
 * </itemizedlist>
191
221
 *
192
222
 * The two allocated strings should be g_free() by the caller.
 
223
 *
 
224
 * Since: 2.30
193
225
 */
194
226
void
195
227
na_core_utils_str_split_first_word( const gchar *string, gchar **first, gchar **other )
238
270
 * Returns: a #GSList of strings.
239
271
 *
240
272
 * The returned list should be na_core_utils_slist_free() by the caller.
 
273
 *
 
274
 * Since: 2.30
241
275
 */
242
276
GSList *
243
277
na_core_utils_slist_duplicate( GSList *slist )
261
295
 * @list: a list of strings.
262
296
 *
263
297
 * Dumps the content of a list of strings.
 
298
 *
 
299
 * Since: 2.30
264
300
 */
265
301
void
266
302
na_core_utils_slist_dump( const gchar *prefix, GSList *list )
287
323
 * Returns: a #GSList with the list of strings after having been splitted.
288
324
 *
289
325
 * The returned #GSList should be na_core_utils_slist_free() by the caller.
 
326
 *
 
327
 * Since: 2.30
290
328
 */
291
329
GSList *
292
330
na_core_utils_slist_from_split( const gchar *text, const gchar *separator )
321
359
 *
322
360
 * Returns: a #GSList list of strings, which should be #na_core_utils_slist_free()
323
361
 * by the caller.
 
362
 *
 
363
 * Since: 2.30
324
364
 */
325
365
GSList *
326
366
na_core_utils_slist_from_array( const gchar **str_array )
345
385
 * @link: the string used to join each element.
346
386
 *
347
387
 * Returns: a newly allocated string which should be g_free() by the caller.
 
388
 *
 
389
 * Since: 2.30
348
390
 */
349
391
gchar *
350
392
na_core_utils_slist_join_at_end( GSList *slist, const gchar *link )
372
414
 * Removes a string from a GSList of strings.
373
415
 *
374
416
 * Returns: the same, updated, @slist.
 
417
 *
 
418
 * Since: 2.30
375
419
 */
376
420
GSList *
377
421
na_core_utils_slist_remove_ascii( GSList *slist, const gchar *text )
400
444
 * @text.
401
445
 *
402
446
 * Returns: the new @slist start position.
 
447
 *
 
448
 * Since: 2.30
403
449
 */
404
450
GSList *
405
451
na_core_utils_slist_remove_utf8( GSList *slist, const gchar *text )
424
470
 *
425
471
 * Returns: a newly allocated array of strings, which should be
426
472
 * g_strfreev() by the caller.
 
473
 *
 
474
 * Since: 2.30
427
475
 */
428
476
gchar **
429
477
na_core_utils_slist_to_array( GSList *slist )
451
499
 *
452
500
 * Returns: a newly allocated string, which should be g_free() by the
453
501
 * caller.
 
502
 *
 
503
 * Since: 2.30
454
504
 */
455
505
gchar *
456
506
na_core_utils_slist_to_text( GSList *slist )
483
533
 * or not if @set is %FALSE.
484
534
 *
485
535
 * Returns: the updated @list.
 
536
 *
 
537
 * Since: 2.30
486
538
 */
487
539
GSList *
488
540
na_core_utils_slist_setup_element( GSList *list, const gchar *element, gboolean set )
509
561
 * Search for a string in a string list.
510
562
 *
511
563
 * Returns: the count of @ßtr in @list list.
 
564
 *
 
565
 * Since: 2.30
512
566
 */
513
567
guint
514
568
na_core_utils_slist_count( GSList *list, const gchar *str )
536
590
 * Search for a string in a string list which may contain nagated items.
537
591
 *
538
592
 * Returns: %TRUE if the string has been found in list.
 
593
 *
 
594
 * Since: 2.30
539
595
 */
540
596
gboolean
541
597
na_core_utils_slist_find_negated( GSList *list, const gchar *str )
569
625
 * Compare two string lists, without regards to the order.
570
626
 *
571
627
 * Returns: %TRUE if the two lists have same content.
 
628
 *
 
629
 * Since: 2.30
572
630
 */
573
631
gboolean
574
632
na_core_utils_slist_are_equal( GSList *a, GSList *b )
597
655
 * @slist: a #GSList list of strings.
598
656
 *
599
657
 * Releases the strings and the list itself.
 
658
 *
 
659
 * Since: 2.30
600
660
 */
601
661
void
602
662
na_core_utils_slist_free( GSList *slist )
614
674
 * Concatenates a gchar **list of strings to a new string.
615
675
 *
616
676
 * Returns: a newly allocated string which should be g_free() by the caller.
 
677
 *
 
678
 * Since: 2.30
617
679
 */
618
680
gchar *
619
681
na_core_utils_gstring_joinv( const gchar *start, const gchar *separator, gchar **list )
678
740
 * relevant integer.
679
741
 *
680
742
 * The two returned strings must be g_free() by the caller.
 
743
 *
 
744
 * Since: 2.30
681
745
 */
682
746
void
683
747
na_core_utils_selcount_get_ope_int( const gchar *selcount, gchar **ope, gchar **uint )
713
777
 * but before the caller has been able to actually write into it.
714
778
 *
715
779
 * There is no "super-test". Just try...
 
780
 *
 
781
 * Since: 2.30
716
782
 */
717
783
gboolean
718
784
na_core_utils_dir_is_writable_path( const gchar *path )
744
810
 * but before the caller has been able to actually write into it.
745
811
 *
746
812
 * There is no "super-test". Just try...
 
813
 *
 
814
 * Since: 2.30
747
815
 */
748
816
gboolean
749
817
na_core_utils_dir_is_writable_uri( const gchar *uri )
812
880
 * allocated buffers which should be g_free() by the caller.
813
881
 *
814
882
 * The extension is set to an empty string if no extension is detected.
 
883
 *
 
884
 * Since: 2.30
815
885
 */
816
886
void
817
887
na_core_utils_dir_split_ext( const gchar *string, gchar **first, gchar **ext )
849
919
 * @path: the path of the file to be deleted.
850
920
 *
851
921
 * Returns: %TRUE if the file is successfully deleted, %FALSE else.
 
922
 *
 
923
 * Since: 2.30
852
924
 */
853
925
gboolean
854
926
na_core_utils_file_delete( const gchar *path )
876
948
 *
877
949
 * Returns: %TRUE if the specified file exists, %FALSE else.
878
950
 *
879
 
 * Race condition: cf. na_core_utils_dir_is_writable() comment.
 
951
 * Race condition: cf. na_core_utils_dir_is_writable_path() and
 
952
 * na_core_utils_dir_is_writable_uri() comments.
 
953
 *
 
954
 * Since: 2.30
880
955
 */
881
956
gboolean
882
957
na_core_utils_file_exists( const gchar *uri )
901
976
 *
902
977
 * Returns: the newly allocated buffer which contains the file content, or %NULL.
903
978
 * This buffer should be g_free() by the caller.
 
979
 *
 
980
 * Since: 2.30
904
981
 */
905
982
gchar *
906
983
na_core_utils_file_load_from_uri( const gchar *uri, gsize *length )
928
1005
 *
929
1006
 * Print a version message on the console
930
1007
 *
931
 
 * nautilus-actions-new (Nautilus-Actions) v 2.29.1
932
 
 * Copyright (C) 2005-2007 Frederic Ruaudel
933
 
 * Copyright (C) 2009, 2010 Pierre Wieser
934
 
 * Nautilus-Actions is free software, licensed under GPLv2 or later.
 
1008
 * <programlisting>
 
1009
 *   nautilus-actions-new (Nautilus-Actions) v 2.29.1
 
1010
 *   Copyright (C) 2005-2007 Frederic Ruaudel
 
1011
 *   Copyright (C) 2009, 2010, 2011 Pierre Wieser
 
1012
 *   Nautilus-Actions is free software, licensed under GPLv2 or later.
 
1013
 * </programlisting>
 
1014
 *
 
1015
 * Since: 2.30
935
1016
 */
936
1017
void
937
1018
na_core_utils_print_version( void )