home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / Classes / RCString / RCStringRetrieval.m < prev    next >
Encoding:
Text File  |  1993-01-19  |  1.0 KB  |  54 lines

  1. #import <RCString.h>
  2. /*
  3.     Copyright (C) 1992. Bruce Ediger.
  4.  
  5.       This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU Library General Public License.
  7. */
  8.  
  9. //
  10. // implementation of "substring retrieval" methods
  11. //
  12.  
  13. @implementation RCString (Retrieval)
  14.  
  15. - (char *)subStringAt:(int)iIndex extent:(int)iLength
  16. {
  17.     char *bpReturn = NULL;
  18.  
  19.     if (iIndex >= 0 && iLength >= 0) {
  20.         if (iIndex + iLength >= p->l)
  21.             iLength = p->l - 1 - iIndex;
  22.         if (iLength > 0) {
  23.             bpReturn = malloc(iLength + 1);
  24.             if (bpReturn) {
  25.                 bcopy(p->s + iIndex, bpReturn, iLength);
  26.                 bpReturn[iLength] = '\0';
  27.             }
  28.         }
  29.     }
  30.  
  31.     return bpReturn;
  32. }
  33.  
  34. - subObjectAt:(int)index extent:(int)length
  35. {
  36.     RCString *oNew;
  37.     char *bpNewString = [self subStringAt:index extent:length];
  38.  
  39.     if (bpNewString) {
  40.         oNew = [[RCString alloc] init];
  41.         if (oNew) {
  42.             oNew->p->s = bpNewString;
  43.             oNew->p->l = strlen(bpNewString) + 1;
  44.         } else {
  45.             [oNew free];
  46.             oNew = NULL;
  47.         }
  48.     } else {
  49.         oNew = [RCString new];
  50.     }
  51.     return oNew;
  52. }
  53. @end
  54.