1 | /* $Id: kHlpString.h 29 2009-07-01 20:30:29Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * kHlpString - String And Memory Routines.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person
|
---|
10 | * obtaining a copy of this software and associated documentation
|
---|
11 | * files (the "Software"), to deal in the Software without
|
---|
12 | * restriction, including without limitation the rights to use,
|
---|
13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
14 | * copies of the Software, and to permit persons to whom the
|
---|
15 | * Software is furnished to do so, subject to the following
|
---|
16 | * conditions:
|
---|
17 | *
|
---|
18 | * The above copyright notice and this permission notice shall be
|
---|
19 | * included in all copies or substantial portions of the Software.
|
---|
20 | *
|
---|
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
28 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef ___k_kHlpString_h___
|
---|
32 | #define ___k_kHlpString_h___
|
---|
33 |
|
---|
34 | #include <k/kHlpDefs.h>
|
---|
35 | #include <k/kTypes.h>
|
---|
36 |
|
---|
37 | #if 0 /* optimize / fix this later */
|
---|
38 | #ifdef __GNUC__
|
---|
39 | /** memchr */
|
---|
40 | # define kHlpMemChr(a,b,c) __builtin_memchr(a,b,c)
|
---|
41 | /** memcmp */
|
---|
42 | # define kHlpMemComp(a,b,c) __builtin_memcmp(a,b,c)
|
---|
43 | /** memcpy */
|
---|
44 | # define kHlpMemCopy(a,b,c) __builtin_memcpy(a,b,c)
|
---|
45 | /** memset */
|
---|
46 | # define kHlpMemSet(a,b,c) __builtin_memset(a,b,c)
|
---|
47 | /** strchr */
|
---|
48 | # define kHlpStrChr(a, b) __builtin_strchr(a, b)
|
---|
49 | /** strcmp */
|
---|
50 | # define kHlpStrComp(a, b) __builtin_strcmp(a, b)
|
---|
51 | /** strncmp */
|
---|
52 | # define kHlpStrNComp(a,b,c) __builtin_strncmp(a, b, c)
|
---|
53 | /** strlen */
|
---|
54 | # define kHlpStrLen(a) __builtin_strlen(a)
|
---|
55 |
|
---|
56 | #elif defined(_MSC_VER)
|
---|
57 | # pragma intrinsic(memcmp, memcpy, memset, strcmp, strlen)
|
---|
58 | /** memcmp */
|
---|
59 | # define kHlpMemComp(a,b,c) memcmp(a,b,c)
|
---|
60 | /** memcpy */
|
---|
61 | # define kHlpMemCopy(a,b,c) memcpy(a,b,c)
|
---|
62 | /** memset */
|
---|
63 | # define kHlpMemSet(a,b,c) memset(a,b,c)
|
---|
64 | /** strcmp */
|
---|
65 | # define kHlpStrComp(a, b) strcmp(a, b)
|
---|
66 | /** strlen */
|
---|
67 | # define kHlpStrLen(a) strlen(a)
|
---|
68 | #else
|
---|
69 | # error "Port Me"
|
---|
70 | #endif
|
---|
71 | #endif /* disabled */
|
---|
72 |
|
---|
73 | #ifdef __cplusplus
|
---|
74 | extern "C" {
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | #ifndef kHlpMemChr
|
---|
78 | KHLP_DECL(void *) kHlpMemChr(const void *pv, int ch, KSIZE cb);
|
---|
79 | #endif
|
---|
80 | #ifndef kHlpMemComp
|
---|
81 | KHLP_DECL(int) kHlpMemComp(const void *pv1, const void *pv2, KSIZE cb);
|
---|
82 | #endif
|
---|
83 | #ifndef kHlpMemComp
|
---|
84 | KHLP_DECL(void *) kHlpMemPComp(const void *pv1, const void *pv2, KSIZE cb);
|
---|
85 | #endif
|
---|
86 | #ifndef kHlpMemCopy
|
---|
87 | KHLP_DECL(void *) kHlpMemCopy(void *pv1, const void *pv2, KSIZE cb);
|
---|
88 | #endif
|
---|
89 | #ifndef kHlpMemPCopy
|
---|
90 | KHLP_DECL(void *) kHlpMemPCopy(void *pv1, const void *pv2, KSIZE cb);
|
---|
91 | #endif
|
---|
92 | #ifndef kHlpMemMove
|
---|
93 | KHLP_DECL(void *) kHlpMemMove(void *pv1, const void *pv2, KSIZE cb);
|
---|
94 | #endif
|
---|
95 | #ifndef kHlpMemPMove
|
---|
96 | KHLP_DECL(void *) kHlpMemPMove(void *pv1, const void *pv2, KSIZE cb);
|
---|
97 | #endif
|
---|
98 | #ifndef kHlpMemSet
|
---|
99 | KHLP_DECL(void *) kHlpMemSet(void *pv1, int ch, KSIZE cb);
|
---|
100 | #endif
|
---|
101 | #ifndef kHlpMemPSet
|
---|
102 | KHLP_DECL(void *) kHlpMemPSet(void *pv1, int ch, KSIZE cb);
|
---|
103 | #endif
|
---|
104 | KHLP_DECL(int) kHlpMemICompAscii(const void *pv1, const void *pv2, KSIZE cb);
|
---|
105 |
|
---|
106 | #ifndef kHlpStrCat
|
---|
107 | KHLP_DECL(char *) kHlpStrCat(char *psz1, const char *psz2);
|
---|
108 | #endif
|
---|
109 | #ifndef kHlpStrPCat
|
---|
110 | KHLP_DECL(char *) kHlpStrPCat(char *psz1, const char *psz2);
|
---|
111 | #endif
|
---|
112 | #ifndef kHlpStrNCat
|
---|
113 | KHLP_DECL(char *) kHlpStrNCat(char *psz1, const char *psz2, KSIZE cb);
|
---|
114 | #endif
|
---|
115 | #ifndef kHlpStrPNCat
|
---|
116 | KHLP_DECL(char *) kHlpStrNPCat(char *psz1, const char *psz2, KSIZE cb);
|
---|
117 | #endif
|
---|
118 | #ifndef kHlpStrChr
|
---|
119 | KHLP_DECL(char *) kHlpStrChr(const char *psz, int ch);
|
---|
120 | #endif
|
---|
121 | #ifndef kHlpStrRChr
|
---|
122 | KHLP_DECL(char *) kHlpStrRChr(const char *psz, int ch);
|
---|
123 | #endif
|
---|
124 | #ifndef kHlpStrComp
|
---|
125 | KHLP_DECL(int) kHlpStrComp(const char *psz1, const char *psz2);
|
---|
126 | #endif
|
---|
127 | KHLP_DECL(char *) kHlpStrPComp(const char *psz1, const char *psz2);
|
---|
128 | #ifndef kHlpStrNComp
|
---|
129 | KHLP_DECL(int) kHlpStrNComp(const char *psz1, const char *psz2, KSIZE cch);
|
---|
130 | #endif
|
---|
131 | KHLP_DECL(char *) kHlpStrNPComp(const char *psz1, const char *psz2, KSIZE cch);
|
---|
132 | KHLP_DECL(int) kHlpStrICompAscii(const char *pv1, const char *pv2);
|
---|
133 | KHLP_DECL(char *) kHlpStrIPCompAscii(const char *pv1, const char *pv2);
|
---|
134 | KHLP_DECL(int) kHlpStrNICompAscii(const char *pv1, const char *pv2, KSIZE cch);
|
---|
135 | KHLP_DECL(char *) kHlpStrNIPCompAscii(const char *pv1, const char *pv2, KSIZE cch);
|
---|
136 | #ifndef kHlpStrCopy
|
---|
137 | KHLP_DECL(char *) kHlpStrCopy(char *psz1, const char *psz2);
|
---|
138 | #endif
|
---|
139 | #ifndef kHlpStrPCopy
|
---|
140 | KHLP_DECL(char *) kHlpStrPCopy(char *psz1, const char *psz2);
|
---|
141 | #endif
|
---|
142 | #ifndef kHlpStrLen
|
---|
143 | KHLP_DECL(KSIZE) kHlpStrLen(const char *psz1);
|
---|
144 | #endif
|
---|
145 | #ifndef kHlpStrNLen
|
---|
146 | KHLP_DECL(KSIZE) kHlpStrNLen(const char *psz, KSIZE cchMax);
|
---|
147 | #endif
|
---|
148 |
|
---|
149 | KHLP_DECL(char *) kHlpInt2Ascii(char *psz, KSIZE cch, long lVal, unsigned iBase);
|
---|
150 |
|
---|
151 | #ifdef __cplusplus
|
---|
152 | }
|
---|
153 | #endif
|
---|
154 |
|
---|
155 | #endif
|
---|
156 |
|
---|