File: str_util.h

package info (click to toggle)
tagtool 0.12.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,352 kB
  • ctags: 1,010
  • sloc: ansic: 9,013; sh: 3,571; makefile: 121
file content (89 lines) | stat: -rw-r--r-- 2,122 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
#ifndef STR_UTIL_H
#define STR_UTIL_H


/*
 * IMPORTANT NOTES:
 *
 * All functions manipulate UTF-8 strings, unless otherwise noted.
 *
 * All input and output strings are 0 terminated.
 *
 * All input strings are assumed to be valid. If the source of the string 
 * is suspect it should be validated first with g_utf8_validate().
 */


/* types of case conversion for str_convert_case() */
enum {
	CASE_CONV_NONE     = 0,
	CASE_CONV_LOWER    = 1,
	CASE_CONV_UPPER    = 2,
	CASE_CONV_SENTENCE = 3,
	CASE_CONV_TITLE    = 4
};


/*
 * Converts a string to the requested case.
 * The result is returned in a newly allocated string.
 */
char *str_convert_case(const char *str, int conv);

/*
 * Replaces all occurrences of the character <orig> with <repl>
 * The result is returned in a newly allocated string.
 */
char *str_replace_char(const char *str, gunichar orig, gunichar repl);

/*
 * Removes all occurrences of character <rem> from <str>.
 * The result is returned in a newly allocated string.
 */
char *str_remove_char(const char *str, gunichar rem);

/* 
 * Trims trailing space, tab and newline characters from string <str>
 */
void str_rtrim(char *str);

/*
 * Returns a pointer to the <n>th occurrence of <c> in <s>, counting from 
 * the beginning.
 * Similar to strchr(3)
 */
char *str_strnchr(const char *s, char c, int n);

/*
 * Returns a pointer to the <n>th occurrence of <c> in <s>, counting from 
 * the end.
 * Similar to strrchr(3)
 */
char *str_strnrchr(const char *s, char c, int n);

/*
 * Safe version of strncpy, string is always NULL terminated.
 */
char *str_safe_strncpy(char *dest, const char *src, size_t n);


/*
 * Converts a pure ASCII string (characters 0x00 to 0x7f) to lower case. 
 * Conversion is done in-place.
 */
void str_ascii_tolower(char *str);

/*
 * Converts a pure ASCII string (characters 0x00 to 0x7f) to upper case. 
 * Conversion is done in-place.
 */
void str_ascii_toupper(char *str);

/*
 * Replaces all occurrences of the ASCII character <orig> with <repl>.
 * Replacement is done in-place.
 */
void str_ascii_replace_char(char *str, char orig, char repl);


#endif