Enlightenment CVS committal
Author : mej
Project : eterm
Module : libast
Dir : eterm/libast/src
Modified Files:
str.c
Log Message:
Fri Oct 31 15:21:53 2003 Michael Jennings (mej)
Fixes to string class find/splice routines.
Added SPIF_DEFINE_PROPERTY_FUNC_NONOBJ() macro for defining get/set
methods of a property which is not an object. It should be used in
place of SPIF_DEFINE_PROPERTY_FUNC() for spif_*_t types that are not
objects, such as spif_int32_t and spif_sockport_t.
===================================================================
RCS file: /cvsroot/enlightenment/eterm/libast/src/str.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -3 -r1.20 -r1.21
--- str.c 30 Oct 2003 23:13:53 -0000 1.20
+++ str.c 31 Oct 2003 20:23:25 -0000 1.21
@@ -21,7 +21,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-static const char cvs_ident[] = "$Id: str.c,v 1.20 2003/10/30 23:13:53 mej Exp $";
+static const char cvs_ident[] = "$Id: str.c,v 1.21 2003/10/31 20:23:25 mej Exp $";
#ifdef HAVE_CONFIG_H
# include <config.h>
@@ -308,27 +308,51 @@
size_t
spif_str_index(spif_str_t self, spif_char_t c)
{
- return (size_t) ((long) (index(SPIF_CONST_CAST_C(char *) SPIF_STR_STR(self), c))
- (long) (SPIF_STR_STR(self)));
+ char *tmp = index(SPIF_CONST_CAST_C(char *) SPIF_STR_STR(self), c);
+
+ if (tmp) {
+ return SPIF_CAST_C(size_t) (SPIF_CAST_C(long) tmp - SPIF_CAST_C(long)
(SPIF_STR_STR(self)));
+ } else {
+ return SPIF_CAST_C(size_t) (self->len);
+ }
}
size_t
spif_str_rindex(spif_str_t self, spif_char_t c)
{
- return (size_t) ((long) (rindex(SPIF_CONST_CAST_C(char *) SPIF_STR_STR(self), c))
- (long) (SPIF_STR_STR(self)));
+ char *tmp = rindex(SPIF_CONST_CAST_C(char *) SPIF_STR_STR(self), c);
+
+ if (tmp) {
+ return SPIF_CAST_C(size_t) (SPIF_CAST_C(long) tmp - SPIF_CAST_C(long)
(SPIF_STR_STR(self)));
+ } else {
+ return SPIF_CAST_C(size_t) (self->len);
+ }
}
size_t
spif_str_find(spif_str_t self, spif_str_t other)
{
- return (size_t) ((long) (strstr(SPIF_CONST_CAST_C(char *) SPIF_STR_STR(self),
- SPIF_CONST_CAST_C(char *) SPIF_STR_STR(other))) -
(long) (SPIF_STR_STR(self)));
+ char *tmp = strstr(SPIF_CONST_CAST_C(char *) SPIF_STR_STR(self),
+ SPIF_CONST_CAST_C(char *) SPIF_STR_STR(other));
+
+ if (tmp) {
+ return SPIF_CAST_C(size_t) (SPIF_CAST_C(long) tmp - SPIF_CAST_C(long)
(SPIF_STR_STR(self)));
+ } else {
+ return SPIF_CAST_C(size_t) (self->len);
+ }
}
size_t
spif_str_find_from_ptr(spif_str_t self, spif_charptr_t other)
{
- return (size_t) ((long) (strstr(SPIF_CONST_CAST_C(char *) SPIF_STR_STR(self),
- SPIF_CONST_CAST_C(char *) other)) - (long)
(SPIF_STR_STR(self)));
+ char *tmp = strstr(SPIF_CONST_CAST_C(char *) SPIF_STR_STR(self),
+ SPIF_CONST_CAST_C(char *) other);
+
+ if (tmp) {
+ return SPIF_CAST_C(size_t) (SPIF_CAST_C(long) tmp - SPIF_CAST_C(long)
(SPIF_STR_STR(self)));
+ } else {
+ return SPIF_CAST_C(size_t) (self->len);
+ }
}
spif_str_t
@@ -430,10 +454,12 @@
spif_charptr_t tmp, ptmp;
size_t newsize;
- newsize = self->len + ((SPIF_OBJ_ISNULL(other)) ? (0) : (other->len)) - cnt + 1;
+ newsize = self->len + ((SPIF_STR_ISNULL(other)) ? (0) : (other->len)) - cnt + 1;
ptmp = tmp = SPIF_CAST(charptr) MALLOC(newsize);
- memcpy(tmp, self->s, idx);
- ptmp += idx;
+ if (idx > 0) {
+ memcpy(tmp, self->s, idx);
+ ptmp += idx;
+ }
if (!SPIF_OBJ_ISNULL(other)) {
memcpy(ptmp, other->s, other->len);
ptmp += other->len;
@@ -458,8 +484,10 @@
len = (other ? strlen(SPIF_CONST_CAST_C(char *) other) : 0);
newsize = self->len + len - cnt + 1;
ptmp = tmp = SPIF_CAST(charptr) MALLOC(newsize);
- memcpy(tmp, self->s, idx);
- ptmp += idx;
+ if (idx > 0) {
+ memcpy(tmp, self->s, idx);
+ ptmp += idx;
+ }
if (len) {
memcpy(ptmp, other, len);
ptmp += len;
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs