File: UgString.h

package info (click to toggle)
uget 2.2.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,348 kB
  • sloc: ansic: 41,325; sh: 1,444; makefile: 325
file content (112 lines) | stat: -rw-r--r-- 3,595 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 *
 *   Copyright (C) 2012-2020 by C.H. Huang
 *   plushuang.tw@gmail.com
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *  ---
 *
 *  In addition, as a special exception, the copyright holders give
 *  permission to link the code of portions of this program with the
 *  OpenSSL library under certain conditions as described in each
 *  individual source file, and distribute linked combinations
 *  including the two.
 *  You must obey the GNU Lesser General Public License in all respects
 *  for all of the code used other than OpenSSL.  If you modify
 *  file(s) with this exception, you may extend this exception to your
 *  version of the file(s), but you are not obligated to do so.  If you
 *  do not wish to do so, delete this exception statement from your
 *  version.  If you delete this exception statement from all source
 *  files in the program, then also delete it here.
 *
 */

#ifndef UG_STRING_H
#define UG_STRING_H

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#ifndef strcasecmp
#define strcasecmp   stricmp
#define strncasecmp  strnicmp
#endif // strcasecmp
#endif // _MSC_VER

#include <time.h>        // time_t
#include <string.h>
#include <stdint.h>
#include <UgDefine.h>

#ifdef __cplusplus
extern "C" {
#endif

// ----------------------------------------------------------------------------
// String

#ifdef HAVE_GLIB
#define ug_strdup_printf   g_strdup_printf
#define ug_strndup         g_strndup
#define ug_strdup          g_strdup
#else
char*   ug_strdup_printf (const char* format, ...);
char*   ug_strndup (const char* string, size_t length);
#define ug_strdup          strdup
#endif

// return length of new string.
// param dest can be param src or NULL.
int    ug_str_remove_crlf (const char* src, char* dest);
int    ug_str_remove_chars (const char* src, char* dest, const char* chars);

// return number of characters was replaced by to_char
int    ug_str_replace_chars (char* str, const char* from_chars, int to_char);

/*
 * convert double to string
 * If value large than 1024, it will append unit string like "KiB",
 * "MiB", "GiB", "TiB", or "PiB"  to string.
 */
char*  ug_str_from_int_unit (int64_t value, const char* tail);

/*
 * convert seconds to string (hh:mm:ss)
 */
char*  ug_str_from_seconds (int seconds, int limit_99_99_99);

/*
 * convert time_t to string
 */
char*  ug_str_from_time (time_t ptt, int date_only);


// RFC3339: 2013-09-12T22:50:20+08:00
// RFC822:  Sat, 07 Sep 2002 00:00:01 GMT
// If the calendar time cannot be represented, a value of -1 is returned.
time_t  ug_str_rfc822_to_time  (const char* rfc822_string);
time_t  ug_str_rfc3339_to_time (const char* rfc3339_string);

// ------------------------------------
// command-line
char** ug_argv_from_cmd (const char* commandline, int* argc, int reserve_len);
void   ug_argv_free (char** ug_argv);

#ifdef __cplusplus
}
#endif

#endif // End of UG_STRING_H