Advertisement
Guest User

[v0.5] stringh.inc

a guest
May 18th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.31 KB | None | 0 0
  1. /*
  2.    
  3.     Copyright (C) 2013 Nicholas McAlpin
  4.     "cstdlib" (by Aeonosphere) is available under the terms of the Mozilla Public License Version 2.0 (MPL v2.0)
  5.     "stringh.inc" (by Aeonosphere) is available under the terms of the Mozilla Public License Version 2.0 (MPL v2.0)
  6.  
  7.     VERSION: "stringh.inc": v0.5
  8.            
  9. */
  10.  
  11.  
  12. #include <a_samp> //Necessary #include (.inc file)...    
  13. #define MAX_STRING 2048 //Maximum string length strncpy and strncat can handle...
  14.      
  15.         //Definition of C's strcpy...
  16.         /*
  17.         Name: strcpy
  18.         Usage: strcpy(dest, src, (explicit) size of dest)
  19.         */
  20. #if defined strcpy(%0,%1,%2)
  21.     #undef strcpy(%0,%1,%2)
  22. #endif
  23. #define strcpy(%0,%1,%2) \
  24.             strcat((%0[0] = '\0', %0), %1, %2)
  25.      
  26.     //Public function for C's strncpy...
  27.     /*
  28.             Name: strncpy
  29.             Usage: strncpy(dest, src, num chars from start, (explicit) size of dest)
  30.     */
  31. #if defined strncpy(%0,%1,%2,%3)
  32.     #undef strncpy(%0,%1,%2,%3)
  33. #endif
  34. forward strncpy(dest[], src[], num, sDest);
  35. public strncpy(dest[], src[] num, sDest)
  36. {
  37.     new cchar[MAX_STRING];
  38.     strmid(cchar, src, 0, (num-1));
  39.     strdel(cchar, num, strlen(cchar));
  40.     strcat((dest[0] = '\0', dest), cchar, sDest);
  41.     return 1;
  42. }
  43.      
  44.     //Public function for C's strncat...
  45.     /*
  46.             Name: strncat
  47.             Usage: strncat(dest, src, num of chars from start, (explicit) size of dest)
  48.     */
  49. #if defined strncat(%0,%1,%2,%3)
  50.     #undef strncat(%0,%1,%2,%3)
  51. #endif
  52. forward strncat(dest[], src[], num, sDest);
  53. public strncat(dest[], src[], num, sDest)
  54. {
  55.     new cchar[MAX_STRING];
  56.     strmid(cchar, src, 0, (num-1));
  57.     strdel(cchar, num, strlen(cchar));
  58.     strcat(dest, cchar, sDest);
  59.     return 1;
  60. }
  61.  
  62.     //Re-application of strcmp, bringing it in line with the C standard...
  63.     /*
  64.             Name: strcmp
  65.             Usage: strcmp(string1, string2)
  66.     */
  67. #if defined strcmp(%0,%1,%2,%3)
  68.     #undef strcmp(%0,%1,%2,%3)
  69. #endif
  70. #if defined strcmp(%0,%1)
  71.     #undef strcmp(%0,%1)
  72. #endif
  73. #define strcmp(%0,%1) \
  74.             strcmp(%0,%1,false)
  75.            
  76.     //Re-application of strcmp, bringing it in line with the C standard...
  77.     /*
  78.             Name: strncmp
  79.             Usage: strncmp(string1, string2, num chars from start)
  80.     */
  81. #if defined strncmp(%0,%1,%2,%3)
  82.     #undef strncmp(%0,%1,%2,%3)
  83. #endif
  84. #define strncmp(%0,%1,%2) \
  85.             strcmp(%0,%1,false,%2)
  86.                                    
  87.     //Re-application of strcmp, bringing it in line with the C standard...
  88.     /*
  89.             Name: strcasecmp
  90.             Usage: strcasecmp(string1, string2)
  91.             Special: case is always ignored here
  92.     */
  93. #if defined strcasecmp(%0,%1)
  94.     #undef strcasecmp(%0,%1)\
  95. #endif
  96. #if defined strcasecmp(%0,%1,%2)
  97.     #undef strcasecmp(%0,%1,%2)
  98. #endif
  99. #if defined strcasecmp(%0,%1,%2,%3)
  100.     #undef strcasecmp(%0,%1,%2,%3)
  101. #endif
  102. #define strcasecmp(%0,%1) \
  103.             strcmp(%0,%1,true)
  104.                            
  105.     //Re-application of strcmp, bringing it in line with the C standard...
  106.     /*
  107.             Name: strncasecmp
  108.             Usage: strncasecmp(string1, string2, num chars from start)
  109.             Special: case is always ignored here
  110.     */
  111. #if defined strncasecmp(%0,%1,%2)
  112.     #undef strncasecmp(%0,%1,%2)
  113. #endif
  114. #if defined strncasecmp(%0,%1,%2,%3)
  115.     #undef strncasecmp(%0,%1,%2,%3)
  116. #endif
  117. #define strncasecmp(%0,%1,%2) \
  118.             strcmp(%0,%1,true,%2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement