Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- C like string functions made by BigETI © 2013
- c_string_h.inc
- You are allowed to edit this include!
- "strcpy" macro credits: http://forum.sa-mp.com/showpost.php?p=2532139&postcount=19
- */
- #include <string>
- #if defined _C_STRING_H_INCLUDED_
- #endinput
- #endif
- #define _C_STRING_H_INCLUDED_
- #if !defined STRBRK_BUFF_LEN
- #define STRBRK_BUFF_LEN (128)
- #endif
- #define __strcat_(%0,%1) strcat(%0,%1)
- #define strncat(%0,%1,%2) strmid(%0,%1,0,%2)
- stock strchr(const str[], chr)
- {
- new str_len = strlen(str);
- if(str_len <= 0) return 0;
- for(new str_pos = 0; str_pos < str_len; str_pos++) if(str[str_pos] == chr) return str_pos+1;
- return 0;
- }
- stock strrchr(const str[], chr)
- {
- new str_len = strlen(str);
- if(str_len <= 0) return 0;
- for(new str_pos = str_len-1; str_pos >= 0; str_pos--) if(str[str_pos] == chr) return str_pos+1;
- return 0;
- }
- #define __strcmp_(%0,%1) strcmp(%0,%1,_,cellmax)
- #define strncmp(%0,%1,%2) strcmp(%0,%1,_,%2)
- #define strcasecmp(%0,%1) strcmp(%0,%1,true,cellmax)
- #define strncasecmp(%0,%1,%2) strcmp(%0,%1,true,%2)
- #define strcpy(%0,%1) strcat((%0[0]='\0',%0),%1)
- #define strncpy(%0,%1,%2) strmid(%0,%1,0,%2,sizeof(%0))
- stock strpbrk(const str1[], const str2[])
- {
- new buffer[STRBRK_BUFF_LEN] = "", buffer_pos = 0, str_len[2];
- if((str_len[0] = strlen(str1)) <= 0 || (str_len[1] = strlen(str2)) <= 0) return buffer;
- new str_pos[2];
- for(str_pos[1] = 0; str_pos[1] < str_len[1]; str_pos[1]++)
- {
- for(str_pos[0] = 0; str_pos[0] < str_len[0]; str_pos[0]++)
- {
- if(str1[str_pos[0]] == str2[str_pos[1]])
- {
- buffer[buffer_pos] = str1[str_pos[0]];
- if((++buffer_pos) >= (STRBRK_BUFF_LEN-1))
- {
- buffer[STRBRK_BUFF_LEN-1] = '\0';
- return buffer;
- }
- }
- }
- }
- buffer[buffer_pos] = '\0';
- return buffer;
- }
- stock strspn(const str1[], const str2[])
- {
- new count = 0, str_len[2];
- if((str_len[0] = strlen(str1)) <= 0 || (str_len[1] = strlen(str2)) <= 0) return 0;
- new str_pos[2];
- for(str_pos[0] = 0; str_pos[0] < str_len[0]; str_pos[0]++)
- {
- for(str_pos[1] = 0; str_pos[1] < str_len[1]; str_pos[1]++)
- {
- if(str1[str_pos[0]] == str2[str_pos[1]])
- {
- count++;
- break;
- }
- }
- }
- return count;
- }
- stock strcspn(const str1[], const str2[])
- {
- new str_len[2];
- if((str_len[0] = strlen(str1)) <= 0 || (str_len[1] = strlen(str2)) <= 0) return 0;
- new str_pos[2];
- for(str_pos[0] = 0; str_pos[0] < str_len[0]; str_pos[0]++) for(str_pos[1] = 0; str_pos[1] < str_len[1]; str_pos[1]++) if(str1[str_pos[0]] == str2[str_pos[1]]) return str_pos[0]+1;
- return 0;
- }
- #define strstr(%0,%1) strfind(%0,%1,false,_)
- #define strcasestr(%0,%1) strfind(%0,%1,true,_)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement