home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume43 / gen / part02 / string.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-24  |  1.4 KB  |  123 lines

  1. /*
  2. File: string.c
  3.  
  4. Author: Bruce Kritt
  5.  
  6. Description:
  7. */
  8.  
  9. #include "char.h"
  10. #include "string.h"
  11.  
  12. int str_len(char* string)
  13. {
  14.     char* p = string;
  15.  
  16.     while (*p++);
  17.  
  18.     --p;
  19.  
  20.     return (p - string);
  21.  
  22. }       // end function str_len()
  23.  
  24. void str_copy(char* lhs,char* rhs)
  25. {
  26.     while (*lhs++ = *rhs++);
  27.  
  28.     return;
  29. }
  30.  
  31. int str_comp(char* lhs,char* rhs)
  32. {
  33.     while (*lhs == *rhs && *lhs && *lhs)
  34.     {
  35.         ++lhs;
  36.         ++rhs;
  37.     }
  38.  
  39.     return (*lhs - *rhs);
  40.  
  41. }       // end function str_comp()
  42.  
  43. void str_cat(char* base,char* add)
  44. {
  45.     while (*base++);
  46.  
  47.     --base;
  48.  
  49.     str_copy(base,add);
  50.  
  51.     return;
  52.  
  53. }       // end function str_cat()
  54.  
  55. void str_trim(char* string) // new
  56. {
  57.     char* end = string + str_len(string) - 1;
  58.  
  59.     do
  60.     {
  61.         if (end < string) break;
  62.  
  63.         if (!is_space(*end)) break;
  64.  
  65.         --end;
  66.     }
  67.     while (1);
  68.  
  69.     *++end = 0;
  70.  
  71.     char* begin = string;
  72.  
  73.     do
  74.     {
  75.         if (*begin == 0) break;
  76.  
  77.         if (!is_space(*begin)) break;
  78.  
  79.         ++begin;
  80.     }
  81.     while (1);
  82.  
  83.     str_copy(string,begin);
  84.  
  85.     return;
  86.  
  87. }       // end function str_trim()
  88. /*
  89. void str_trim(char* string) // old
  90. {
  91.     char* end = string + str_len(string);
  92.  
  93.     while (is_space(*--end));
  94.  
  95.     *++end = 0;
  96.  
  97.     char* begin = string;
  98.  
  99.     while (is_space(*begin++));
  100.  
  101.     --begin;
  102.  
  103.     str_copy(string,begin);
  104.  
  105.     return;
  106.  
  107. }       // end function str_trim()
  108. */
  109. void str_rc(char* string)
  110. {
  111.     char* from = string;
  112.     char* to = string;
  113.  
  114.     do
  115.     {
  116.         if (*from != ',') *to++ = *from;
  117.     }
  118.     while (*from++);
  119.  
  120.     return;
  121.  
  122. }       // end function str_rc()
  123.