1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
5 * Copyright (C) 2008, Eduardo Silva P.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 /* Return a buffer with a new string from string */
35 char *mk_string_copy_substr(const char *string
, int pos_init
, int pos_end
)
37 unsigned int size
, bytes
;
40 size
= (unsigned int) (pos_end
- pos_init
) + 1;
43 buffer
= malloc(size
);
49 if(pos_init
> pos_end
)
55 bytes
= pos_end
- pos_init
;
56 memcpy(buffer
, string
+pos_init
, bytes
);
59 return (char *) buffer
;
62 int mk_string_char_search(char *string
, int c
, int n
)
79 /* Get position of a substring.
80 * Original version taken from google, modified in order
81 * to send the position instead the substring.
84 int _mk_string_search(char *string
, char *search
, int n
)
89 np
= strcasestr(string
, search
);
103 int mk_string_search(char *string
, char *search
)
105 return _mk_string_search(string
, search
, -1);
108 /* lookup char in reverse order */
109 int mk_string_search_r(char *string
, char search
, int n
)
122 if(string
[i
]==search
){
130 int mk_string_search_n(char *string
, char *search
, int n
)
132 return _mk_string_search(string
, search
, n
);
136 char *mk_string_remove_space(char *buf
)
139 int new_i
=0, i
, len
, spaces
=0;
150 bufsize
= len
+1-spaces
;
155 new_buf
= mk_mem_malloc(bufsize
);
160 new_buf
[new_i
] = buf
[i
];
168 char *mk_string_casestr(char *heystack
, char *needle
)
170 if(!heystack
|| !needle
)
175 return strcasestr(heystack
, needle
);
178 char *mk_string_dup(const char *s
)
186 int mk_string_array_count(char *arr
[])
190 for(i
=0; arr
[i
]; i
++){}